function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce BuzzLogicSalesforce BuzzLogic 

A user can create 50 records per week in an object

  • User Deatails should be passed
  • Count of records should not exceed
  • user must create only 100 records not more than that per week.
  • Created date is this_week
  • Restrict the user from creating more than 100 records per week
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

You can write a trigger on the respective object as below. The below trigger will prevent user from creating more than 100 account in a week
 
trigger MaxAccount on Account (before insert) {
Integer maxAccounts = 100;
    if (maxAccounts != null) {
        Set<Id> userIds = new Set<Id>();
        Map<Id, Integer> AccountCountMap = new Map<Id, Integer>();

        for (Account c: trigger.new) {
            userIds.add(c.OwnerId);
            AccountCountMap.put(c.OwnerId, 0);
        }

        Map<Id, User> userMap = new Map<Id, User>([
            select Name
            from User
            where Id in :userIds
        ]);

        for (AggregateResult result: [
            select count(Id),
                OwnerId
            from Account
            where CreatedDate = this_week  and
                OwnerId in :userIds
            group by OwnerId
        ]) {
            AccountCountMap.put((Id) result.get('OwnerId'), (Integer) result.get('expr0'));
        }

        for (Account c: trigger.new) {
            AccountCountMap.put(c.OwnerId, AccountCountMap.get(c.OwnerId) + 1);

            if (AccountCountMap.get(c.OwnerId) > maxAccounts) {
                c.addError('Too many Account created this Week for user ' + userMap.get(c.OwnerId).Name );
            }
        }
    }
}

If this solution helps, Please mark it as best answer.

Thank,