function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sk3501.3915272120779841E12sk3501.3915272120779841E12 

System.QueryException: List has no rows for assignment to SObject

The error is coming when i want to fetch customerUserTypes in Profile.

Set<String> customerUserTypes = new Set<String> {'CSPLiteUser', 'PowerPartner', 'PowerCustomerSuccess',   'CustomerSuccess'};
Account acc = new Account (
Name = 'newAcc1'
); 
insert acc;
Contact con = new Contact (
AccountId = acc.id,
LastName = 'portalTestUser'
);
insert con;
Profile p = [select Id,name from Profile where UserType in :customerUserTypes limit 1];

User newUser = new User(
profileId = p.id,
username = 'newUser@yahoo.com',
email = 'pb@ff.com',
emailencodingkey = 'UTF-8',
localesidkey = 'en_US',
languagelocalekey = 'en_US',
timezonesidkey = 'America/Los_Angeles',
alias='nuser',
lastname='lastname',
contactId = con.id
);
insert newUser;
sk3501.3915272120779841E12sk3501.3915272120779841E12
Anyone please help me why this exception error is coming. And how to solve it.
vbsvbs
The most obvious check that needs to be done is if there actually are any Profiles with the UserType in the list of values mentioned above and if the running user has access to the data based on the class sharing visibility. A quick run through the profiles for the sandbox you are working on should answer this.
riffindusriffindus
Customer portal user will not have access to user object, so you are gett no row as SOQL result.

Aariff