• Afroz Khan 8
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
@AuraEnabled(cacheable = true)
public static String colorbox() {
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where DeveloperName = 'test_report'];
String reportId = (String)reportList.get(0).get('Id'); Reports.ReportDescribeResult reportInfo = Reports.ReportManager.describeReport(reportId); Reports.ReportExtendedMetadata reportMeta = reportInfo.getReportExtendedMetadata(); Map<String, Reports.DetailColumn> columnData = reportMeta.getDetailColumnInfo(); for(Reports.DetailColumn column: columnData.values()) { System.debug(column.getName()); System.debug(column.getLabel()); } // Get the report metadata Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId); System.debug('describe: ' + describe); Reports.ReportMetadata reportMd = describe.getReportMetadata(); System.debug('reportMd: ' + reportMd); // Override filter and run report Reports.ReportFilter filter = reportMd.getReportFilters()[0]; System.debug('filter: ' + filter); Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd); System.debug('results: ' + results); Reports.ReportFactWithSummaries factSum = (Reports.ReportFactWithSummaries)results.getFactMap().get('0!0'); System.debug('Value for November: ' + factSum.getAggregates()[0].getLabel()); String LateRecord = (string)factSum.getAggregates()[0].getLabel(); system.debug('LateRecord='+LateRecord); @testVisible Integer i = integer.valueof(LateRecord); system.debug('i='+i); if(i > 2) { //red return 'TRUE'; } //green return Null; }
Whenever trying to execute the below code I am getting the error:


global class batchclass implements Database.Batchable<sObject>,Database.Stateful{
    global integer countopp;
    global Decimal sumamount;
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query='Select id, Customer_segment__c ,(select accountid,amount,Stagename,Createddate from Opportunities) from Account Limit 500';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Account> lstacc)
    {
         AggregateResult[] gr= [SELECT Accountid,SUM(Amount) optyamt,Count(Id) cid FROM Opportunity Where Accountid IN:lstacc Group by Accountid];
    
    for(AggregateResult ag:gr){
        sumamount = (Decimal)ag.get('optyamt');
        countopp=(integer)ag.get('cid');
    }

        for(account acc:lstacc){
            if(sumamount<50000 && countopp>1){
                        acc.Customer_segment__c = 'Hot';
            }
            else if(sumamount>=50000 && countopp>1){
                        acc.Customer_segment__c = 'Medium';
            }
             else{
            acc.Customer_segment__c = 'Low';
        }
        update lstacc;
    }
    }
    global void finish(Database.BatchableContext BC){
        system.debug('finish'); 
    }
}
@AuraEnabled(cacheable = true)
public static String colorbox() {
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where DeveloperName = 'test_report'];
String reportId = (String)reportList.get(0).get('Id'); Reports.ReportDescribeResult reportInfo = Reports.ReportManager.describeReport(reportId); Reports.ReportExtendedMetadata reportMeta = reportInfo.getReportExtendedMetadata(); Map<String, Reports.DetailColumn> columnData = reportMeta.getDetailColumnInfo(); for(Reports.DetailColumn column: columnData.values()) { System.debug(column.getName()); System.debug(column.getLabel()); } // Get the report metadata Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId); System.debug('describe: ' + describe); Reports.ReportMetadata reportMd = describe.getReportMetadata(); System.debug('reportMd: ' + reportMd); // Override filter and run report Reports.ReportFilter filter = reportMd.getReportFilters()[0]; System.debug('filter: ' + filter); Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd); System.debug('results: ' + results); Reports.ReportFactWithSummaries factSum = (Reports.ReportFactWithSummaries)results.getFactMap().get('0!0'); System.debug('Value for November: ' + factSum.getAggregates()[0].getLabel()); String LateRecord = (string)factSum.getAggregates()[0].getLabel(); system.debug('LateRecord='+LateRecord); @testVisible Integer i = integer.valueof(LateRecord); system.debug('i='+i); if(i > 2) { //red return 'TRUE'; } //green return Null; }
Whenever trying to execute the below code I am getting the error:


global class batchclass implements Database.Batchable<sObject>,Database.Stateful{
    global integer countopp;
    global Decimal sumamount;
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query='Select id, Customer_segment__c ,(select accountid,amount,Stagename,Createddate from Opportunities) from Account Limit 500';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Account> lstacc)
    {
         AggregateResult[] gr= [SELECT Accountid,SUM(Amount) optyamt,Count(Id) cid FROM Opportunity Where Accountid IN:lstacc Group by Accountid];
    
    for(AggregateResult ag:gr){
        sumamount = (Decimal)ag.get('optyamt');
        countopp=(integer)ag.get('cid');
    }

        for(account acc:lstacc){
            if(sumamount<50000 && countopp>1){
                        acc.Customer_segment__c = 'Hot';
            }
            else if(sumamount>=50000 && countopp>1){
                        acc.Customer_segment__c = 'Medium';
            }
             else{
            acc.Customer_segment__c = 'Low';
        }
        update lstacc;
    }
    }
    global void finish(Database.BatchableContext BC){
        system.debug('finish'); 
    }
}