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
viswanadh pviswanadh p 

Help me: How to write a update trigger for a case and contacts

Hi all,

My question is: If i update any case using trigger, then automatically the contacts object also be updated. Is it possible.  

Regards
Viswanadh
bob_buzzardbob_buzzard
Yes, you can do this using a trigger as long as there is a relationship between the contact and the case.  Here's an example from an SFSE post that updates a field on the associated account when a case changes. It should be straightforward to adapt:
 
Trigger CaseAfterInsertUpdate on Case (after insert, after update) {
    List<Account> accList = new List<Account>();
    for (Case c : Trigger.new) {
        Account acc = new Account(
            Id = c.Account.Id,
            Last_Survey_Sent__c = c.Last_Survey_Sent__c
        );
        accList.add(acc);
    }
    try {
        update accList;
    } catch (Exception ex) {
        System.debug('Could not update Last Survey Sent field on Account with cause: ' + ex.getCause())
    }
}
Original SFSE post can be found here (http://salesforce.stackexchange.com/questions/51620/apex-trigger-to-update-account-field-when-case-field-is-updated).