Skip to main content
Hi,

I need assistance with the proper code.

We have Parent Opportunities (Contract Vehicle) that have a Budget Amount field (Budget_Amount__c) to house the Total Contract Value.

We then have lookup relationship for related child opportunities that reflect the values of the individual task orders with amounts that should rollup to the overall Contract Vehicle Opportunity Budget_Amount__c.

I need assistance with code or formula to accomplish the following:

If an Opportunity has Related Opportunities with Opportunity record type = Standard

  

  • I want to display sum of amount of all Closed Won child opportunities in the custom CVAcquired_amount__c field in the parent opportunity record
  • I want to display sum of amount of all OPEN child opportunities  in the custom CVOpen_amount__c field in the parent opportunity record 
  • I want to display the TCV Difference by calculating Budget_Amount__c  - CVAcquired_amount__c in the parent opportunity record and it populate in the TCV_Difference_c field

Can someone please assist with the best way to accomplish this?

 

Thank you in advance!

 
2 Antworten
  1. 20. Apr. 2019, 11:34
    Hi Yolanda,

    For the first part of your question you try the following:

    //Bringing all Contract Vehicle records in a list.

    List<Contract Vehicle> listName = [SELECT id FROM Contract Vehicle LIMIT 1000];

    //Add Ids to a set

    Set<id> setName = new Set<id>();

    for(Contract Vehicle inst : listName){

    setName.add(inst.id);

    }

    //Bringing related child opportunities

    List<ChildOpp> list2 = [SELECT Id from ChildOpp where (ParentId IN: setName AND StageName = 'closed won' ];

    //Setting CVAcquired_amount__c of parent

    for(ContractVehicle a : listName){

    for(ChildOpp o : list2){

    if(o.ParentId == a.id){

    count++;

    a.CVAcquired_amount__c = count;

    }

    }

    count = 0;

    }

    /*this should do your work. Updated code with standard record type also if wanted. I haven't done because you haven't told much about it. Do tell if this works.*/

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

    Thanks,

    Ajay Dubedi
0/9000