0
List<Contract> contracts = new List<Contract> {  
    new Contract(  
              AccountId = DB.getAccountByNUID('800000004').Id,   
              Academic_Year__c = '2020-2022',  
              Is_Canceled__c = false,   
              StartDate = Date.newInstance(2021, 10, 10),  
              RecordTypeId = CPSContractUtil.getRecordTypeId('Faculty Teaching Assignment'),  
              //Course_Section_ID__c = getCourseSectionByName('202215-80003').id,  
              Type__c = 'Primary',  
              Status = 'Draft'  
    )      
};  
insert contracts;  

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Account does not have valid appointment for Class Academic Year.: [] this error is coming.

1 Answer 1

3

You seem to have a custom validation rule in contract that requires you to have an appointment for the account and class year.

You need to create the relevant objects before inserting the contract.

You're also getting an account by NUID (is that the ID?), with a hard-coded ID. Have you created it earlier in your test? If so, avoid the hard-coded value and reference it from the account object instead.

If you want more help with the code and so on, we'd need to have at least the code for the whole test and some idea of what the validation rule is.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .