Salesforce to Salesforce using PartnerSoapSforceCom

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.

Note:

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 = '[email protected]';
       
        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;       
            sObjects.add(tmpObj);
        }
        con.create(sObjects);           
    }
}

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

Add the below code in sobjectPartnerSoapSforceCom apex class.

//Start      

        public String AcctName;      

        private String[] AcctName_type_info = new String[]{'Name','urn:partner.soap.sforce.com','string','1','1','true'};      

        public String ExtID;      

        private String[] ExtID_type_info = new String[]{'External_ID__c','urn:partner.soap.sforce.com','string','1','1','true'};      

        public String Phone;      

        private String[] Phone_type_info = new String[]{'Phone','urn:partner.soap.sforce.com','string','1','1','true'};      

        public String AcctType;      

        private String[] AcctType_type_info = new String[]{'Type','urn:partner.soap.sforce.com','string','1','1','true'};     

        public String AcctIndustry;      

        private String[] AcctIndustry_type_info = new String[]{'Industry','urn:partner.soap.sforce.com','string','1','1','true'};      

        public String AcctNum;      

        private String[] AcctNum_type_info = new String[]{'AccountNumber','urn:partner.soap.sforce.com','string','1','1','true'};       

        public String AcctDesc;      

        private String[] AcctDesc_type_info = new String[]{'Description','urn:partner.soap.sforce.com','string','1','1','true'};      

        public String AcctFax;      

        private String[] AcctFax_type_info = new String[]{'Fax','urn:partner.soap.sforce.com','string','1','1','true'};      

        public String AcctSLA;      

        private String[] AcctSLA_type_info = new String[]{'SLA__c','urn:partner.soap.sforce.com','string','1','1','true'};       

        public String AcctRating;      

        private String[] AcctRating_type_info = new String[]{'Rating','urn:partner.soap.sforce.com','string','1','1','true'};     

        //end

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.

Output:

Leave a Reply