function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ScarScar 

Change Case Owner to Queue in BeforeTrigger , Insufficient privileges error

Hi all,

 

I have to change a case owner in a before trigger. The trigger works fine when i use an Administrator profile and the case owner is chnaged to that of a queue, but when i try changing the owner when using a user who's not an admin, i get an error saying that i don't have enough priviledges to perform the action.

 

 

I've put debug logs throughout the code to figure out the error,

The owner id actually is assigned the Queue Id, i think it's during the save operaion that i've missed something or there's an error.

 

can someone please point me in the right direrction and help me figurre out the error?

Best Answer chosen by Admin (Salesforce Developers) 
ScarScar

After lots of time spent searching here and there, i've finally been able to figure the error. 

 

An email is triggered each time a Case or lead owner is changed.  It's because there was en error while firing the email, that i had the insufficient priviledges error and there was not a change in wonership. 

 

To counter the problem , i followed the following  example 

http://help.salesforce.com/apex/HTViewSolution?id=000176854&language=en_US

 

and it worked. :) 

 

Alternately, i could have used WorkFlow rules to change the owner but in my case it would have meant 9 or more  Workflows  depending upon requirements.

 

 

 

All Answers

Satish_SFDCSatish_SFDC
Can you check if the class has the 'with sharing' keywords. Not sure if this is causing the error, but you can give it a try by removing the 'with sharing' from the apex class.

Regards,
Satish Kumar
ScarScar
I do not have a with Sharing class. It's a public class. i'm able to manually change the owner to a queue but not through the trigger.
ScarScar

After lots of time spent searching here and there, i've finally been able to figure the error. 

 

An email is triggered each time a Case or lead owner is changed.  It's because there was en error while firing the email, that i had the insufficient priviledges error and there was not a change in wonership. 

 

To counter the problem , i followed the following  example 

http://help.salesforce.com/apex/HTViewSolution?id=000176854&language=en_US

 

and it worked. :) 

 

Alternately, i could have used WorkFlow rules to change the owner but in my case it would have meant 9 or more  Workflows  depending upon requirements.

 

 

 

This was selected as the best answer
John James 24John James 24
Would you be able to check if the class has the 'with sharing' catchphrases. Not certain in case this is causing the mistake, however you can check it out by eliminating the 'with sharing' from the summit class. https://www.sydneyfoodco.com/
keshav bhattkeshav bhatt
yes it does work and resolve the issue. thanks
https://www.governmentkischeme.com
keshav bhattkeshav bhatt
yes it does work and resolve the issue. thanks
https://www.governmentkischeme.com
Naksh vermaNaksh verma
Country Delight Referral Code, Welcome to our other post, in this article we will talk about Country Delight Referral Code
https://techbiote.com/country-delight-referral-code/ (https://techbiote.com/country-delight-referral-code/" target="_blank)