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
Dhruv NirgudeDhruv Nirgude 

i have created one future class so i found one error in Apex Job here is my error notification

ailedFirst error: Update failed. First exception on row 1 with id 0015g00000N8j5YAAR; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, For this particular combination we can not create more than one child record: []

My code
public class AccountCalculator {
@future
    public static void countContacts(List<Id> accIds){
        List<Account> accList  = [SELECT Id from Account where Id IN:accIds];

        for(Account acc : accList){
        acc.Number_Of_Contacts__c = acc.Contacts.size();    
        }        
        if(!accList.isEmpty()){
        }
    update accList;
    }
}


 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Dhruv,

There is some validation that an account cannot have more than 1 contact and the account you are updating has more than 1 Contact I hope which is causing the issue. 

You may need to remove that validation or this will be expected behaviour.

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

Thanks,