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
New_DeveloperNew_Developer 

Help with error message

Hi ,

 

i wrote a before delete trigger , which works fine but the error message iam trying to display on the page when the trigger fires is not displaying on the same page , insetad its displaying on a different page with the message as below.

 

"Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "You cannot delete this record".

Click here to return to the previous page.   "

 

"You cannot delete this record" is the error message which i wrote in the trigger  which has to be displayed when a user is trying to delete that record.So iam not sure why its not showing the error message on the page .

 

 

 

 

QingsongQingsong

Can you paste your trigger?

New_DeveloperNew_Developer

this is the trigger

 

if(trigger.isdelete == true){
for(Code__c c: Trigger.old)
{
cids.add(c.id);
}
for(Opportunity objOpp : [Select id ,Code__c from Opportunity where Code__c IN :cids])
{
oppIds.add(objOpp.Code__c);
}
for(Code__c codedel : Trigger.old){
if(oppIds.contains(codedel.id)){
codedel.addError('You cannot delete this ');
}
else
System.debug('Deleting');

}
}
}