function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bprakashbprakash 

How to use formula fields of related list

I have an account and it has 10 assets,i have a formula field number called support,in apex i want to sort it out so that i can get the max number value on support.

It says that formula fields are decimal so i had given list type as decimal and i sorted that,what i found in the debug log is 0,0,0,0...

I had cleared that one in the loop,Please help me out...

Thanks

Bhanu

Alex.AcostaAlex.Acosta

SELECT MAX(support__c) FROM Asset WHERE AccountId = :account.Id

bprakashbprakash

Field must be grouped or aggregated: Id at line 9 column 44

its throwing an errror

Alex.AcostaAlex.Acosta

AggregateResult[] groupedResults = [SELECT MAX(support__c) maxSupport FROM Asset WHERE AccountId = :account.Id];

Object supportObject = groupedResults[0].get('maxSupport');
Double support = Double.valueOf( supportObject );

bprakashbprakash

Illegal assignment from Object to SOBJECT:Asset 

asish1989asish1989

Hi

would you like to provide the detail code(visualforce and apex) so that It will be easier to find problem..?

 

 

Thanks

asish

bprakashbprakash

i had formula field on asset which is number ,i want to sort this to max value on account.But unfortunately we dont have rollupsmmary on accounts for assets.

Can you suggest how it can be done in apex.

Thanks

Bhanu

Alex.AcostaAlex.Acosta

I'm not sure why this is not working for you, I've ran this and tested it with my sandbox using the Price field. We need to see code to fix the issue