Skip to main content
Hi,

   I want to perform a simple calculation on my Vf page. I have an integer  countCompleted and a decimal auditsToBeMade variable on the controller side.

public Integer getcountCompleted(){

        Integer countCompleted = [select COUNT() from Financial_Audit_Plan__c where YTD_Completed_Audits__c = 1 AND ((DM1__c = :userInfo.getUserID())

                                       OR (DM2__c = :userInfo.getUserID()) OR (DM3__c = :userInfo.getUserID()) OR (DM4__c = :userInfo.getUserID())) AND Calendar_year(Planification_Date__c) = :System.today().year()];

        System.debug('Total is '+countCompleted);

        return countCompleted;

    }

public Decimal getauditsToBeMade(){

        if(financial1!=null && total_size!=0)                                                                                

        auditsToBeMade = financial1[0].Total_Planned_Audits__c;

        return auditsToBeMade;

    }

I just want to dispaly something like this. ({!countCompleted}/{!auditsToBeMade})*100%  on the page.  I tried by creating a new variable on the controller and performing calculation there and then displaying that variable on the page.: 

public Decimal getpercentAudit(){

        if(auditsToBeMade!=0){

            Decimal percentAudit = (getcountCompleted()/getauditsToBeMade())*100;

            System.debug('Percent is '+percentAudit);

            return percentAudit.setScale(2, RoundingMode.HALF_UP);

        }else{

            return null;

        }

        

    }

But I get an exception whenever getauditsToBeMade() method doent return any value, how can i prevent this error? Please advice.

Thank you
2 answers
  1. Oct 18, 2016, 4:56 PM
    Hi Thank you for your reply. but I am not sure if I understand wht you are saying. Can you please elaborate or show some example?
0/9000