You need to sign in to do that
Don't have an account?
Michael Clarke 36
Variable does not exist: addError
Hi, I am new to Apex
I have copied an example trigger code, however I get the error message 'Variable does not exist: addError'.
All it does is prevent deletion of an orphan contact with a custom error msg.
Can you tell me what I am doing wrong?
trigger ContactBeforeDelete on Contact (before delete)
{
for(Contact c:trigger.old)
{
if(c.accountId==null)
{
c.addError=('You are not authorised to delete this contact.');
}
}
}
I have copied an example trigger code, however I get the error message 'Variable does not exist: addError'.
All it does is prevent deletion of an orphan contact with a custom error msg.
Can you tell me what I am doing wrong?
trigger ContactBeforeDelete on Contact (before delete)
{
for(Contact c:trigger.old)
{
if(c.accountId==null)
{
c.addError=('You are not authorised to delete this contact.');
}
}
}
Make sure the api names of the field you are using is correct.
Looking forward to hearing back from you.
Regards,
Anutej
All Answers
Make sure the api names of the field you are using is correct.
Looking forward to hearing back from you.
Regards,
Anutej
You can use this code instead Kindly let me know if it helps you.
should read
c.addError('You are not authorised to delete this contact.');