I have a SOQL query with a lot of filters and I want to group the results and process objects which match a certain filter. For eg. I could have a query where I want to process different kind of leads differently,
List<Lead> leads = [Select id,name,ownerId from Lead where rating = 'Hot' or leadsource='Web' or name like 'Sam%'];
For rating = 'Hot' , I want to change the ownerId to 'X'.
For leadSource ='Web', I want to change the ownerId to 'Y'
For name like 'Sam%', I want to change to a queue
I can think of 2 ways of doing this -
1) To have different queries for individual filters and process the objects
2) Or to loop over the results and have an if/else statement to identify the action
Is there any other way to optimize it? Can I group the results based on filters?