I am using database.query method to retrieve 2 fields from account. But when i tried to fetch get the values of that fields i am getting null value. Can someone help me. Here totalValueFieldName is API Name of the account field.
List<SObject> lstObj = Database.query(query);
system.debug('lstObj -- '+lstObj);
if(lstObj.size() > 0){
Decimal totalVal = 0;
Decimal actualVal = 0;
if(totalValueFieldName != null && totalValueFieldName.trim() != ''){
system.debug('totalValueFieldName top -- '+totalValueFieldName);
system.debug('lstObj[0].get totalValueFieldName top -- '+lstObj[0].get(totalValueFieldName));
totalVal = Decimal.valueOf(String.valueOf(lstObj[0].get(totalValueFieldName)));
}
actualVal = Decimal.valueOf(String.valueOf(lstObj[0].get(actualValueFieldName)));
//Means only 1 API Name was supplied and field type is percentage
if(totalVal == 0){
retVal = Integer.valueOf(actualVal );
}else if (actualVal > 0){
retVal = Integer.valueOf( ( actualVal / totalVal ) * 100 );
}
Thank you.