2

We have forwarded records using salesforce to salesforce concept it was done well . Here we need to know which records are forwarded . we tried by using workflow with the condition making "sent connection Name not equals to null" but it is not perfect approach . could anyone please let us know the right way to know how can we know which records are forwarded using salesforce to salesforce at each record level.

Thanking you.

1 Answer 1

0

we have created a field with data type checkbox. We are using a condition whether a record is eligible to forward or not by using another check box field named "eligible for sharing". Now when the check box is checked then only we have to forward that record using salesforce to salesforce concept.

we have written a batch Apex to make "externally shared" check box to be checked. Please find the batch Apex below . */ global class SalesforceToSalesforceConnection implements Database.Batchable, Database.Stateful //public class SalesforceToSalesforceConnection {

//the start method
global Database.QueryLocator start(Database.BatchableContext BC)
{
    System.debug('Test Start');        
    return Database.getQueryLocator([select Id, Status, ConnectionId, LocalRecordId from PartnerNetworkRecordConnection where status='sent']);

}

//the start method
global void execute(Database.BatchableContext BC,List<sObject> scope)
{
      System.debug('Test Execute');
      List<Account> accList=new List<Account>();
      List<Contact> conList=new List<Contact>();

      Set<String> LocalIds = new Set<string>();
      for(PartnerNetworkRecordConnection obj : (List<PartnerNetworkRecordConnection>)scope)
          LocalIds.add(obj.LocalRecordId);
      Map<Id,Account> UnSharedAccounts =new Map<Id,Account>([select Id,Externally_Shared__c from Account where Id in : LocalIds and Externally_Shared__c != true]);
      Map<Id,Contact> UnSharedContacts = new Map<Id,Contact>([select Id,Externally_Shared__c from Contact where Id in : LocalIds and Externally_Shared__c != true]);

      for(PartnerNetworkRecordConnection s :(List<PartnerNetworkRecordConnection>) scope)
      {

         //System.debug('s :'+s);
         String str=s.LocalRecordId;

         if(str.startsWith('001') && UnSharedAccounts.containsKey(s.LocalRecordId))
         {
             Account ac=new Account(Id=s.LocalRecordId,Externally_Shared__c=true);
             accList.add(ac);
         }

         if(str.startsWith('003') && UnSharedContacts.containsKey(s.LocalRecordId))
         {
             Contact con=new Contact(Id=s.LocalRecordId,Externally_Shared__c=true);
             conList.add(con);
         }

}

After sharing the record using salesforce to salesforce concept we have to run this batch apex in developer console .Use the below code.

SalesforceToSalesforceConnection stsc=new SalesforceToSalesforceConnection(); Database.executeBatch(stsc);

Now the externally shared checkbox gets checked after executing the batch class.

You must log in to answer this question.

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