Post Salesforce data from one org to Another org Using SOAP API

SOAP API is used to integrate applications or other third party applications, and it lets the user to maintain passwords, perform searches and much more. You can use the SOAP API with any programming language that supports Web services.


SOAP API is used to integrate applications or other third party applications, and it lets the user to maintain passwords, perform searches and much more. You can use the SOAP API with any programming language that supports Web services.

post data to salesforce

In this article, I have documented the steps that we need to follow to post the data from one Salesforce instance to another instance using the SOAP API.

Note 1: 

First, log into the Salesforce (Destination system) that you want to receive the data from, and follow the steps 1 to 3.

  1. Create a web service class like below:

global class MyWebServiceHandler { 
    webService static Id createAccount (String firstName, String lastName) { 
        Contact c = new  Contact(lastName =  lastName,  firstName = firstName); 
        insert c; 

  1. Generate a WSDL file for the above Web Service class and save the generated XML file (MyWebServiceHandler.xml) in your system:

post data to salesforce

  1. Generate partner WSDL FileUnder Build section, navigate to Develop [Symbol]  API and click Generate Partner WSDL link. It will generate a WSDL file and save the Partner.xml.

post data to salesforce

Note 2: 

Log into another Salesforce (Source system) that you are going to send the data and follow the below steps

  1. Under Build section, navigate to Develop  [Symbol] Apex Classes, click Generate from WSDL button and select the Partner WSDL file (i.e. partner.xml) that you created in the Step 3. Now, click Parse WSDL button

post data to salesforce

It will navigate to another page that will show the Parse successful message. Now, click Generate Apex code button. (if you get any error during the apex generation, please replace all the occurrences of “anyType” to “string”  in the Partner.xml file).

post data to salesforce

  1. Repeat the above step for the MyWebServiceHandler.xml file also

post data to salesforce

Two files will be generated from their corresponding xml files. The first file is used for the synchronous call, and the next one is used for the asynchronous call.

  1. Create Remote site settings for the destination Org in the Source Org. For example, my destination org instance is Ap1, So I have created a remote site setting like below in the source org

post data to salesforce

  1. Apex class and Trigger for Contact Creation: Create the below class (ContactHandler) and trigger (ContactTrigger) into your Source org.

replace the “xxx” with your Destination org’s user name and password + security token, like below.

partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login(‘’, ‘xxxxx’);


partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login(Username, Password+securityToken);


public class ContactHandler{ 


    public static void createContact(String jsonString){ 

        List<Contact> contactList = (List<Contact>)json. deserialize(jsonString, List<Contact>.class); 

        if(!contactList.isEmpty() && contactList.size() < 99){ 

                 partnerSoapSforceCom.Soap myPartnerSoap = new partnerSoapSforceCom.Soap();  

            partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login(', 'xxxxx'); 

            soapSforceComSchemasClassMywebservi. SessionHeader_element webserviceSessionHeader = new soapSforceComSchemasClassMywebservi. SessionHeader_element();  

            webserviceSessionHeader.sessionId = partnerLoginResult.sessionId;  

               soapSforceComSchemasClassMywebservi. MyWebServiceHandler myWebservice = new soapSforceComSchemasClassMywebservi. MyWebServiceHandler(); 

            myWebservice.SessionHeader = webserviceSessionHeader; 

                 for(Contact contactIns:contactList){  

                myWebservice.createContact (contactIns.firstname, contactIns.lastname); 






Trigger ContactTrigger on Contact (after Insert,after Update) { 

    List<Contact> contactList = NEW List<Contact>(); 


        For(Contact contactInstance:Trigger.New){ 



        String jsonString = json.serialize(contactList); 

        ContactHandler. createContact(jsonString); 




The above class and trigger handle only 99 records because standard Salesforce callout limit is 100 per transaction, if you want to process more than 100 records, you should go for a batch class.

  1. If you create a contact in the source instance, the same contact will be created in the destination instance also.

Source ORG: 

post data to salesforce

Destination ORG: 

post data to salesforce

Reference Link: https://developer. sforce_api_quickstart _steps.htm

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.