You need to sign in to do that
Don't have an account?

Number of assets on account
Hi
Iam trying to find number of assets on account with some coditions
i had used aggregate funtion,its not giving the correct results.Please i need help on this,waiting for the reply
AggregateResult[] groupedResults1 =([SELECT AccountId,COUNT(ID)ct FROM Asset where accountid in:contId AND Status != 'Returned' AND Type__c !='Converted' group by AccountID,Status,Type__c]);
Hi, I don't believe you can mix count() with other fields. You either do a count, or you do a normal select. Therefore your SOQL should be along the lines of:
SELECT COUNT() FROM Asset where [etc]
Sorry, just checked some of my own code for the correct setup of this - it should be along these lines:
integer cnt=Database.countQuery('SELECT count() from <etc>');
actually i was using in batch
Hi BPrakash
Syntactically your query is correct, to help further on this I would like to know what result you are expecting and what it is returning?
i want only the assets which the type!= 'Returned and status!= converted
but iam getting three results and i want only the count with the assets which met above condition.
Please help me that will great
BPrakash
You have a filter on Account also in your query which you are passing a list/set of Account/Id. If this list/set has more than one account and assets related to those accouts fullfil your other two conditions certainly it will return more than one result in AggregateResults.
Put you result in System.Debug and see which AccountIds you get in result and check if assets related to those fulfill your conditions.