You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
update fields from other object
Hello All,
I am hoping you can help me with this issue.
I have 2 custom objects.
Custom object A has fields quatity and estimate
Custom object B has field price.
Custom object A has a Lookup to Custom Objetc B.
So when a user enters a quantity on a custom object A fields, I need to go to custom object B and grab the price for those fields. Bring it back and multiply the value retrieved by the quantity to get the estimate.
So in the Class(already have a trigger and other classes for theis object) what is the best approach to make sure the update works not only on single record edits but during large data loads . My issue is that a user can edit up to 20 fields on record A and I am not sure how to update all of them all at once.
Thank you,
P
I am hoping you can help me with this issue.
I have 2 custom objects.
Custom object A has fields quatity and estimate
Custom object B has field price.
Custom object A has a Lookup to Custom Objetc B.
So when a user enters a quantity on a custom object A fields, I need to go to custom object B and grab the price for those fields. Bring it back and multiply the value retrieved by the quantity to get the estimate.
So in the Class(already have a trigger and other classes for theis object) what is the best approach to make sure the update works not only on single record edits but during large data loads . My issue is that a user can edit up to 20 fields on record A and I am not sure how to update all of them all at once.
Thank you,
P
All Answers
Greetings!
You can create the Estimate field as Formula field and get the value from the parent to calculate the total as per your requirement.
Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Thanks,
P
Thank you for the reply. Is the code the same for before insert and before update? In my class it is framed where I can seperate out if the action is a before update or before insert....
Also, there is 15 fields that could possibly be updated. Should I add those fields to a another list and then do an update outside the for loop?
Also, I saw an example that looked like this where they where copying fields from one object to another but I have never worked with schema before. Are you familiar with this syntax. Is it effecient?
Thank you,
P
If you seperate them, you can create a static trigger handler and call the handler in different places. or you can use cod like;
if (trigger.isbefore && (trigger.isInsert || trigger.isUpdate))
{
//call the method
}
2. for multipe fields processing, you may use code like below. You usually don't have to use a separate loop.
Will you elaborate on what you mean by 'you need to modify according to your code.'
Also, will you annotate on the code? This way I(and others reading this post) can better understand what each line of code is doing.
Thanks for your time and help,
P
Also, in my Class the methods have refrences to the previous and new vlaues of the object. Was not sure if that helps.
I would modify the handler method code:
global void beforeUpdate( List<SObject> oldSo, List<SObject> newSo )
When it is called in trigger, it would be:
SObjectClassHandler.beforeUpdate(trigger.Old,trigger.New);
Thank you,
P
Back to you the second last post, if you use the code in the trigger directly, you can do assignment "list<objectA__c> objectAs = trigger.new; ".
If using triggerhanlder class, you cannot as the method beforeUpdate won't understand what trigger.new is.
Hey David if you have time, would you look at https://developer.salesforce.com/forums/ForumsMain?id=9062I000000Qxk2QAC?
I am trying to match field names from 1 object to record names on another object.
Thank you,
P