+ Start a Discussion
Dagny FernandesDagny Fernandes 

getting error: FIELD_CUSTOM_VALIDATION_EXCEPTION

Hi Frends,
Iam getting the bellow error:
TicketStatus: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0AO000000Ak6Y6MAJ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This profile cannot edit this escalation the tickets are raised: [] Class.TicketStatusHandler.onAfterUpdate: line 229, column 1 Trigger.TicketStatus: line 37, column 1

There is requirement like i have a parent record and child records, the child record as a self lookup relation to parent record. 
Here the parent record is escaltion and child record is ticket.
The above error is comeing while editing the ticket because There is a validation on the parent record(Escaltion) based on profile. the validation is  
Ex: IF Ticket is raised for the respaective Escalation then the BA profile cannot edit the Escaltion. But can edit the Ticket, based on ticket value from trigger escaltion is updated, here it comes the above mentioned error.

How can i overcome from this problem need help.

Thanks in advance,
Best Answer chosen by Dagny Fernandes
Dagny FernandesDagny Fernandes
Hi @BalajiRanganathan thanks for you suggetion.
This solved the class was writen under "with sharing" i removed the with sharing it started updateing the record nw the code runs under system admin profile

All Answers

BalajiRanganathanBalajiRanganathan
you need to handle the dml exception in the TicketStatusHandler.onAfterUpdate and add the error message so that it can be shown to the user.


try{
update accounts;
} catch (DMLException e){
  for (Account account : accounts) {
   account.addError('There was a problem updating the accounts');
}
} finally {
inProgress = false;
}

Refer the below url for more info.
https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling
 
Dagny FernandesDagny Fernandes
Thanks a Lot @Balaji for the replay,
But i wanted this update to be happen in the back end
Dagny FernandesDagny Fernandes
Hi @BalajiRanganathan thanks for you suggetion.
This solved the class was writen under "with sharing" i removed the with sharing it started updateing the record nw the code runs under system admin profile
This was selected as the best answer