0

Is there a limitation with PermsissionSetAssignment object in Apex. can't we insert the records using apex?

I am unable to compile the class as it is saying "Variable does not exist: AssigneeId" and "Variable does not exist: PermissionSetId"

public static void insertperms(){
        PermissionSetAssignment ps = new PermissionSetAssignment();
                ps.AssigneeId = UserInfo.getUserId();
                ps.PermissionSetId = 'qweqweqwe'; 
               // permList.add(ps);
    }

enter image description here

5
  • What API Version are you using? This object is available in API version 22.0 and later.
    – Adrian Larson
    Commented Apr 13, 2018 at 21:34
  • API version is 42.0
    – Ajay
    Commented Apr 13, 2018 at 21:38
  • 1
    Did someone define a custom class named PermissionSetAssignment in your org?
    – Adrian Larson
    Commented Apr 13, 2018 at 21:48
  • I can confirm that this should work, I used this code myself just today: insert new PermissionSetAssignment(AssigneeId = testUser.Id, PermissionSetId = testPermSet.Id);
    – Mark Pond
    Commented Apr 13, 2018 at 21:49
  • @Mark Pond, rightly said, there was same class name. All set for now.
    – Ajay
    Commented Apr 13, 2018 at 21:50

1 Answer 1

4

Sounds like a probable naming collision. If someone created a class named PermissionSetAssignment in your org, you would get exactly this error. To work around it, you can use the more verbose Schema.SomeStandardOjbect notation.

Schema.PermissionSetAssignment assignment = new Schema.PermissionSetAssignment();

It's not a great idea to introduce this type of naming collision. If it's not too late to change course, I suggest doing so.

4
  • Based on the provided screenshot and the error list, yeah there's a class named permissionSetAssignment that is at least 52 lines long. :-)
    – Mark Pond
    Commented Apr 13, 2018 at 21:51
  • @MarkPond Haha good point. Started typing this answer out before that got added.
    – Adrian Larson
    Commented Apr 13, 2018 at 21:53
  • Which one should I mark answer? both of you gave the answers :)
    – Ajay
    Commented Apr 13, 2018 at 22:16
  • There's only one Answer here and several Comments.
    – Adrian Larson
    Commented Apr 13, 2018 at 22:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .