You need to sign in to do that
Don't have an account?
efficiency question
while my tag is not "newbie" any longer, i am not a developer... in particular, not an apex, java or any OOP developer so am greatly in need of advice (most of the time!!)....
anyways, i have a custom object, RunCharges, that contains 230 records. depending on value of some fields on custom object, i need to access up to 5 of these records and associated values in a trigger, potentially up to 20 times...
is it more efficient to do create a LIST, perform one SELECT for all records and iterate thru this list up to 20 times, or to do a SELECT statement with the specific criteria, i.e. process and qty range (causing a potential of 20 SELECT statements)??
or, i could do 5 SELECT statements for each type of process, and iterate through the 20 or so records until i find my quantity range?
any advice is more than welcoome... thanks very much.
A single query is most effecient. If possible, consider using a MAP instead of a LIST. You can use one field as a "key" (or even a composite key... meaning using string math to create unique entries). As an arbirary example, say you had two fields with a city and state, and a third field that contained a tax rate:
From here, you could then look up a city and state that's loaded in memory. You could use a similar method with your data if you can figure out a way to map your data uniquely. It's also possible to put maps inside of maps, if that makes it easier to visualize/code.
All Answers
A single query is most effecient. If possible, consider using a MAP instead of a LIST. You can use one field as a "key" (or even a composite key... meaning using string math to create unique entries). As an arbirary example, say you had two fields with a city and state, and a third field that contained a tax rate:
From here, you could then look up a city and state that's loaded in memory. You could use a similar method with your data if you can figure out a way to map your data uniquely. It's also possible to put maps inside of maps, if that makes it easier to visualize/code.
thanks very much for your input... very good idea to create the unique key....thanks again...c