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
JohnRyderJohnRyder 

Data validation

Hey Folks,

 

Is it possible to validate data in before insert trigger  instead of adding error?

 

Regards..

Best Answer chosen by Admin (Salesforce Developers) 
nathaForcenathaForce

Hi John,

Data validation on records going through a trigger should be done in the beforeInsert/beforeUpdate events only. 

here is how the code could look like:

 

for (Account acct: trigger.new){
  acct.Description = acct.Description.deleteWhitespace();
}

 

Let me know if that helps


Nathalie

All Answers

nathaForcenathaForce

Hi John,

Data validation on records going through a trigger should be done in the beforeInsert/beforeUpdate events only. 

here is how the code could look like:

 

for (Account acct: trigger.new){
  acct.Description = acct.Description.deleteWhitespace();
}

 

Let me know if that helps


Nathalie

This was selected as the best answer
JohnRyderJohnRyder
Thanks Nathalie,it works.