You need to sign in to do that
Don't have an account?
Trigger question
I'm Trying to write a trigger that I can call from multiple custom objects. I would like the trigger to pass an id from the object which is currently in focus to a class.
Resource contains the field hourly rate, which is needed on both the Resource Assignment, and Time objects. Both are related to the Resource object.Ultimately the hourly rate field from the Resource Assignment, and Time objects are used in calculations on another object so a Rollup field is not an option.
Here is how I envision it going:
trigger RAHourlyRate on Resource_Assignment__c(before insert, before update) { HourlyRate.Rate(/*pass the resource ID from the Resource Assignment Ojbect*/); } trigger TimeHourlyRate on Time(before insert, before update) { HourlyRate.Rate(/*pass the resource ID from the Time Management Ojbect*/); } public class HourlyRate{ public static void Rate() { /*Variable to receive the Resource ID passed from either the Resource assignment or Time Objects*/ for(Resource r:[SELECT id, Hourly_Rate__c FROM Resource__c WHERE id = :Variable passed in from trigger]) { Resource_Assignment__c.hourly_rate__c = r.hourly_rate__c; } Update Resource_Assignment__c; } }
How do I pass the resource ID from the trigger to the class?
Will this work how I envision it or is this completely incorrect?
Thank you in advance for your help.
Hi austin_steve,
try this:
Thank you for your input. I think I'm 90% there. In the code provided everything works (I think) except the Update Resource Assignment Hourly Rate line. As I read through it again I understand why but not sure how to rectify the issue.
So here is my next shot at it:
I think this looks correct and it seems to be passing the ID like I wanted, but in my class code I had previously been trying to update the Resource Assignment object, which I don't want to do in the class I want to do that in the Trigger. So below is what I think would be the correct way to do that. I'm just not sure if I need something in the class to capture the value as I pass control back to the trigger then update the RA__c table.
Again thank you for all your help
Steve
I don't understand very well the information described.
The main function you need is to update the record in the trigger?
If so, try this: