0

I have created a salesforce to salesforce connection using trigger for new record and for update using the basic functionality.

But as during the deployment I may be need to put million of data and in this particular scenario I can't use trigger for mass transfer.

Is there any other way to use connection of salesforce to salesforce and do mass transfer.

1 Answer 1

3

You can write Apex Batch Class for doing the mass transfer. In the execute method you can insert the PartnerNetworkRecordConnection object.

Below is the sample code i.e. not compiled for mass transferring the Account object if Publish and Subscribe is done in respective Org.

global class ShareAccount implements Database.Batchable<sObject> {
  global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator([Select Id from Account]); 
  }

  global void execute(Database.BatchableContext BC, List<sObject> scope){
    //GET THE CONNECTION ID FROM PARTNERNETWORKCONNECTION WHERE THE RECORDS NEEDS TO BE SHARED CONSIDERING THE CONNECTION IS ONLY 1
    List<PartnerNetworkConnection> pncList = [SELECT Id 
                                              FROM PartnerNetworkConnection 
                                              WHERE ConnectionStatus = 'Accepted' LIMIT 1]

    List<PartnerNetworkRecordConnection> pnrcInsertList = new List<PartnerNetworkRecordConnection>();
    if(!pncList.isEmpty()) {
        //LOOP THROUGH ALL THE ACCOUNT FOR SHARING THE ACCOUNT
        for(Account accObj : scope){
                pnrcInsertList.add(new PartnerNetworkRecordConnection( ConnectionId  = pncList[0].Id,
                                                                       LocalRecordId = accObj.Id,
                                                                       SendEmails    = FALSE));
        }
    }

    if(!pnrcInsertList.isEmpty()) {
        insert pnrcInsertList;
    }
  }

  global void finish(Database.BatchableContext BC){       
  }
}

Note: You can write the batch class for initial transfer and then you can utilize the trigger code

1
  • Thanks for this , But other that if externally we are trying to do is there any trick that can help us so. Cheers ! Jan 4, 2017 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .