+ Start a Discussion
niki s 7niki s 7 

Which will execute first

Hello as we all know that customer validation excute first and then before trigger . 
so I write a trigger to show error message if description is null
trigger updatecontact on contact( before trigger)
for(contact con: trigger new)
If(con.description == null)
Con.adderror(' message from trigger i.e contact is null')
 
And wrote a custom validation for the same thing
When I try to save the code its showing message from before trigger not from custom validation .

Why so . Please help I'm confused
 
 
Prasanthi_s1505Prasanthi_s1505
Hi Niki,

please check the for Loop.. in your code.

for(contact con: trigger new)
 
It should changed to for(contact con: trigger.new)
as per my Observation from your code.

If you have wrote any Custom Validition for the same please deactivate it and try.

Note: Any requirement can be solved through validations or with any automations try to follow them only. In case of requirement cannot be solved through these validations, worlflows, proccesbuilder etc. then try using Triggers. Its a good practice.

Thanks & Regards,
Prasanthi
Prasanthi_s1505Prasanthi_s1505
Hello Niki,

If My Answer was helpful please mark it as Best Answer.

Thank in Advance,
Prasanthi
niki s 7niki s 7
I'm asking about order of execution here 
niki s 7niki s 7
Not about code
Gonapati BhavithaGonapati Bhavitha
Hi Niki,

Executes all before triggers First then,Runs most Custom validation.
 For Help please  go through  the below link.
https://www.apexhours.com/order-of-execution-salesforce/

Thank You,
Bhavitha


 
Gonapati BhavithaGonapati Bhavitha
Hi Niki,
please  go through  the below link also,
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
If you find helpful,
Please mark it as best answer.

Thank You,
Bhavitha