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

salesforce 2 salesforce connection, avoid sending error message emails to connection owner

wrote trigger to avoid over wrtting of fields from source env to target env.
the trigger is working fine, but it isending error messages thorugh emails to salesforce connection owners, daily it is around 300 mails from lead object.

The details are as follows:

    Error updating Lead record(s).  Cannot update Lead (Full Name : steven steve). Message:  You can't update this record! . StatusCode = FIELD_CUSTOM_VALIDATION_EXCEPTION

    Number of records that failed with this error : 1
For more information on how "Salesforce to Salesforce" impacts existing validation rules and apex triggers please r


trigger LeadUpdate on Lead (before update) {
    map<Id,boolean> mapIds = 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!');



I searched for this and think there is no workaround as such to stop these emails as its a geniune error message coming for the trigger " You can't update this record!" triggered from a validation which should ideally be notified to the connection owner.

Yes Sonam, you are correct, we solved it by in different way. Thanks a lot