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
Sourabh Tayal 5Sourabh Tayal 5 

Salesforce 2 salesforce automation using trigger

I am implementing the same Salesforce to Salesforce automate record sharing with Apex Trigger for contact object and its related and master records.
I have did all prerequiste setting for this.

My trigger is firing(after insert, after update) and not giving any error but contact record is not sharing with other org.

Help me regarding it or let me know if i have left any action.
I am mentioning my code here:


Trigger AutoforwardContact on Contact(after Insert,after update){  
    PartnerNetworkConnection pp =[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection
                                                               where ConnectionStatus = 'Accepted' and connectionName = '360DC'];
    system.debug('ppppp' + pp);
    Id networkId = pp.id;    
    System.debug('>>>>>>networkId' + networkId);
      
        List<PartnerNetworkRecordConnection> connections =  new    List<PartnerNetworkRecordConnection>();
        for (Contact newTest: Trigger.new) {                         
                PartnerNetworkRecordConnection newConnection = new PartnerNetworkRecordConnection(
                      ConnectionId = networkId,
                      LocalRecordId = newTest.Id,
                      SendClosedTasks = false,
                      SendOpenTasks = false,
                      SendEmails = false,
                      ParentRecordId = newTest.AccountId);
                System.debug('>>>>>>newConnection' + newConnection);   
                connections.add(newConnection);
            }
        database.insert(connections);  
}

Manuall sharing is working but whenever i try for automate using trigger it is not working.
Swati GSwati G
Hi,

Please debug the result of database.insert and see if you are getting errors.
Sourabh Tayal 5Sourabh Tayal 5
i checked for it, not getting any error. Let me know any other solution / trick for same problem.