I having trouble in updating the case owner as Queue in Web/Email-to-Case. I wanted to query the email of the sender if its on the list of spam cases (saved in custom setting) then set it to Spam Queue else put in Non Spam Queue. I don't set any Workflow, assignment rule. Below is my code :) (sorry Im still a newbie in coding apex)
I think there are following logical error in your code.
1) If you do not get any matching record for your SOQL then for loop will not get executed.
2) Due to this non spam queue will be never set.
3) You should write the SOQL without loop to resolve this
4) This code is not Bulkify. See details at https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
You can follow this step, hopefully it will work.
You can find that, in the Email-to-Case setting Case Origin in set as 'Email'. For Web-to-Case it will default 'Web'
Rather than using trigger, I think you can play with assignment rule and add relevant condition along with the Case origin to route to a proper queue. There will be single assignment rule to be active, but it can have multiple conditions to route to a queue.