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
Karthikeyan ChandranKarthikeyan Chandran 

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?
Best Answer chosen by Karthikeyan Chandran
Pankaj MehraPankaj Mehra
Hi Karthikeyan Chandran,

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

Pankaj MehraPankaj Mehra
Hi Karthikeyan Chandran,

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
 
This was selected as the best answer
Karthikeyan ChandranKarthikeyan Chandran
Great it's working thank you @Pankaj