Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger ErrorMessage on Account (before insert) { if(Trigger.isInsert && Trigger.isBefore){ User_Account_Count.count_Account_Mounth(Trigger.new); } }
public class User_Account_Count { public static void count_Account_Mounth(List<Account> accListInsert){ try{ String userId = UserInfo.getUserId(); List<Account> accList = new List<Account>(); accList = [SELECT Id, Name FROM Account WHERE OwnerId =: userId AND CreatedDate = THIS_MONTH]; System.debug('Account'+accList.size()); if(accList.size() > 20){ for(Account acc : accListInsert){ acc.adderror('Cannot insert morethan 20 account in a month'); } } }catch(Exception exp){ System.debug('Exception Cause---'+exp.getMessage() + 'Line Number---'+exp.getLineNumber()); } } }
You can use the below code.
I have written a trigger as per your requirement.
<<<<<----Trigger ---->>>>>
<<<<<----Apex Class------>>>>>>
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com