1

I try to automate the tasks given by maintenance modules to be done manually, since I find it more interesting. For Winter 23 App Builder maintenance, App Builder should create a permission set and assign it to some user.

There is an SFDX command to assign a permission set

sfdx force:user:permset:assign -n Name -o user -u org

however, it doesn't have a parameter to specify expiration date, so if I try to execute

sfdx force:user:permset:assign -n ReportPermissions, such command won't set the expiration date.

How can I assign a permission set with expiration date by a code or a script?

1 Answer 1

3

It is possible by combining Apex and sh.

First create a file assignCurrentUser.apex inside scripts/apex of your project.

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'PermName' AND NamespacePrefix = 'PrefixNamespace' LIMIT 1]; insert new PermissionSetAssignment(AssigneeId = UserInfo.getUserId(), PermissionSetId = ps.Id, ExpirationDate = Date.today() + 30); 

and then create a file acu.sh in scripts folder

code=$(cat scripts/apex/assignCurrentUser.apex) code="${code/PrefixNamespace/$1}" echo "${code/PermName/$2}" > temp.apex sfdx force:apex:execute -f temp.apex rm temp.apex 

and finally execute

./acu.sh '' ReportPermissions

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.