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
Abhirams470Abhirams470 

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:

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 :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!');

    }
}

Thanks
Sonam_SFDCSonam_SFDC
Hi,

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.


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