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 :trigger.new]) {
if( recordConn.Status.equalsignorecase('Sent') ){ //Lead is connected - outbound
mapIds.put(recordConn.LocalRecordId,true);
}
}
for ( integer iCount=0;iCount<trigger.new.size();iCount++ )
{
if ( mapIds.get(trigger.new[iCount].Id) != null )
trigger.new[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 = FIELD_CUSTOM_VALIDATION_EXCEPTION
Number of records that failed with this error : 1