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
Jos VervoornJos Vervoorn 

FATAL_ERROR System.QueryException: sObject type 'AssignmentRule' is not supported.

I'm creating cases thru a community and using VF/Extention to submit to dB. 
AssignmentRule CaR = new AssignmentRule();
      CaR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];

       System.debug('** * ** Controller || Retrieve Case Assignment Rule ...');
     
       Database.DMLOptions dmlOpts = new Database.DMLOptions();
       dmlOpts.assignmentRuleHeader.assignmentRuleId= CaR.id;
            objCase.SetOptions(dmlOpts);
When creating case I get the following error: sObject type ÁssignmentRule'is not supported. 

Now I do notice that when I remove with charing from my controller extension it works but that would mean all sharing rules are ineffective which is not really helping. I also would like to stay away from doing this in after update trigger as some case need to run thru assignment rules and some don't so I need to include the login there. 

Is there another way .. like for example a method inside a utility class ... some samples would be great. Many thanks in advance.


 
Best Answer chosen by Jos Vervoorn
Jos VervoornJos Vervoorn
Hi Rahul,

Thanks but finally I used 
Database.DMLOptions dmlOpts = new Database.DMLOptions();
       dmlOpts.assignmentRuleHeader.useDefaultRule = true;
       objCase.SetOptions(dmlOpts);

You can only have one active (& default) case assignment rule .... there's no need to query...  and therefore no need to create class with/without sharing.

All Answers

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Jos Vervoorn,

May I suggest you please refer the below link for reference. Hope it helps.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
Jos VervoornJos Vervoorn
Hi Rahul,

Thanks but finally I used 
Database.DMLOptions dmlOpts = new Database.DMLOptions();
       dmlOpts.assignmentRuleHeader.useDefaultRule = true;
       objCase.SetOptions(dmlOpts);

You can only have one active (& default) case assignment rule .... there's no need to query...  and therefore no need to create class with/without sharing.
This was selected as the best answer