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
Vignesh RamshettyVignesh Ramshetty 

how to post questions

HI
 i have Customer_Policy_details__c object which is child to account which contines Expired, Active, getting expired records so, when ever the policy status changes to Getting expired or expired or deleated i want to update the count in account object below is the code able to save the class but count is not updating in Account object can anyone help.


trigger forcounting on Customer_Policy_details__c (after update,after delete) {



forcount.makefunction(trigger.new,trigger.old);



}


Public class forcount{

Public Static void makefunction (List<Customer_Policy_details__c> varnewCon,List<Customer_Policy_details__c> varold){


                         map<Id,Customer_Policy_details__c> varmaplist = new map<Id,Customer_Policy_details__c>();
                         
                         
                         
     if (varnewCon != null){

         for(Customer_Policy_details__c varc : varnewCon){

                  if(varc.Account__r != null ){
                    
                  varmaplist.put(varc.Account__r.id,varc);

           }

       }

    }

  if (varold != null){

         for(Customer_Policy_details__c varcc : varold){

                       if(varcc.Account__r != null )
{
                    
                  varmaplist.put(varcc.Account__r.id,varcc);

           }

       }

    }

List<Account> varacclist = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r) FROM Account Where id in: varmaplist.keyset()];

    
    if(varacclist.size() > 0) {
                   
                        for(Account a : varacclist  ){
                            for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{

                             if(csd.Policy_Status__c == 'Expired'){

                           a.Expired__c = a.Customer_Policy_details__r.size();
          }

                 else if(csd.Policy_Status__c == 'Getting Expited'){

                           a.Acction_Required__c = a.Customer_Policy_details__r.size();

           }
              else   if(csd.Policy_Status__c == 'Active'){

                           a.Active_Policies__c = a.Customer_Policy_details__r.size();

           }
        }
}

       update varacclist; 

      }

  }

}
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi ,

This seems to be duplicate question for the below.

https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=ALLQUESTIONS&id=9062I000000R3RfQAK (https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=ALLQUESTIONS&id=9062I000000R3RfQAK)

Can you close this question by marking this as best answer so it avoids duplicate effort.

Thanks,