You need to sign in to do that
Don't have an account?
Lee_Campbell
Complicated List Query...
If I created a class such as:
public class myClass{ public double myMethod(List<Object> a, integer b){ //some logic } }
And a list such as: [Select id, some_double__c, some_String__c, some_other_double__c from Object where blah blah blah],
could I use those doubles in the class?
i.e. logic that said something generic like:
a new double x is found by finding the doubles on row i of the list, multiply the first double by 5 then subtract the second double, which in the case above would be:
x = 5 * a[i].some_double__c - a[i].some_other_double__c;
Any ideas?
Yes, although you'll have to give the class a way to identify which double is #1 and which is #2, through a naming convention or the like.
I think what you are looking for is dynamic DML - this allows you to extract field values from an sobject based on a string containing the name rather than hardcoding the field.
E.g.
All Answers
You should be able to do exactly as you have written, so I'm guessing I'm not understanding your problem. Are you trying to refer to the double fields generically - i.e. not specify the exact name or type of sobject?
My intention was to specify the sObject that this is a list of, but not the SOQL query items, so that whatever list I use in this class, the class can find the doubles in that list and perform some operation on them.
Does that make more sense?
Yes, although you'll have to give the class a way to identify which double is #1 and which is #2, through a naming convention or the like.
I think what you are looking for is dynamic DML - this allows you to extract field values from an sobject based on a string containing the name rather than hardcoding the field.
E.g.
Brilliant, thanks!
Hmmm... I've just tried it and I'm getting a "method does not exist or incorrect signature" error when I try to make use of this new class in a Trigger. Any thoughts?
One word: static. My bad.