You need to sign in to do that
Don't have an account?
Salesforce BuzzLogic
I want to restrict User from creating 50 records per week on account object
I want to restrict User from creating 50 records per week on account object .Here is my code.I am missing the logic.
public class RestrictAccountByUser {
public static void limitNoOfAccounts(List<Account> AccList) {
Integer maxAccounts = 50;
Set<Id> UserId =New Set<Id>();
Map<Id,User> UserIds =new Map<Id,User>([Select id from User ]);
List<Account> thisWeekAccountList = [select id,CreatedById,CreatedDate from Account where CreatedDate = THIS_WEEK and CreatedById=:UserInfo.GetUserId()];
Integer AccountListCount = [Select count() from Account where UserId=:UserIds'];
if (thisWeekAccountList.Size()>maxAccounts)
AccList[0].addError('Dear user you have exceeded the maximum number of Accounts allowed this Week.');
}
}
public class RestrictAccountByUser {
public static void limitNoOfAccounts(List<Account> AccList) {
Integer maxAccounts = 50;
Set<Id> UserId =New Set<Id>();
Map<Id,User> UserIds =new Map<Id,User>([Select id from User ]);
List<Account> thisWeekAccountList = [select id,CreatedById,CreatedDate from Account where CreatedDate = THIS_WEEK and CreatedById=:UserInfo.GetUserId()];
Integer AccountListCount = [Select count() from Account where UserId=:UserIds'];
if (thisWeekAccountList.Size()>maxAccounts)
AccList[0].addError('Dear user you have exceeded the maximum number of Accounts allowed this Week.');
}
}
I try with below code. its working for me. If this helps please mark it as best answer.
Thanks!!