You need to sign in to do that
Don't have an account?
Chris Marzella
How to set a result from a SOQL query to a variable?
What do I need to get to assign the result of this query to a variable?
trigger SetTotalCreatures on Deck__c (after update) { Integer cardTotal = [SELECT Sum(Number_In_Deck__c) FROM Cards_in_Deck__c WHERE Type__c = 'Creature']; Deck__c.Total_Creatures__c = cardTotal; }
I am just trying to assign a number to a custom field based on the result from the SOQL query.
Please check below post. I hope that will help u
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_agg_fns.htm
http://blog.jeffdouglas.com/2010/04/12/using-aggregateresult-in-salesforce-com-soql/
http://blog.terrasky.com/blog/useful-soql
Please let us know if this will help u
Thanks,
Amit Chaudhary
Suraj, using your code I get : [Error] Error: Compile Error: Illegal assignment from Object to Decimal at line 7 column 9
Amit, using your code I get: [Error] Error: Compile Error: Illegal assignment from Object to Decimal at line 6 column 9
for some clarification on the fields: cards in deck is a number, type is a picklist, total creatures is a number (not sure if that matters)
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BM0kIAG
Please let us know if this will help u
Thanks
Amit Chaudhary
The total creatures should add up to 12. It is accessing the "Number in Deck" field for every record not just the current record.
I hope that will help u
I hope type field you have on card in desk object right