You need to sign in to do that
Don't have an account?

How to throw error with sales force trigger under a field or on a top of page?
Hi I am new to triggers and I would like to know how to throw normal errors under a field or on the top of the page.
Also please provide with a sample example with explanation.
Also please provide with a sample example with explanation.
Hi Sai Durga,
" throw normal errors under a field or on the top of the page" -> As mentioned by Anutej above, you may use <record>.addError. It can be used in the following ways:
To show the error on a specific field:
You can reference this article for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_addError
Please mark this as the 'Best answer' if you find this information useful.
All Answers
There is an implementation in below link that has a similar implementation I am posting the code as well for quick reference:
Link: https://developer.salesforce.com/forums/?id=9060G0000005cjKQAQ
I hope you find this useful.
Regards,
Anutej
Hi Sai Durga,
" throw normal errors under a field or on the top of the page" -> As mentioned by Anutej above, you may use <record>.addError. It can be used in the following ways:
To show the error on a specific field:
You can reference this article for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_addError
Please mark this as the 'Best answer' if you find this information useful.
Hi Sai,
'Trigger.New[0]' is accessing the first record in the list 'Trigger.New'. This can be translated in English as:
Get me the first record (index 0) in the List of triggering records.
Bear in mind that .addError can only be used on an instance of 'Trigger.New'.
Hope that helps!