• Fazur
  • NEWBIE
  • 0 Points
  • Member since 2018
  • SFDC Dev
  • Sixt R & D

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi Team,

I am getting salesforce "Apex CPU time limit exceed exception" in the below code. Please help me to optimize the code or how to sort out this issue. Any help would be greatly appriciated. 


public static Map<String, Object> getCFAccountOverdue(Set<String> cfAccountIdSet ) {
    Map<String, Object> cfAccountOverdueMap = new Map<String, Object>();
    Map<String, Decimal> overdueDateRangeMap = new Map<String, Decimal>();
    
    for(Schema.pickListEntry eachVal : CF_Claim__c.Overdue_Date_Ranges__c.getDescribe().getPicklistValues()){
        overdueDateRangeMap.put(eachVal.getValue(), 0);
    }
        for(CF_Claim__c eachClaim : [SELECT CF_Account__c, Overdue_In_Days__c, Amount__c  FROM CF_Claim__c  WHERE CF_Account__c IN:cfAccountIdSet AND Status__c = 'Open' ORDER BY CF_Account__c,Overdue_In_Days__c Nulls last]) {                
            if( !cfAccountOverdueMap.containsKey(eachClaim.CF_Account__c) ) {   
                Map<String, Decimal> dateRangeMap = new Map<String, Decimal>(); 
                dateRangeMap.putAll(overdueDateRangeMap);
                dateRangeMap.put(eachClaim.Overdue_In_Days__c, eachClaim.Amount__c != null ? eachClaim.Amount__c : 0);
                cfAccountOverdueMap.put(eachClaim.CF_Account__c, dateRangeMap);                    
            }else {
                Map<String, Decimal> dateRangeMap = (Map<String, Decimal>)cfAccountOverdueMap.get(eachClaim.CF_Account__c);
                dateRangeMap.put(eachClaim.Overdue_In_Days__c, ((dateRangeMap.get(eachClaim.Overdue_In_Days__c)) + (eachClaim.Amount__c != null ? eachClaim.Amount__c : 0)));
                cfAccountOverdueMap.put(eachClaim.CF_Account__c, dateRangeMap);
            }
        }
    return cfAccountOverdueMap; 
}
  • August 23, 2018
  • Like
  • 0
Hi Team,

I am getting salesforce "Apex CPU time limit exceed exception" in the below code. Please help me to optimize the code or how to sort out this issue. Any help would be greatly appriciated. 


public static Map<String, Object> getCFAccountOverdue(Set<String> cfAccountIdSet ) {
    Map<String, Object> cfAccountOverdueMap = new Map<String, Object>();
    Map<String, Decimal> overdueDateRangeMap = new Map<String, Decimal>();
    
    for(Schema.pickListEntry eachVal : CF_Claim__c.Overdue_Date_Ranges__c.getDescribe().getPicklistValues()){
        overdueDateRangeMap.put(eachVal.getValue(), 0);
    }
        for(CF_Claim__c eachClaim : [SELECT CF_Account__c, Overdue_In_Days__c, Amount__c  FROM CF_Claim__c  WHERE CF_Account__c IN:cfAccountIdSet AND Status__c = 'Open' ORDER BY CF_Account__c,Overdue_In_Days__c Nulls last]) {                
            if( !cfAccountOverdueMap.containsKey(eachClaim.CF_Account__c) ) {   
                Map<String, Decimal> dateRangeMap = new Map<String, Decimal>(); 
                dateRangeMap.putAll(overdueDateRangeMap);
                dateRangeMap.put(eachClaim.Overdue_In_Days__c, eachClaim.Amount__c != null ? eachClaim.Amount__c : 0);
                cfAccountOverdueMap.put(eachClaim.CF_Account__c, dateRangeMap);                    
            }else {
                Map<String, Decimal> dateRangeMap = (Map<String, Decimal>)cfAccountOverdueMap.get(eachClaim.CF_Account__c);
                dateRangeMap.put(eachClaim.Overdue_In_Days__c, ((dateRangeMap.get(eachClaim.Overdue_In_Days__c)) + (eachClaim.Amount__c != null ? eachClaim.Amount__c : 0)));
                cfAccountOverdueMap.put(eachClaim.CF_Account__c, dateRangeMap);
            }
        }
    return cfAccountOverdueMap; 
}
  • August 23, 2018
  • Like
  • 0