Salesforce 2 Salesforce connection | overwriting of fields | Error are sent to the connection owner email address;

When the user edits address field in destination Salesforce org, immediately overwrites the field value to put it back to its original value from the source org through salesforce to salesforce.

I wrote a trigger to avoid this, but it is sending error messages emails to connection owners.

ex: if we process 300 leads from source to destination, salesforce 2 salesforce connection is sending 300 error messages emails to connection users. But we don’t have any validation rules.

trigger LeadUpdate on Lead (before update) {
    list<Id,boolean> listIds = new map<Id,boolean>();
    for(PartnerNetworkRecordConnection recordConn : [select Status,LocalRecordId from PartnerNetworkRecordConnection where LocalRecordId IN]) {
        if( recordConn.Status.equalsignorecase('Sent') ){ //Lead is connected - outbound
    for ( integer iCount=0;iCount<;iCount++ )
        if ( mapIds.get([iCount].Id) != null )
  [iCount].addError('You can\'t update this record!');

error message is:

Error updating Lead record(s). Cannot update Lead (Full Name : Smith
Thomas). Message: You can’t update this record! . StatusCode =

Number of records that failed with this error : 1


To add onto Daniel’s point #3, you can detect the Connection User as the running user using this APEX:

public Boolean isRunningUserConnectionUser() {
   return UserInfo.getUserType() == 'PartnerNetwork' && 
          UserInfo.getName() == 'Connection User'; // localize appropriately 

no need for a custom setting

Source : Link , Question Author : user5515 , Answer Author : cropredy

Leave a Comment