You need to sign in to do that
Don't have an account?
GROUP BY with account type - is there a way to do it without using aggregate objects?
Hello all and thanks in advance for your replies on this. I checked similar question but I didn't find something matching my usecase.
My code is really straightforward (it works without GROUP BY): I want to take a series of fields from account when some conditions are met (the last update on an account should be higher than 150 days).
Below the working code (without GROUP BY):
public Account getAccount()
{
account = [SELECT Id, Name, Last_Status__c,Additional_Information__c,Ongoing_Problem__c,Last_Update__c FROM Account
WHERE (OwnerId = :UserInfo.getUserID()) AND (Type <> 'Dead') AND (Last_Update__c = LAST_N_DAYS:150)
ORDER BY Last_Update__c DESC LIMIT 1];
return account;
}
Adding GROUP BY Last_Update__c system says I should aggregate also Id, if I do it it asks for Name and so on until I aggregate with every possible field in the SELECT. This is already not what I want, but even doing this in the end a get a type incompability.
Is there a simple way to have this grouping having still an account at the end of the process?
And btw, is "Last_Update__c = LAST_N_DAYS:150" correct to get only accounts that have NOT been updated in the last 150 days? Using logic, it should be "Last_Update__c > LAST_N_DAYS:150" but I never get any result if I use this expression, even if many accounts in Salesforce should respect this condition.
A.