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
Chie MenChie Men 

When is the Amount Used in the Usage-based entitlements updated?

When and how is the Amount Used  column in the Usage-based entitlements updated? I have a Customer Community Plus Login license and I assigned a user to that license. After that, I logged in. I checked the company information page, Customer Community Plus login license is now less than 1. When I checked the Usage-based entitlements, neither the Power Customer Community Daily Unique Logins or Power Customer Community Logins has a value in the Amount Used.
I thought that when I logged in using the user i just created, there will be a value on the Amount used.
Ashish Dixit 2Ashish Dixit 2
Hi Everbody,
I am very much new in test class so  i want test class for my triggerhandler class, could you please help me  provide the code for below test class.PFA code.Thank you so much.

public without sharing class PMOTriggerHandlers {

    /** BeforeInsertHandler
     * @author: Martin Gardner
     * @date: 23/03/2015
     * @description: Before Insert handler on PMO Object
     * @variables: Definition of variables (optional)
     * @version: 1.0 - created from IC_PMOTrigger
     */
    public class BeforeInsertHandler implements Triggers.HandlerInterface{

        public void handle() {
        
        if(checkPMOcount()){
            System.debug(LoggingLevel.INFO, 'Pre insert handling ' + Trigger.new );
            //MG cDecisions 04/11/2014 removing the update of PMO stage to opportunity
            Set<Id> setOppIds = new Set<Id>();
            //MG cDecisions //public List<Opportunity> ListOfOppToUpdate = new List<Opportunity>();
            Map<Id,Opportunity> mapOfOpportunity ;
                
            //retrieve the ListOfOpportunityIds
            for(PMO__c rec : (List<PMO__c>)trigger.new){
                System.debug('*****PMO ID****'+rec.JJ_Opportunity__c);
                if(rec.JJ_Opportunity__c!=NULL){
                    setOppIds.add(rec.JJ_Opportunity__c);
                }
            }

            //map to store the parent Opportunities for all PMOs being inserted or updated
            //mapOfOpportunity = new Map<Id,Opportunity>([Select Id,Name,JJ_Share_Access__c,JJ_PMO_R_D_Stage__c FROM Opportunity WHERE Id IN :setOppIds]);
            mapOfOpportunity = new Map<Id,Opportunity>( [SELECT Id,Name,JJ_Share_Access__c FROM Opportunity WHERE Id IN :setOppIds] );
            System.debug('************'+mapOfOpportunity);
            if(mapOfOpportunity!=NULL){
                for(PMO__c rec : (List<PMO__c>)trigger.new){                
                    /**********************Sets the access level on the PMO based on the parent Opportunity***************************/
                    if( rec.JJ_Opportunity__c != NULL && 
                        mapOfOpportunity.containsKey(rec.JJ_Opportunity__c) && 
                        mapOfOpportunity.get(rec.JJ_Opportunity__c).JJ_Share_Access__c!=NULL){
                        rec.JJ_Private__c = mapOfOpportunity.get(rec.JJ_Opportunity__c).JJ_Share_Access__c.equalsIgnoreCase(IC_Constants__c.getInstance('Private Share').value__c)?True:False;
                    }
                }
            }
            IC_PMOSetStageDate.setRDStageDate(trigger.new);
           }             
        }  
        
        public boolean checkPMOcount(){
         Set<Id> existingOppIds=new Set<Id>();
         Boolean Status = false;
         PMOModuleSecurity.updateAccess(trigger.new);
         existingOppIds =  PMOModuleSecurity.checkNoOfPMOModule(trigger.new);
         if(existingOppIds.size()>0){                  
            for(PMO__c rec : (List<PMO__c>)trigger.new){                
                if(existingOppIds.contains(rec.JJ_Opportunity__c)){
                    rec.addError('Another PMO module already exists for this opportunity. Only 1 PMO module is allowed per opportunity.');
                    Status=false;
                }
                else{
                   status=true;
                }
            }
         }
         return status; 
    }     
 }
    
    /** AfterInsertHandler
     * @author: Martin Gardner
     * @date: 23/03/2015
     * @description: After Insert handler on PMO Object
     * @variables: Definition of variables (optional)
     * @version: 1.0 - created from IC_PMOTrigger
     */
    public class AfterInsertHandler implements Triggers.HandlerInterface{

        public void handle() {
            System.debug(LoggingLevel.INFO, 'Post insert handling ' + Trigger.new );
            new AccessManager().grantAccess((List<PMO__c>)Trigger.new);
            PMOTriggerHandlers.processNewOrUpdatedPMO((List<PMO__c>)Trigger.new);
        }       
    }
    /** BeforeUpdateHandler
     * @author: Martin Gardner
     * @date: 23/03/2015
     * @description: Before Update handler on PMO Object
     * @variables: Definition of variables (optional)
     * @version: 1.0 - created from IC_PMOTrigger
     */
    public class BeforeUpdateHandler implements Triggers.HandlerInterface{

        public void handle() {
            System.debug(LoggingLevel.INFO, 'Pre update handling ' + Trigger.new );
            IC_PMOSetStageDate.setRDStageDate((List<PMO__c>)trigger.new);
        }       
        
    }   
    /** AfterUpdateHandler
     * @author: Martin Gardner
     * @date: 23/03/2015
     * @description: After Update handler on PMO Object
     * @variables: Definition of variables (optional)
     * @version: 1.0 - created from IC_PMOTrigger
     */
    public class AfterUpdateHandler implements Triggers.HandlerInterface{

        public void handle() {
            System.debug(LoggingLevel.INFO, 'Post update handling ' + Trigger.new );
            PMOTriggerHandlers.processNewOrUpdatedPMO((List<PMO__c>)Trigger.new);
        }       
        
    }   

    /** BeforeDeleteHandler
     * @author: Martin Gardner
     * @date: 23/03/2015
     * @description: Before delete handler on PMO Object
     * @variables: Definition of variables (optional)
     * @version: 1.0 - created from IC_PMOTrigger
     * @version: 1.1 - Changed name to BeforeDeleteHandler from AfterDeleteHandler
     */
    public class BeforeDeleteHandler implements Triggers.HandlerInterface{

        public void handle() {
            System.debug(LoggingLevel.INFO, 'Post delete handling ' + Trigger.old );
            PMOTriggerHandlers.processDeletedPMO((List<PMO__c>)Trigger.old);
        }       
        
    }

    /** processNewOrUpdatedPMO
     * @author Martin Gardner
     * @description Processes any new or updated PMO records 
     * @param list<PMO__c> records : the new or updated PMO records to process.
     * @return void
     *
     * @author: Hamayoun Khan
     * @date: 04/28/2015
     * @version: 2.0 - added logic to include Score_Team__c object for Alliance Manager
     */
    private static void processNewOrUpdatedPMO(list<PMO__c> records){
            //create list to hold updating record in 
            Set<Score__c> scoresToUpdate = new Set<Score__c>();
            //create a set of opp ids
            Set<Id> oppIds = new Set<Id>();
        Set <Id> pmoIds = new Set <Id> () ;
            Map<Id, PMO__c> mapPMOByOpp = new Map<Id, PMO__c>(); /** Removes duplicates by Opp Id **/
            for(PMO__c rec: (List<PMO__c>)records){
                oppIds.add(rec.JJ_Opportunity__c);
                mapPMOByOpp.put(rec.JJ_Opportunity__c, rec);
                pmoIds.add(rec.Id);
            }
            System.debug(LoggingLevel.INFO, 'processNewOrUpdatedPMO : Opp Ids ' + oppIds);
            System.debug(LoggingLevel.INFO, 'processNewOrUpdatedPMO : mapPMOByOpp ' + mapPMOByOpp);
            //Create a map of Opp Id to score
            Map<Id, Score__c> mapScores = new Map<Id, Score__c>([SELECT Id, IC_Opportunity__c  
                                                                FROM Score__c 
                                                                WHERE IC_Opportunity__c in :oppIds]);
            System.debug(LoggingLevel.INFO, 'processNewOrUpdatedPMO : mapScores ' + mapScores);
            for(Score__c rec:mapScores.values()){
                rec.Post_Deal_Execution__c = mapPMOByOpp.get(rec.IC_Opportunity__c).Project_Event_Outcome__c;
                scoresToUpdate.add(rec);
            }
            //update scores 
            list<Score__c> result = new List<Score__c>(scoresToUpdate);
            update  result;

        // Now handle Score_Teams
        if (Trigger.isUpdate) {
        // before inserting, delete all STs associated with PMO being updated
            List<Score_Team__c> sts = [select Id from Score_Team__c where PMO__c in :pmoIds] ;
            delete (sts) ;
        }
        // Add new Score_Team rec for all relevant Scores
        List<Score_Team__c> stsToAdd = new List<Score_Team__c>() ;
            for(Score__c rec:mapScores.values()){
                String am = mapPMOByOpp.get(rec.IC_Opportunity__c).JJ_IC_Alliance_Manager__c;
        if (am != null) {
            String pmoId = mapPMOByOpp.get(rec.IC_Opportunity__c).Id;
            Score_Team__c st = new Score_Team__c (Score__c=rec.Id, Role__c='Alliance Manager', User__c=am, Opportunity_Type__c='IC', PMO__c=pmoId);
            stsToAdd.add(st) ;
        }
            }
        insert stsToAdd;
    }

    /** processDeletedPMO
     * @author Martin Gardner
     * @description Processes any new or updated PMO records 
     * @param list<PMO__c> newRecords : the new or updated PMO records to process.
     * @return List<Score__c>
     *
     * @author: Hamayoun Khan
     * @date: 04/28/2015
     * @version: 2.0 - added logic to include Score_Team__c object for Alliance Manager
     */
@TestVisible private static void processDeletedPMO(list<PMO__c> records){
        // Update any Score__c associated with the Opportunity associated with the PMOs being deleted
            Set<Score__c> scoresToUpdate = new Set<Score__c>();
            //create a set of opp ids
            Set<Id> oppIds = new Set<Id>();
        Set <Id> pmoIds = new Set <Id> () ;
            for(PMO__c rec: (List<PMO__c>)records){
                oppIds.add(rec.JJ_Opportunity__c);
                pmoIds.add(rec.Id);
            }
            //Get a map of the scores that need to be updated.
            Map<Id, Score__c> mapScores = new Map<Id, Score__c>([SELECT Id, IC_Opportunity__c 
                                                                FROM Score__c 
                                                                WHERE IC_Opportunity__c in :oppIds]);

            //Logic to run on deletion of PMO object
            for (Score__c s: mapScores.values()) {
                //update Post_Deal_Execution__c and add to set (in case multiple scores existed for same PMO object)   
                s.Post_Deal_Execution__c = null;
                scoresToUpdate.add(s);                           
            }
            //update scores 
            list<Score__c> result = new List<Score__c>(scoresToUpdate);
            update  result;

        // Delete all Score_Team__c for Scores
        List<Score_Team__c> sts = [select Id from Score_Team__c where PMO__c in :pmoIds] ;
        delete (sts) ;
    }               
}