In this post I'm going the cover basics in the Metadata API and how it can connect with a .net console application. Then after I will show you how to create a custom object and create fields by using the metadata api from the console app.
What is Salesforce Metadata API
There are many things can be done from the metadata api. you can create Objects,Fields,Validation,Workflows, Profiles, Reports for a particular client organization just by running the piece of code so that you need not do all the customization settings manually which will consume time if you have to do that several times for different clients for the same configuration settings. You can also take the backup of your organization customization settings just by fetching the metadata WSDL from your Salesforce org.
You can read, create, update, delete following components in a Salesforce organization.- Custom Objects/Fields.
- Visualforce pages.
- Page Layouts.
- Validation rules.
- Apex.
- Workflows.
- Approval processes.
- Profiles.
- Reports etc.
- Security.
In our first step we'll need to get the metadata api url by navigating to Setup -> API -> Generate Metadata WSDL. Metadata api have SOAP and REST version. Here we are focusing on for the SOAP.
Below screen shows how to generate wsdl from Salesforce.Then after copy the wsdl url.
Step 2 : Create a console application by using visual studio.
Here I'm using visual studio community 2017. And I'm targeting .NET framework 4.5.
Step 3 : Add the web reference in to the console application.
Right click on References in the solution explorer and click on Add Service References. Then you need to click on Advanced button and click Add Web References button. So you will end up with the below screen that you can paste the wsdl url and click on go button which you have copied in step 1.
give the namespaces as "com.salesforce.metadata" and click on Add References button. Then after visual studio automatically create the related files and references in order to connect with Salesforce. But here you need to get the sessionId from Salesforce Rest api or Enterprise/Partner wsdl , because Metadata API doesn't gives the login method.
Comments
Post a Comment