how to write a trigger on a object that user can create only one record , but if any other person trying to create another record it should throw error.
trigger OnlyOneRecord on Account(before insert){
List<Account> lstAccount = [Select Id from Account];
Boolean createRecord = false;
if(lstAccount.size() > 1)
createRecord = true;
for(Account a : trigger.new){
if(createRecord == true)
a.addError('You can create only one record for Account );
}
}
Mark this as solve and choose the best answer if this answers your question.
Please use below code .
Refer the following code -
Mark this as solve and choose the best answer if this answers your question.
Regards,
Santosh Chitalkar