Salesforce to Salesforce using PartnerSoapSforceCom

Step 1: Generate Partner WSDL.

Save the generated Partner WSDL.

Step 2: Generate Apex code using the generated Partner WSDL.

Copy the generated code and create a new Apex Class.

In the generated code do the following changes.
  1. Change public partnerSoapSforceCom.DeleteResult[] delete(String[] ids)  to public partnerSoapSforceCom.DeleteResult[] deleteSObjects(String[] ids).
  2. Change public partnerSoapSforceCom.UpsertResult[] upsert(String externalIDFieldName,sobjectPartnerSoapSforceCom.sObject_x[] sObjects) to public partnerSoapSforceCom.UpsertResult[] upsertSObjects(String externalIDFieldName,sobjectPartnerSoapSforceCom.sObject_x[] sObjects).
  3. Change public partnerSoapSforceCom.MergeResult[] merge(partnerSoapSforceCom.MergeRequest[] request) to public partnerSoapSforceCom.MergeResult[] mergeSObjects (partnerSoapSforceCom.MergeRequest[] request).
  4. Change public partnerSoapSforceCom.SaveResult[] update(sobjectPartnerSoapSforceCom.sObject_x[] sObjects) to public partnerSoapSforceCom.SaveResult[] updateSObjects(sobjectPartnerSoapSforceCom.sObject_x[] sObjects).
  5. Change public partnerSoapSforceCom.UndeleteResult[] undelete(String[] ids) to public partnerSoapSforceCom.UndeleteResult[] undeleteSObjects(String[] ids).

Step 3: Creating a custom button ‘Share with Bangalore’.

Step 4: Add the custom button to Account page layout.

Step 5: Create shareWithBangalore apex class.

Sample Code:

global class shareWithBangalore
    webservice static void share(Id localId)
        String password = 'pocuser01xmJO32dqUnhHUwB1kFNW9kEw';
        String userName = '';
        List<Account> acct = new List<Account>();
        String sql = 'SELECT Name,Phone,External_ID__c,Type,Industry,AccountNumber,Description,FAX,SLA__c,Rating FROM Account WHERE ID=:localId';
        acct = Database.Query(sql);
        partnerSoapSforceCom.Soap con = new partnerSoapSforceCom.Soap();
        partnerSoapSforceCom.LoginResult loginResult = con.login(username, password);   
        con.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
        con.endpoint_x =loginResult.ServerUrl;
        con.Sessionheader.sessionid = loginResult.sessionid;
        List<sobjectPartnerSoapSforceCom.sObject_x> sObjects = new List<sobjectPartnerSoapSforceCom.sObject_x>();          
        sobjectPartnerSoapSforceCom.sObject_x tmpObj = new sobjectPartnerSoapSforceCom.sObject_x();
        for(Account ac:acct)
            tmpObj.type_x = 'Account';
            tmpObj.AcctName = ac.Name;
            tmpObj.ExtID= ac.External_ID__c;
            tmpObj.Phone = ac.Phone;           
            tmpObj.AcctType = ac.Type;
            tmpObj.AcctIndustry = ac.Industry;
            tmpObj.AcctNum = ac.AccountNumber;
            tmpObj.AcctDesc= ac.Description;            
            tmpObj.AcctFAX = ac.FAX;
            tmpObj.AcctSLA = ac.SLA__c;   
            tmpObj.AcctRating = ac.Rating;       

Step 6: Add the field details in sobjectPartnerSoapSforceCom apex class.

Add the below code in sobjectPartnerSoapSforceCom apex class.


        public String AcctName;      

        private String[] AcctName_type_info = new String[]{'Name','','string','1','1','true'};      

        public String ExtID;      

        private String[] ExtID_type_info = new String[]{'External_ID__c','','string','1','1','true'};      

        public String Phone;      

        private String[] Phone_type_info = new String[]{'Phone','','string','1','1','true'};      

        public String AcctType;      

        private String[] AcctType_type_info = new String[]{'Type','','string','1','1','true'};     

        public String AcctIndustry;      

        private String[] AcctIndustry_type_info = new String[]{'Industry','','string','1','1','true'};      

        public String AcctNum;      

        private String[] AcctNum_type_info = new String[]{'AccountNumber','','string','1','1','true'};       

        public String AcctDesc;      

        private String[] AcctDesc_type_info = new String[]{'Description','','string','1','1','true'};      

        public String AcctFax;      

        private String[] AcctFax_type_info = new String[]{'Fax','','string','1','1','true'};      

        public String AcctSLA;      

        private String[] AcctSLA_type_info = new String[]{'SLA__c','','string','1','1','true'};       

        public String AcctRating;      

        private String[] AcctRating_type_info = new String[]{'Rating','','string','1','1','true'};     


Edit the private String[] field_order_type_info = new String[]{'type_x','fieldsToNull','Id'}; to private String[] field_order_type_info = new String[]{'type_x','fieldsToNull','Id','AcctName','ExtID','Phone','AcctIndustry','AcctType','AcctNum','AcctDesc','AcctFax','AcctSLA','AcctRating'};

Step 7: Adding Remote site settings.



  1. Awesome Magulan..the great salesforce Admin...

  2. Thanks for the post. Great job!

  3. It is not working

  4. Hi, if we have iprestrictions in org. what ip address does it log to the remote destination url mentioned to pull the data with user account

  5. I am having the following errors : IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = And I confiure both the source and destination org, to be sure with the remote site setting you provided. I suspect the : url. What is this url?


Sharing is Caring!!! Share this with your friends!!!

submit to reddit