You need to sign in to do that
Don't have an account?
Brooks Johnson 6
Convert String to Integer
I am trying to write a method to get the median value on a set of scores on the Contact object. I have a list from the Contact object that is looking for one value from a numeric field. But I am getting an error that arithmetic expressions must use numeric arguments. I am assuming this is coming from my trying to do math with my Contact list values?
public class CalculateHealthMetrics { public static void getMedianPardotScore(){ Decimal medianPiScore = 0; Integer listSize = 0; Integer index = listSize -1; //get all Pardot Scores in Descending Order List<Contact> pardotScores = [SELECT pi__score__c FROM Contact ORDER BY pi__score__c DESC]; listSize = pardotScores.size(); system.debug('list size =' + listSize); pardotScores.sort(); if(Math.mod(listSize, 2) == 0){ medianPiScore = (pardotScores[(index -1) / 2] + pardotScores[(index / 2) + 1]) / 2; } } }
You are using the complete contact record in your calculation which the reason you are getting the error. I have modified the code as per below:
Please let me know if you face any issues with the code mentioned above.
Thanks,
Abhishek Bansal.