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
kevinedelmannkevinedelmann 

Update related object when field on case changes

We hae a look up field to Opportunites on the cases object.  I would like to update a field on the Opportunity when the Case is closed out.  I want to change the value from Sent for procesing, to Report Returned.

 

How can I get this done. 

 

FYI, I have no apex coding background so please take that into consideration in your answer.

 

Thanks in Advance.


Kevin Edelmann

Best Answer chosen by Admin (Salesforce Developers) 
kevinedelmannkevinedelmann
Here is a solution I came up with after looking at an example from another post
trigger UpdateOppty on Case (after update){

if (Trigger.new[0].Id == Trigger.old[0].Id &&
Trigger.new[0].Opportunity__c!= null &&
Trigger.new[0].Status == 'Closed' &&
Trigger.new[0].RecordTypeId == '012Q0000000CgyE' ) { //This assures this is an update, the opportunity field is populated and that the record type is for the Repricing


string oId = Trigger.new[0].Opportunity__c; //this is the opportunity object lookup ID
Opportunity oppty = [Select Id, Disruption_Repricing_Request__c from Opportunity where Id = :oId limit 1];


oppty.Disruption_Repricing_Request__c = 'Delivered';

update oppty;
}
}
Message Edited by kevinedelmann on 06-12-2009 03:02 PM
Message Edited by kevinedelmann on 06-12-2009 03:30 PM

All Answers

werewolfwerewolf
Your only option is in fact Apex code, specifically an Apex trigger, likely on after insert/update of Case which updates the corresponding Opportunity.
werewolfwerewolf
Anticipating your next question: you may find sort-of-relevant sample code on the CSS quick start wiki here.  Also check out the Force.com Cookbook.
kevinedelmannkevinedelmann

I have looked at all that stuff, just a bit tough for me to translate that to what I need.  I was hoping for a little help gettting the code close to what I would need so I could then take it from there.

 

Any help would be greatly appreciated.

werewolfwerewolf
Well, I have no sample code for you that updates an Opportunity from a case.  Have you considered perhaps hiring a consultant from this board (the Jobs Board I mean) to write that code for you as a one-off?  It should be quite simple and inexpensive, and you should be able to use that as a sample for similar types of things in the future.
kevinedelmannkevinedelmann
Here is a solution I came up with after looking at an example from another post
trigger UpdateOppty on Case (after update){

if (Trigger.new[0].Id == Trigger.old[0].Id &&
Trigger.new[0].Opportunity__c!= null &&
Trigger.new[0].Status == 'Closed' &&
Trigger.new[0].RecordTypeId == '012Q0000000CgyE' ) { //This assures this is an update, the opportunity field is populated and that the record type is for the Repricing


string oId = Trigger.new[0].Opportunity__c; //this is the opportunity object lookup ID
Opportunity oppty = [Select Id, Disruption_Repricing_Request__c from Opportunity where Id = :oId limit 1];


oppty.Disruption_Repricing_Request__c = 'Delivered';

update oppty;
}
}
Message Edited by kevinedelmann on 06-12-2009 03:02 PM
Message Edited by kevinedelmann on 06-12-2009 03:30 PM
This was selected as the best answer
werewolfwerewolf
That looks about right.  The only potential issue with that is that if multiple opportunities get updated in bulk then you'll only update your parent object for the first opportunity.  If all your users will be doing updates via the UI, though, then you're good to go.
kevinedelmannkevinedelmann

werewolf,

 

Thanks for the confirmation.  Yes, they will only be updating this case object via the UI. 


Now on to figuring out how to create a test so I can deploy it to production.  :)