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
Hari G SHari G S 

System.DmlException

 

Hi,

 

trigger contactEndDate on Contract (after insert, after update) {
    Contract contract = trigger.new[0];
    list<Contact> contactList = new list<Contact>();
    Date sDate = contract.EndDate;
    Id accID = contract.AccountId;
    if(accID != null) {
        Contact[] con = [select SMA_End_Date__c,Name From Contact where AccountId = :accID];
        if(con != null && con.size() > 0) {
            for (Contact contact : con) {
                contact.SMA_End_Date__c = sDate;
                contactList.add(contact);               
            }
            update contactList;      
        }
    }
}

 

When i try to invoke the above trigger i am getting this error

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger contactEndDate caused an unexpected exception, contact your administrator: contactEndDate: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 003L0000002xSxCIAU; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, ContactObj: []: Trigger.contactEndDate: line 13, column 13

 

Can anyone please help me to resolve this problem?

 

Thanks and Regards

Hari G S

 

Best Answer chosen by Admin (Salesforce Developers) 
ashish raiashish rai

Hello,

       Well you have written validation rule on contact object which create this error. So my suggetion is use before update because it excute first before custom validation.

 

 

Think this will help you.

All Answers

Rahul SharmaRahul Sharma

There must be some validation rule on contact causing this exception, 

Check it and try to satisfy that condition before updating the contacts.

ashish raiashish rai

Hello,

       Well you have written validation rule on contact object which create this error. So my suggetion is use before update because it excute first before custom validation.

 

 

Think this will help you.

This was selected as the best answer