Deploy Metadata Using Salesforce Metadata API
Dec 3, 2025
Blog Post:
https://www.infallibletechie.com/2025/12/deploy-metadata-using-salesforce-metadata-api.html
Show More Show Less View Video Transcript
0:07
Hello everyone. In this video, we are
0:09
going to see how to deploy using
0:13
Salesforce metadata API.
0:16
For Salesforce deployments, we can make
0:19
use of metadata API. We can also make
0:23
use of VS code or any other ID like
0:26
cursor and also Google anti-gravity
0:30
if you want to deploy
0:33
any changes or if you want to create any
0:35
metadata in your Salesforce or in this
0:39
video I'm going to show how to make use
0:41
of metadata API to create an Apex class.
0:47
But in this video, we're not going to
0:49
create the class. But uh I'm going to
0:51
show how to validate the creation of
0:54
Apex class.
0:59
The first step is we have to get access
1:02
token so that we can do the deployment
1:06
request. In order to do the
1:11
deployment, we need this access token.
1:15
So here
1:18
this is my Salesforce my domain URL.
1:22
The path for uh getting access token is
1:26
services/2
1:28
/ token. In the header I am not passing
1:31
any information but in the body I am
1:36
passing username, password, client ID
1:39
and secret which is consumer key and
1:41
consumer secret from your Salesforce
1:44
connected app. So we have to create a
1:47
connected app in Salesforce. Now you can
1:50
also create external client uh
1:53
credential in Salesforce setup using
1:56
which you will be able to get the
1:57
consumer key and consumer secret. So you
1:59
have to pass that information here.
2:04
So if you do a post request to this
2:07
endpoint, you will be able to get the
2:08
access token using a sample script. I'm
2:13
storing that information in the access
2:15
token global variable.
2:18
The next step is we have to create a zip
2:21
file.
2:23
In order to create that,
2:26
I created a folder with the name
2:28
package.
2:30
I created a package.xml file.
2:40
So this is my package.xml
2:43
and I created a folder called classes.
2:46
And inside the folder I have uh created
2:50
two files. one with the extension cls
2:54
and the other with the extension cls -
2:58
meta.xml.
3:00
When you create
3:02
an apex class in your VS code or cursor
3:05
or any other IDE, you will see two
3:08
files. One is CLS
3:12
and the other one is CLS meta.xml.
3:17
So both these files should be inside
3:20
classes folder.
3:24
If you are going to deploy lightning web
3:27
component then it should be LWC. If you
3:29
want to deploy custom labels then it
3:31
should be labels. If you want to deploy
3:34
custom metadata type then the folder
3:37
name should be custom metadata. So make
3:39
sure you are creating the right folder
3:42
and then you are placing the right files
3:43
inside the folder.
3:46
Next in order to validate
3:52
here in the JSON uh
3:56
form data
3:57
I am setting the deployment uh options
4:01
the deploy options as check only to true
4:04
so that it will validate the deployment
4:06
and it will not do the actual deployment
4:09
test level I have set it to no test run
4:12
because this is a demo or I'm just
4:13
playing around.
4:15
Next, I have used one more key called
4:18
file. And in the file, I have selected
4:22
from my uh desktop
4:29
the same folder whatever we created with
4:32
package.xml and classes folder. I have
4:35
created a zip format for it. So, you can
4:38
also
4:40
compress it. If you are using Mac OS, do
4:43
not uh right click and compress because
4:45
it will create some additional files in
4:48
the folder in the zipped folder or the
4:51
compressed folder. So it so your
4:53
deployments will fail. So make use of
4:55
some commands in your terminal if you
4:57
are using Mac OS.
4:59
So once it is done in the header we have
5:02
to pass authorization as the key and uh
5:07
in the value we we have to enter bar
5:11
space the access token which we got from
5:14
the first post request. Now if you do a
5:18
post request
5:21
it created a deployment
5:25
we should be able to see that. So as of
5:27
now only two validates succeeded.
5:30
Now let's try refresh it.
5:33
So I can see the third validation that
5:37
is also succeeded. You can do a get
5:41
request to your Salesforce my domain
5:43
URL/services/
5:45
data slash the version current version
5:48
is v65.0/ 0 / metadata/ deploy request
5:54
slash the deployment ID which you got
5:57
when you did a post request to deploy
6:00
the changes.
6:06
I am making use of include details equal
6:08
to true so that we get
6:11
when when the response comes from
6:13
Salesforce it contains a deployment uh
6:16
deploy results that attribute will have
6:19
additional values which will be very
6:21
helpful for us to troubleshoot and
6:23
debug.
6:25
So now if I give a send request I got
6:29
deploy result because of include details
6:33
which contains a crucial information for
6:35
troubleshooting and debugging. So here
6:37
it says
6:40
there are no error messages, no error
6:42
state. It is completed.
6:45
Success is also true. Status is
6:47
succeeded.
6:50
So everything went through properly
6:51
without any uh issues. we were able to
6:54
um confirm it from Salesforce setup
6:56
also. So in order to deploy you have to
7:00
make use of your Salesforce my domain
7:01
URL/services
7:04
slash data slash the current version/
7:07
metadata/deploy
7:10
request. So this will allow you to
7:11
deploy and validate your Salesforce
7:15
deployments using metadata API.
7:24
Please check the video description. In
7:26
the video description, I have shared my
7:28
blog post. From the blog post, you
7:31
should be able to see all the steps that
7:33
were discussed in this video for your
7:35
reference.
7:43
I hope it was helpful.
7:49
Thank you for watching.
#Enterprise Technology
#Programming
#Internet Software
#Web Services
