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
RelaxItsJustCodeRelaxItsJustCode 

Roll up summary class need a guru second set of eyes on this... please help...

    Public static void CaseRollUpFieldsOpportunity(Map<Id,Opportunity> oldMap, Map<Id,Opportunity> newMap)
    {
    List<Id> OpptyCaseIds = new List<Id>();
    map<Id,Double> CaseMap = new map <Id,Double>(); 

    for (Opportunity o : newMap.Values())
    {   
        if(o.Total_Adjusted__c > 0)
        {      
                    OpptyCaseIds.add(o.Case_No__c);
        }
    }

    for(AggregateResult q : [Select Case_No__c, SUM(Total_Adjusted__c) From Opportunity Where Case_No__c in: OpptyCaseIds Group By Case_No__c])
        {
       // CaseMap.put((Id)q.get('Case_No__c'),(Double)q.get('expr0'));
    }
    
    List<Case> CasesToUpdate = new List<Case>();
    
    for(Case a : [Select Id, Total_Adjusted__c from Case where Id IN :OpptyCaseIds])
    {
            Double AdjustedSum = CaseMap.get(a.Id);
            a.Total_Adjusted__c = AdjustedSum;
            CasesToUpdate.add(a);
    }

    update CasesToUpdate;
    }

 I have a problem with the commented field. btw Case_No__c is case id....  I just need to know how to add the double to the map so I can update the field on the case record.  Please let me know what you think.

 

Thank you,

Steve Laycock

Best Answer chosen by Admin (Salesforce Developers) 
Kiran  KurellaKiran Kurella

 

Try this:

 

for(AggregateResult q : [Select Case_No__c, SUM(Total_Adjusted__c) TotalAdjusted From Opportunity Where Case_No__c in: OpptyCaseIds Group By Case_No__c]) {


      CaseMap.put((Id)q.get('Case_No__c'),(Double)q.get('TotalAdjusted'));
}

All Answers

Rahul_sgRahul_sg

try using set ...instead of List for OpptyCaseIds 

 

also refer http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_double.htm

Kiran  KurellaKiran Kurella

 

Try this:

 

for(AggregateResult q : [Select Case_No__c, SUM(Total_Adjusted__c) TotalAdjusted From Opportunity Where Case_No__c in: OpptyCaseIds Group By Case_No__c]) {


      CaseMap.put((Id)q.get('Case_No__c'),(Double)q.get('TotalAdjusted'));
}

This was selected as the best answer