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
Medhanie HabteMedhanie Habte 

Update Opportunity Amount for Recurring Subscriptions based on a currency field

Greetings,

I am trying to figure out a way to update the opportunity amount field to match a custom currency field that updates when a payment is made. My goal is for the amount field to match up with the custom currency (basically watching the field for any changes) and this would be contingent on if the recurring payment picklist field is set to recurring and the subscription end date is not greater than or does not equal TODAY. It would process on update.

I have attempted to do this via workflow, but this does not process during an APEX batch as the value is considered NULL. Any steps I can take. I trust this helps. I'll be looking around for ideas too.
Best Answer chosen by Medhanie Habte
Abhishek BansalAbhishek Bansal
Hi Medhaine,

As per my understanding you need to update the amount field on Opportunity whenever Transaction total is updated on Opportunity.
So based on this, i have written a trigger.
Please find it below :
 
trigger updateAmount on Opportunity (before update){
	for(Opportunity opp : trigger.new){
		if(opp.ChargentSFA__Transaction_Total__c != null){
			opp.Amount = opp.ChargentSFA__Transaction_Total__c;
		}
	}
}
Below steps describes the working of trigger :
  1. Trigger will run only when opportunity is updated
  2. When Opoortunity is updated and transaction total is not null than opportunity amount is equal to Transaction Total of opportunity.
Please let me know if your requirements are different from this.
You can also contact me on ny gmail : abhibansal2790@gmail.com
Or SkypeId : abhihsek.bansal2790.

Thanks,
Abhishek

All Answers

Danilo da SilvaDanilo da Silva
Try:
setup -> create -> Workflow & Approvals -> Process Builder
or
setup -> customize -> opportunities -> trigger
Abhishek BansalAbhishek Bansal
Hi Medhanie,

Your requirement can be easily achieved with the help of trigger.
If you can provide more information about your custom currency field like on which object does it exists and on what logical conditions you want to update Opportunity Amount than i can help you in writing a trigger.
Please provide more details on this.

Thanks,
Abhishek
Medhanie HabteMedhanie Habte

Absolutely, so we have the Opportunity object and a custom object being referenced called Transactions (API Name: ChargentSFA)

So the custom currency field in the Opportunity object in mind is called  
"ChargentSFA__Transaction_Total__c" This field is a summary roll up from the Transaction object that takes all of the single transaction amounts and compiles them into one. This individual transaction amount is based on "ChargentSFA__Charge_Amount__c" currency field, which indicates how much is to be charged in each transaction.

Some of the opportunity records are regarded as recurring in the Payment Status Picklist, and in that a schedule in the payment frequency field, such as weekly, monthly, annually. Opportunities are stopped if a billing amount is met, or a scheduled end is met. Usually we set it so that an end date is included.

We have a batch apex that runs once a week that processes active recurring gifts, creates transaction records and updates the "ChargentSFA__Transaction_Total__c", when this happens we would like for the Opportunity Amount field to reconcile and update to match the ChargentSFA_Transaction_Total__c field. Not all opportunities use the Transaction_Total field, but just those that do. I have attached an image same to signify. I can work with the code to work according to our needs. Thank you for guidance.
User-added image

Abhishek BansalAbhishek Bansal
Hi Medhaine,

As per my understanding you need to update the amount field on Opportunity whenever Transaction total is updated on Opportunity.
So based on this, i have written a trigger.
Please find it below :
 
trigger updateAmount on Opportunity (before update){
	for(Opportunity opp : trigger.new){
		if(opp.ChargentSFA__Transaction_Total__c != null){
			opp.Amount = opp.ChargentSFA__Transaction_Total__c;
		}
	}
}
Below steps describes the working of trigger :
  1. Trigger will run only when opportunity is updated
  2. When Opoortunity is updated and transaction total is not null than opportunity amount is equal to Transaction Total of opportunity.
Please let me know if your requirements are different from this.
You can also contact me on ny gmail : abhibansal2790@gmail.com
Or SkypeId : abhihsek.bansal2790.

Thanks,
Abhishek
This was selected as the best answer