I am trying to write an apexrest service that takes in fields for the Opportunity Object. There are certain restrict picklists on the Opportunity object that I've created. Additionally there are other custom validation rules and some checks done through the trigger. I want to return these error messages in the response if the insert fails.
I decided to use
Database.insert(object,false) such that I could use the
Database.SaveResultto go through the errors and generate a response by iterating over them. When I tried this on my dev org with a small object with 2 validation rules and some checks in the trigger, I could iterate over the errors successfully in case the insert failed.
However, when I tried to use the same approach for the Opportunity object with restricted picklists, it throws on one error at a time instead of showing all validation errors at once. Say I have three restrcited picklists 'Banking Apps', 'Ecom Apps', 'Sport Apps' and I send some faulty values in the request for all of them, it throws me
INVALID_OR_NULL_FOR_RESTRICTED_PICKLISTfor only the 'Banking Apps' picklist. If i fix the value for 'Banking App' and make the request again, it throws only one error for 'Ecom Apps'.
I would like to return all error messages at once in a single response. If someone could help me out with this or suggest me some other ways to validate the data coming in the request. Writing all the validations inside the apex is not a feasible choice as I have over 50 custom validation rules and some more in long triggers.
Edit : I have noticed that when all the picklist values are rectified, the email fields start showing up one after the other. Is there any documentation available regarding these checks that are made and in which order ? Or these occur in the order of the fields on the layout as I have some email fields in between the set of picklists ?