Activity Forums Salesforce® Discussions How to assign permission set in test class?

  • How to assign permission set in test class?

    Posted by Nitish on April 30, 2016 at 4:48 pm

    I have set OWD to private and create a permission set to give access to object. We have removed all the object settings access from the concerned profile. Previously with OWD set to private, profile based object access was there. Now all the test classes are getting failed. Error is coming in test classes that User must have Read Access to the record. So what should I do to assign permission set in test class so that my all test classes and its methods run perfectly.

    Surbhi replied 8 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Surbhi

    Member
    May 30, 2016 at 11:38 am

    Hi NItish,

    Please follow the below steps:

    Step 1: Insert a test user record.
    Step 2: Query your Permission Set information that you have used in class.
    Step 3: Assign the inserted user to the above queried Permission Set. For this PermissionSetAssignment object is used.
    Step 4: Initialize your class/method by running as the above inserted user.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos