You need to sign in to do that
Don't have an account?
Can you help me on this, new to development using Apex Triggers.
Hi,
How do i update a field from one custom object to another standard object?
I have a field called "TF Amount" in a custom object "credit", i just want to update the "Amount" field in "Opportunity" with "TF amount" field.
Can any one help me on this ASAP?
How do i update a field from one custom object to another standard object?
I have a field called "TF Amount" in a custom object "credit", i just want to update the "Amount" field in "Opportunity" with "TF amount" field.
Can any one help me on this ASAP?
First of all you need to find a relationship between both the objects Opportunity and Credit, If Opportunity is Master-Details or Lookup to Credit object then you can simply perform below operation
trigger CreditTrigger on Credit__c (after update) {
List<Opportunity> lstOpportunity = new List<Opportunity>();
for(Credit__c c : Trigger.new) {
lstOpportunity.add(new Opportunity(Id = c.Opportunity__c,Amount = c.TF_Amount__c));
}
update lstOpportunity;
}
In case the Credit object is not directly related to Opportunity then you need to query Opportunity records with any relationships it exists.
Please let me know in case you are not able to do the update.
Thanks
All Answers
First of all you need to find a relationship between both the objects Opportunity and Credit, If Opportunity is Master-Details or Lookup to Credit object then you can simply perform below operation
trigger CreditTrigger on Credit__c (after update) {
List<Opportunity> lstOpportunity = new List<Opportunity>();
for(Credit__c c : Trigger.new) {
lstOpportunity.add(new Opportunity(Id = c.Opportunity__c,Amount = c.TF_Amount__c));
}
update lstOpportunity;
}
In case the Credit object is not directly related to Opportunity then you need to query Opportunity records with any relationships it exists.
Please let me know in case you are not able to do the update.
Thanks