You need to sign in to do that
Don't have an account?
marcob
what is the best apex code?
Hi,
what is better:
string querystring = 'select id, field_a, field_b from <custom object> where id =: <variable>';
Alternative 1:
for(<custom object> co :database.query(selectie)){
myList.add(co);
}
Alternative 2:
myList = database.query(selectie);
Any suggestions?
Thx in advance!
Marco
Definitely 2, why waste resources iterating a result list, to add it's elements to another list when you can assign the list immediately. Neither cases need exception handeling if you ask me. Coding efficiently is not always about script statements, sometimes more code, can equal a higher efficiency, but not in this case.
All Answers
And the one that results in 1 script statement doesn't require additional error handling, like when the number of rows found = zero?
Definitely 2, why waste resources iterating a result list, to add it's elements to another list when you can assign the list immediately. Neither cases need exception handeling if you ask me. Coding efficiently is not always about script statements, sometimes more code, can equal a higher efficiency, but not in this case.
Well, this leaves no doubt, 2 is the winner!
Thanks for your help!
Br, Marco.