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
pharawaypharaway 

web-to-case update a field on Contact

Can someone point me in the right direction?  I am new to sforce, so please bare with me ...
 
I have created html forms using web-to-case.  When these cases are created in sforce, I want the Status field on the Contact table to be updated with different values based on what type of case was submitted (either Travel Request, Expense Report, or Academic form).  The Case is attached to the Contact record based on email address.
 
I thought maybe I should create a trigger on the Case object.  This is what I came up with .. but am getting an error.  Since this is new to me, I don't even know if I created it correctly or not ... or if there is another way I should do this.
 

trigger UpdateContactStatus on Case (after insert) {

if (Case.Reason = 'Travel Request')

    {Contact.Status__c = 'Received Travel Request from Candidate';

    }

  }

 

This is the error: 

Error: Compile Error: Expression cannot be assigned at line -1 column -1

 

Any help is much appreciated!
 
Thanks,
Paige
MeikoMeiko
Have you gotten an answer to this?
pharawaypharaway

Yes, I did.  It is working now.  Here it is:

trigger UpdateContactStatus on Case (after insert, after update) {
    Case c = Trigger.new[0]; //This creates a "Case" object called "c" and sets it to the record you just inserted
    if (c.Reason == 'Travel Request') { //This performs the equality check
        Contact con = new Contact(id = c.ContactId); //This creates a "Contact" object and sets it to be the Contact on the Case
        con.Status__c = 'Received Travel Request from Candidate'; //This sets the value on the Contact
        update con; //This updates the Contact
    }
}

 

Thanks!

 

MeikoMeiko
Thanks so much!