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
MMA_FORCEMMA_FORCE 

Update Amount Field in Salesforce via Trigger

Hi,
I have written this code to update Amount Field on Opportunity via trigger. The issue is I can see in the debug log that it is doing it correctly but on the opportunity the amount field does not change at all...
trigger Update_amount on Opportunity (before insert,before update) { 
  for (opportunity obj: trigger.new){ 
    obj.Amount = (obj.Total_Value__c*12)+ obj.Amount; 
    System.Debug('x'+ obj.Amount);
    System.Debug('y'+ obj.Total_Value__c);
    System.Debug('z'+ obj.Total_Value__c*12);
  } 
}

Its weird.... Any thoughts?
Thanks
Z
Paul S.Paul S.
Wierd - this wasn't working for me, either - then suddenly it started working.  Curious to hear if it now works on your end as well.
Himanshu ParasharHimanshu Parashar
Hi,

You can't update Opportunity Amount field if that opportunity contains lineitem. this is documented at Salesforce which says:

"Estimated total sale amount. For opportunities with products, the amount is the sum of the related products. Any attempt to update this field, if the record has products, will be ignored. The update call will not be rejected, and other fields will be updated as specified, but the Amount will be unchanged."

Please check Amount field description 

https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_opportunity.htm


Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer.