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
jd_labbejd_labbe 

Assistance needed with adding logic on trigger to override $ amount with oppty products

Hello,

 

I am a newbie to apex coding, but trying to figure out a way to override the opportunity amount once opportunity products have been added. Through research, I was able to write a trigger that allows my sales reps to override the amount on an opportunity with Opportunity products. BTW, we utilize BigMachines for quoting, so the opportunity products are sync'd over from BigMachines each time the quote is updated. 

 

As I mentioned before, this solution works, but in order to remove the override flag and revert back to the quote amount, the salesrep must go back into BigMachines and re-save the quote record to initiate the product update thus updating the amount. What I would like to do is figure out a way to insert logic in the For statement that will either replace the Unit Price with "RealAmount" if the override flag = true  OR utilize Unit Price if override flag is not True.

 

Any ideas? Trigger code is below:

 

 

 

trigger OverrideLISalesPrice2 on Opportunity (after insert,after update) {
List<Id> oppIds = new List<Id>{};

for (Opportunity o : Trigger.new)

{
if (o.Use_Actual_Amount__c == True && o.HasOpportunityLineItem == true)
    oppIds.add(o.id);
}

 List<OpportunityLineItem> theLines = [SELECT Id,UnitPrice,RealAmount__c FROM OpportunityLineItem WHERE OpportunityId IN :oppIds];
 
   
    for(OpportunityLineItem OLI : theLines)  
                    {  
                        OLI.UnitPrice = OLI.RealAmount__c;  
                    }  
                update theLines;

 

Ritesh AswaneyRitesh Aswaney

you are adding opp ids to your selection list only if your flag is set to true. which means that if it is false, then the unitprice will not be overwritten and will apply. reckon your code already does that.

 

either that, or i haven't been able to get your problem.

jd_labbejd_labbe

Ritesh,

 

Thanks for the prompt response. Actually, the code works correctly today. The issue is that once the "Override" flag is removed, the value does not change back to quote amount automatically. I must re-initiate a change on the opportunity line items either manually (update all) or through BigMachines. This is what I am trying to automate. Should I just create a separate trigger where if "Override" flag is false, update the opportunity line items (re-save)? If so, how would I do this?

 

Thanks!!

Rahul Reddy 1Rahul Reddy 1
Ritest
Did you get any solution for this? Also can you send me 2 tickets on issues related to bigmachines and how you resolved them i mean the work around? That would be really helpful ASAP.

Truly appreciate your help.

Regards
Rahul
Rahul Reddy 1Rahul Reddy 1
Ritesh

Did you get any solution for this? Also can you send me 2 tickets on issues related to bigmachines and how you resolved them i mean the work around? That would be really helpful ASAP.

Truly appreciate your help.

Regards
Rahul