Created
June 7, 2016 16:11
-
-
Save afawcett/2470b738c266c667523d3d3568d4e3cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PermissionSet permissionSet = new PermissionSet(); | |
permissionSet.Name='ApexTest'; | |
permissionSet.label='Apex Test'; | |
insert permissionSet; | |
ObjectPermissions objectPermission = new ObjectPermissions(); | |
objectPermission.ParentId = permissionSet.Id; | |
objectPermission.SObjectType = Book_Order__c.SObjectType.getDescribe().getName(); | |
objectPermission.PermissionsEdit = true; | |
objectPermission.PermissionsRead = true; | |
objectPermission.PermissionsDelete = true; | |
objectPermission.PermissionsCreate = true; | |
insert objectPermission; | |
ObjectPermissions objectPermission2 = new ObjectPermissions(); | |
objectPermission2.ParentId = permissionSet.Id; | |
objectPermission2.SObjectType = Order_Line_Item__c.SObjectType.getDescribe().getName(); | |
objectPermission2.PermissionsEdit = true; | |
objectPermission2.PermissionsRead = true; | |
objectPermission2.PermissionsDelete = true; | |
objectPermission2.PermissionsCreate = true; | |
insert objectPermission2; | |
FieldPermissions fieldPermission = new FieldPermissions(); | |
fieldPermission.ParentId = permissionSet.Id; | |
fieldPermission.SObjectType = Order_Line_Item__c.SObjectType.getDescribe().getName(); | |
fieldPermission.Field = Order_Line_Item__c.SObjectType.getDescribe().getName() + '.' + Order_Line_Item__c.Shipping_Status__c.getDescribe().getName(); | |
fieldPermission.PermissionsEdit = allowUpdateShippingStatus ? true : false; | |
fieldPermission.PermissionsRead = true; | |
insert fieldPermission; | |
User newUser = new User( | |
Alias = 'test1'+System.today().dayOfYear(), | |
Email=permissionSet.Id+'@testorg.com', | |
EmailEncodingKey='UTF-8', | |
LastName='Testing', | |
LanguageLocaleKey='en_US', | |
LocaleSidKey='en_US', | |
ProfileId = [select Id from Profile where Name = 'Standard User'].Id, | |
TimeZoneSidKey='America/Los_Angeles', | |
UserName=permissionSet.Id+'@testorg.com'); | |
insert newUser; | |
insert new PermissionSetAssignment(AssigneeId=newUser.Id, PermissionSetId=permissionSet.Id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment