Skip to main content
public class UpdateCustomerclass

{    

    @InvocableMethod    

public static void Updatecustomer(List<vlocity_cmt__OpportunityMember__c>  oppMemberRecords) { 

    {

        Map<Id,Id> accOpp= new Map<Id,Id>();

        List<Account>  accUpdate= new List<Account>();

        if(oppMemberRecords.size() > 0) {

            for(vlocity_cmt__OpportunityMember__c memberRecords : oppMemberRecords) {

                if(memberRecords.vlocity_cmt__ServiceAccountId__c != NULL ) {             

                    accOpp.put(memberRecords.vlocity_cmt__ServiceAccountId__c , memberRecords.vlocity_cmt__OpportunityId__c);     

                } 

            }

        

       Map<Id,AggregateResult> mapOptyUsageSum = new map<Id,AggregateResult>([SELECT vlocity_cmt__OpportunityId__c, SUM(vlocity_cmt__ServiceAccountId__r.Service_EstimatedMonthlyUsage__c) total FROM vlocity_cmt__OpportunityMember__c WHERE vlocity_cmt__OpportunityId__c in :accOpp.keyset() group by vlocity_cmt__OpportunityId__c ]);

        system.debug('mapOptyUsageSum'+mapOptyUsageSum);        

        List<Opportunity> updateOptyList = new List<Opportunity>();

        Double annualUsage;

        

     for(Opportunity Oppty: [select id, Customer_Class__c from Opportunity where id in :accOpp.keyset()])

        {

            if(mapOptyUsageSum.ContainsKey(Oppty.Id))

            {

                annualUsage = ((decimal)mapOptyUsageSum.get(Oppty.Id).get('total'))*12;

                

                if(annualUsage > 12500)

                {

                    Oppty.Customer_Class__c ='Commercial';

                }else{

                    Oppty.Customer_Class__c ='Small Commercial'; 

                } 

                updateOptyList.add(Oppty);

            }                    

        }       

        if(updateOptyList.size()>0)

        {

            update updateOptyList;

        }

    }

}

}

}
2 respostas
  1. 23 de jan. de 2021, 08:27
    Hi Swetha, Thanks for the reply.

    can you help me with the Test class for the below.

    @isTest(SeeAllData=true)

    private class UpdateCustomerclass_Test {

      private static testmethod void  CreateRelatedData(){

        Test.startTest();

        Id currentUserId=UserInfo.getUserId();

    Please help me to complete this , im  new to Apex coding
0/9000