+ Start a Discussion
riffindusriffindus 

Validation rules/mandatory fields while inserting records in apex class

What will happen to validation rules and mandatory fields of an object when inserting records through apex class but not following validation rules or not providing the mandatory field values.

 

consider account object has name, city (mandatory), max_salary(has some validation rule), phone number fields.

 

if i insert

account s = new account (name =' bob', phone = '7896785678', max_salary='50000');

 

what will happen to this line while executing, will it fail because i have not provided mandatory field (city) and didn't follow validation rule for max_salary field. 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
Yes, on either account. Your code must always satisfy all required fields and validation rules. There is no way to successfully save any record in the database that does not meet all current business logic.

All Answers

sfdcfoxsfdcfox
Yes, on either account. Your code must always satisfy all required fields and validation rules. There is no way to successfully save any record in the database that does not meet all current business logic.
This was selected as the best answer
riffindusriffindus

ok. Thank you for the reply. So execution of apex class will throw error before inserting the record into the database. Am i right?

 

 

Vishal KashyapVishal Kashyap

You data which does not meet the criteria is not uploaded. In mast upload you get a list of records not uploaded and reason for it in a log file.

Vishal KashyapVishal Kashyap

There are ways to bypass validation rule.. try to discover them..  

 

Aishwarya pandey 3Aishwarya pandey 3
Can anyone tell me how to put validation on records inserted through csv file.
getting csv recordd through lightning component.