You need to sign in to do that
Don't have an account?
manjunath vivek
Unable to sum the field values using controller
Hi all,
My visualforce code and controller is as follows.
<apex:page standardcontroller="Bankloan__c" extensions="inform">
<apex:form >
<apex:pageBlock >
<apex:pageblockTable value="{!bank}" var="b">
<apex:column value="{!b.EMI__c}"/>
<apex:column value="{!b.Bank_name__c}"/>
<apex:column value="{!b.Loan_type__c}"/>
<apex:column value="{!b.EMI_date__c}"/>
<apex:column value="{!b.Loan_taken__c}"/>
</apex:pageblockTable>
<apex:outputText value="{!emi}"/>
<BR></Br>
<apex:outputText value="{!loanamount}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Public class inform{
Public List<Bankloan__C> Bank {get;set;}
public inform(ApexPages.StandardController controller) {
Bank=[Select EMI__c,Bank_name__c,Loan_type__c,EMI_date__c,Loan_taken__c from Bankloan__c];
}
Public Decimal getemi(){
Decimal sum=0;
For(Bankloan__C BK: Bank){
Sum+=BK.EMI__C;
}
Return Sum;
}
Public Decimal getloanamount(){
Decimal summ=0;
For(Bankloan__C BK: Bank){
Summ=BK.Loan_taken__c;
}
Return Summ;
}
}
It works fine, but when I change Summ=BK.Loan_taken__c;( I have written it in bold letters in the above code)
to Summ+=BK.Loan_taken__c;, it throws an error message "System.NullPointerException: Argument cannot be null.
Class.inform.getloanamount: line 19, column 1",I a not able to fix the issue, i have used same type of method in the above code
for retrieving EMI,without any issue.I made sure there are values available for Loan_taken__c field, still unable to fix he isssue.
Can some one help me please?
My visualforce code and controller is as follows.
<apex:page standardcontroller="Bankloan__c" extensions="inform">
<apex:form >
<apex:pageBlock >
<apex:pageblockTable value="{!bank}" var="b">
<apex:column value="{!b.EMI__c}"/>
<apex:column value="{!b.Bank_name__c}"/>
<apex:column value="{!b.Loan_type__c}"/>
<apex:column value="{!b.EMI_date__c}"/>
<apex:column value="{!b.Loan_taken__c}"/>
</apex:pageblockTable>
<apex:outputText value="{!emi}"/>
<BR></Br>
<apex:outputText value="{!loanamount}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Public class inform{
Public List<Bankloan__C> Bank {get;set;}
public inform(ApexPages.StandardController controller) {
Bank=[Select EMI__c,Bank_name__c,Loan_type__c,EMI_date__c,Loan_taken__c from Bankloan__c];
}
Public Decimal getemi(){
Decimal sum=0;
For(Bankloan__C BK: Bank){
Sum+=BK.EMI__C;
}
Return Sum;
}
Public Decimal getloanamount(){
Decimal summ=0;
For(Bankloan__C BK: Bank){
Summ=BK.Loan_taken__c;
}
Return Summ;
}
}
It works fine, but when I change Summ=BK.Loan_taken__c;( I have written it in bold letters in the above code)
to Summ+=BK.Loan_taken__c;, it throws an error message "System.NullPointerException: Argument cannot be null.
Class.inform.getloanamount: line 19, column 1",I a not able to fix the issue, i have used same type of method in the above code
for retrieving EMI,without any issue.I made sure there are values available for Loan_taken__c field, still unable to fix he isssue.
Can some one help me please?
Please use the below code to check null values :
if( BK.Loan_taken__c != null)
Summ+=BK.Loan_taken__c;
Let me know for any issues
Regards,
BDatla
Let me know if you need any clarification.
Regards,
BDatla