function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
William HinesWilliam Hines 

Tasks not sharing with partner connection in S2S

I have been developing my S2S connection within two sandbox environments. I can get Contacts and Accounts to forward over with no problem, however, the child activity objects are not included. I understand that the subscribing org needs to have the parent objects (Contacts) selected to auto-accept. This is currently the case. All available fields are mapped properly for both orgs, and again Contacts and Accounts are forwarded with no problem. I cannot get the tasks to carry over with a manual action or programmatic forwarding. The code that relates specifically to sharing contacts is as follows:

            PartnerNetworkRecordConnection newConnection;
            
            newConnection = 
                new PartnerNetworkRecordConnection( 
                    ConnectionId = networkId, 
                    LocalRecordId = newContact.Id, 
                    RelatedRecords = 'Opportunity,Task,Attachment,Case',
                    SendClosedTasks = true, 
                    SendOpenTasks = true, 
                    SendEmails = true, 
                    ParentRecordId = newContact.AccountId);  
            
            contactConnections.add(newConnection);
William HinesWilliam Hines
Update on this, I can forward contacts and the child tasks are forwarded as well through the manual action, however, the Apex code is not forwarding the tasks. Full batch class below:

global class ShareContactsWithPartner implements Database.Batchable<sObject>{

    global String email;
    global Id networkId;
    global List<Id> shareContactsSelection = new List<Id>();

    global ShareContactsWithPartner(List<Id> listShareContactsSelection)
    {
        shareContactsSelection = listShareContactsSelection;
    }

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator([SELECT Id, AccountId FROM Contact WHERE Id IN: shareContactsSelection]);
    }

    global void execute(Database.BatchableContext BC, List<Contact> scope)
    {
        List<PartnerNetworkRecordConnection> contactConnections =  new  List<PartnerNetworkRecordConnection>(); 
        
        for (Contact newContact : scope) { 

            PartnerNetworkRecordConnection newConnection;
            
            newConnection = 
                new PartnerNetworkRecordConnection( 
                    ConnectionId = networkId, 
                    LocalRecordId = newContact.Id, 
                    SendClosedTasks = true, 
                    SendOpenTasks = true, 
                    SendEmails = true, 
                    ParentRecordId = newContact.AccountId);  
            
            contactConnections.add(newConnection);
        } 

        if (contactConnections.size() > 0 ) {
           System.debug('Inserting contactConnections!');
           database.insert(contactConnections);
        }
    }

    global void finish(Database.BatchableContext BC)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('batch@riskxinvestments.com');
        mail.setSenderDisplayName('Batch Processing');
        mail.setSubject('Batch Process Completed');
        mail.setPlainTextBody('Batch Process has completed');

        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
    }
}