Apex to Assign Skuid License and Permission Set

  • 1
  • Question
  • Updated 2 years ago
  • Answered
We use Skuid to build an application review process in a public-facing Portal (someday we'll grow up and be big boys and girls in SF Communities -- we're not there yet). We seem not to be the only ones who find that Skuid's auto-assignment of licenses and Page View Permissions isn't effective for high volume SF licenses associates with portals and communities (e.g. Overage High Volume Customer Portal). Auto-assignment works fine for other SF licenses (internal staff), but not for external users.

So I've been approaching this from the apex side and nearly have a solution -- I think the only thing getting in our way is our complicated coding environment tripping up my unit testing. But I'm not sure. Has anyone else taken this approach?

Trigger:
//For Skuid only, adds a free, unlimited Permission Set and License to all new Users.
trigger SSA_Custom_User on User (after insert) {
    List<User> users= trigger.new;
        FOR(User u :users) {
            IF(u.ProfileId == '00e12000000RuwGAAS') {
       			SSACustomUser.SkuidUserPermissions(u.Id);
       	 		SSACustomUser.SkuidUserLicense(u.Id);
        }
    }
}
Class:
public class SSACustomUser {
    @future
    public static void SkuidUserPermissions(String Id) {
        PermissionSet ps = [select Id, Name from PermissionSet where Name = 'Skuid_Page_Viewer' limit 1];
        PermissionSetAssignment psa = new PermissionSetAssignment
            (PermissionSetId = ps.Id, AssigneeId = Id);
            system.debug('user id is ' + Id);
        	insert psa;
         }

    @future
    public static void SkuidUserLicense(String Id) {
        PackageLicense pl = [select Id, NameSpacePrefix from PackageLicense where NameSpacePrefix = 'Skuid' limit 1];
         UserPackageLicense upl = new UserPackageLicense
            (PackageLicenseId = pl.Id, UserId = Id);
            insert upl;
    }
}
Photo of Dan Kray

Dan Kray

  • 70 Points

Posted 2 years ago

  • 1
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,840 Points 5k badge 2x thumb
Dan~

Sorry that you are having difficulty getting the auto assignment to work for your public facing portal. I am sure you've already tried this, but how did running the anonymous apex script in the middle of this tutorial for all active users turn out for you? We are also circling internally to see how to best help you with this!

Thanks!
Karen
(Edited)
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,840 Points 5k badge 2x thumb
Dan~

One of my colleagues came across this Apex code that may help you out. Can you give that a shot and see if it doesn't resolve the problem for you? 

Thanks!
Karen
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 12,066 Points 10k badge 2x thumb
Hi Dan,

I wanted to check in on this issue. I know you had said you were getting close, but running into trouble because of some underlying complexity in the environment. Karen had sent something that may be relevant, but we think now that it addresses a need that's a little different from yours. 

If you're still wrestling with this, can you share some specifics about the problem you're trying to solve? Console errors, expected behavior vs. actual behavior, etc?
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,128 Points 50k badge 2x thumb
Official Response
Dan~

We will be releasing a fix that addresses the issue you were experiencing in the upcoming maintenance releases due out on 2/13/18. With that, you should be able to auto-assign Licenses and Permission Sets to Self-Registered Portal / Community Users using Skuid's built-in functionality --- eliminating the need for any Apex Code here.

Thanks!
Karen
(Edited)
Photo of Khamla Phimmachack

Khamla Phimmachack, Official Rep

  • 1,946 Points 1k badge 2x thumb
Dan,

We have addressed this issue in the latest patch of Millau 11.0.6. You should now be able to auto-assign Skuid Licenses and Permission Sets to Community/Portal users who Self-Register.

Production install link for Millau 11.0.6
Sandbox install link for Millau 11.0.6