Skip to main content

I'm creating a test method where I have to create a test user. I will be using runAsrunAs for this. But, in creating the actual test user, I'm unsure how to set profile items such as PermissionsApiUserOnlyPermissionsApiUserOnly. Here is my code so far (taken from documentation):

    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
    User u = new User(Alias = 'standt', Email='[email protected]', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/New_York', UserName='[email protected]',
        Profile.PermissionsApiUserOnly='true');

But, I get Invalid field Initializer error on Profile.PermissionsApiUserOnly.

Invalid field Initializer error on Profile.PermissionsApiUserOnly

Any help would be greatly appreciated. Thanks!

I'm creating a test method where I have to create a test user. I will be using runAs for this. But, in creating the actual test user, I'm unsure how to set profile items such as PermissionsApiUserOnly. Here is my code so far (taken from documentation):

    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
    User u = new User(Alias = 'standt', Email='[email protected]', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/New_York', UserName='[email protected]',
        Profile.PermissionsApiUserOnly='true');

But, I get Invalid field Initializer error on Profile.PermissionsApiUserOnly.

Any help would be greatly appreciated. Thanks!

I'm creating a test method where I have to create a test user. I will be using runAs for this. But, in creating the actual test user, I'm unsure how to set profile items such as PermissionsApiUserOnly. Here is my code so far (taken from documentation):

    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
    User u = new User(Alias = 'standt', Email='[email protected]', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/New_York', UserName='[email protected]',
        Profile.PermissionsApiUserOnly='true');

But, I get

Invalid field Initializer error on Profile.PermissionsApiUserOnly

Any help would be greatly appreciated. Thanks!

Source Link
Wilock
  • 55
  • 1
  • 5

Setting profile information for test user in apex test class

I'm creating a test method where I have to create a test user. I will be using runAs for this. But, in creating the actual test user, I'm unsure how to set profile items such as PermissionsApiUserOnly. Here is my code so far (taken from documentation):

    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
    User u = new User(Alias = 'standt', Email='[email protected]', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/New_York', UserName='[email protected]',
        Profile.PermissionsApiUserOnly='true');

But, I get Invalid field Initializer error on Profile.PermissionsApiUserOnly.

Any help would be greatly appreciated. Thanks!