You need to sign in to do that
Don't have an account?
KevinA.ax1880
Trigger to affect relate objects when a record is updated to active = 0
Hi, We are just getting started with SalesForce, and I am a developer proficient in .Net & SQL, I am having a hard time finding examples for updating child records of a custom object when it has it's status updated. I believe a trigger are what I am looking for, but the examples I am finding are all very generic. I would like some help in how to reference current the record's ID and how to perform an update of related child records. The two paradiagms I am familiar with are vb.net recordsets & SQL updates. I am literally starting with nothing: trigger trDeleteRelatedRecipients on Report_Package__c (after update) { } Any help would be greatly appreciated!
Hi Kevin,
Sorry I haven't been around to help more, it has been a busy week.
The modifications to the code that you have made look pretty good to me!
But I would make the following changes, so you are only doing one DML statment, rather than it been in a loop.
Also you don't need the try catch unless you wish to throw your own custom exception messages, you can do this as shown in the example in the updated code below:
Hope this helps!
All Answers
Hi Kevin,
For Trigger Code:
Class for method:
You could actually tidy up the above a little more, but I thought I would seperate it out a bit so you can get a feel for how it works!
Hi Gary,
Thanks for your reply. This does look helpful. If you don't mind, I have a few follow up questions:
1. I don't appear to be able to save the Class code in the same window as the trigger code. Where am I able to save the Class?
2. It appears that oldMap is a variable set holding the current records ID. Does that sound correct?
3. What does the newMap parameter signify?
EDIT: I found the Apex Classes, although it is balking at the 'with sharing' clause. In your class where you are checking the status to inactive to active the field is Active__c datatype: Formula (Checkbox), and will not compile when I try & evaluate with modified logic. Would you have anything to offer that may help getting past this obstacle?:
And finally, thanks again for the reply. I did search for quite a bit before posting this forum question. Would you know of any resources that would help me transition my VB and/or SQL knowledge to assist in my learning the apex methods and techniques?
I am able to get the Class to save/compile with the modifications below. Now onto seeing if the modified Class can be called from the trigger. Please stand by. UPDATE: Looks like it worked! Speaking with my manager, it may be more appropriate to flag/update the records instead of physically deleting them. Do you have an example of an update sub? My attempt to modify the script with changes found on the force.com help are throwing an error:
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Package_Recipient__c> at line 22 column 9
I still would love to know if you have a good resource for these types of questions.
Here is my final solution that I was able to get to work. I would appreciate any comments if there may have been a better solution. I basically had to modify firechimp's script from a delete to an update using a for loop. I am using a system.debug when trapping the error, but would like some feedback on providing an interactive error response (message box)
Hi Kevin,
Sorry I haven't been around to help more, it has been a busy week.
The modifications to the code that you have made look pretty good to me!
But I would make the following changes, so you are only doing one DML statment, rather than it been in a loop.
Also you don't need the try catch unless you wish to throw your own custom exception messages, you can do this as shown in the example in the updated code below:
Hope this helps!
HI Gary,
Thanks for the response & I can understand the delay. No worries. It helped push me to dig further myself. I'll check out your example once i get some coffee... - Thanks, Kevin
Hi Gary,
Moving on, can you reccommend a resource for going over the basics of apex programming? I am kinda just hunting & pecking.
- Thanks, Kevin
Can anyone help me with a raise error method that will display only my custom text & not all of the associated error/SalesForce messaging?
Curently, the class customException method that Gary helped me with displays something like below, and I am wanting to only display the message that I have delineated with the underscores____Cannot un-end date a recipient. Create a new contact____: