You need to sign in to do that
Don't have an account?
How Can I Convert an SObject Count/Sum to an Integer?
Hello, I have an SQL statement returns the count of of the number of records in my object:
countrecord = [SELECT COUNT(Probability__c)totalcount FROM Pipeline_Tracker_Ver_2__c];
I want to convert this to an integer, and add the value 1, so that I can set this as a dynamic value for ROWSPAN on one of my tables. I figured that since I am returning a count, I should be able to easily convert this to an integer. I have been trying the formula:
public Integer count; count = integer.valueof(countrecord) + 1;
However, I get the following error. It seems to be getting totalcount correct, which is 2, but I'm not sure why it's an invalid integer, or what they mean by external entry point.
System.TypeException: Invalid integer: [AggregateResult (totalcount:2)]
Class.MarginEscalatorsThermometerChart_Q1_2011.getCount: line 231, column 17 External entry point
Any insight would be great, as I'm not sure what else to try.
Thanks!
Mike
Hi,
Try this,
AggregateResult ar = [SELECT COUNT(Probability__c)totalcount FROM Pipeline_Tracker_Ver_2__c];
public Integer count;
count = (integer)ar.get('totalcount');
Check Whether it works.
Thanks,
BaLa
All Answers
Hi,
Try this,
AggregateResult ar = [SELECT COUNT(Probability__c)totalcount FROM Pipeline_Tracker_Ver_2__c];
public Integer count;
count = (integer)ar.get('totalcount');
Check Whether it works.
Thanks,
BaLa
what is the type of countrecord in your code....it should be of aggregate result object..?
hi kiran,
I am new to salesforce and have written the following trigger. But not able to write its test class.
can you help me with the code?? hoping for a +ve response..u can mail me at sahil.rajpal@accenture.com
TRIGGER
trigger increaseCount on Employee__c (after insert)
{
List<Employee__c> EmployeeToUpdate = new List<Employee__c>{};
for(Employee__c emp : Trigger.new)
{
Company__c company =[ select Number_of_Employees__c from Company__c where Id= :emp.Company__c ];
if (company.Number_of_Employees__c==Null)
{
company.Number_of_Employees__c=1;
}
else
{company.Number_of_Employees__c =company.Number_of_Employees__c+1;}
update company;
}
}
Thanks Bala,
That worked. It seems that I need to put my query into either a List or Aggregate Result.
I found that the following code worked as well.