0

I need your help to understand what's happening here.

We are using the Customer Portal (Community) for quite a long time, we use 'Customer Community Login User' profiles that we assign to external users in order to grant them access to the community.

I have a controller named OpenProjects.cls that shows the user (based on his account) a list of all the opened Project__c records that belong to the user's account.

Below you can see a query that gets some information about the contact's account.

        conAccount = [Select Support_Type__c, BillingCountry, (Select RecordTypeId From Applications__r), 
                         (Select Announcement__c From Announcement_Accounts__r) 
                  From Account
                  where id =: con.AccountId];

Everything works fine with the above query, but from here it gets messy:

I created a new lookup field on the Contact object that points to an Account (Contact_Account_Integrator__c).

Then, I modified the query (it's the same except for the 'Where' condition) as follow:

        conAccount = [Select Support_Type__c, BillingCountry, (Select RecordTypeId From Applications__r), 
                         (Select Announcement__c From Announcement_Accounts__r) 
                  From Account
                  where id =: con.Contact_Account_Integrator__c];

But now I get this error: 'List has no rows for assignment to SObject'

I tried using the same query on Workbench and it did return results! I checked the Field Level Security and the user's profile has both read and edit permissions Do you have any ideas? does it relate to Sharing Rules?

Debug Log:

10:39:36.0 (45554685)|SOQL_EXECUTE_BEGIN|[30]|Aggregations:2|SELECT Support_Type__c, BillingCountry, (SELECT RecordTypeId FROM Applications__r), (SELECT Announcement__c FROM Announcement_Accounts__r) FROM Account WHERE id = :tmpVar1
10:39:36.0 (75768637)|SOQL_EXECUTE_END|[30]|Rows:0
10:39:36.0 (76084802)|SYSTEM_MODE_EXIT|false
10:39:36.0 (76494931)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject
0

This is because There are chances that your community user don't have access of this record. Thats why you are getting this exception. Also check for field level Security as well.

One more thing

conAccount = [Select Support_Type__c, BillingCountry, (Select RecordTypeId From Applications__r), 
                         (Select Announcement__c From Announcement_Accounts__r) 
                  From Account
                  where id =: con.Contact_Account_Integrator__c];

Instead of direct assigning this to variable first use list and then check size of the list and then use the value using this way you will not get this exception.

List<Account> conAccountList = [Select Support_Type__c, BillingCountry, (Select RecordTypeId From Applications__r),  (Select Announcement__c From Announcement_Accounts__r)  From Account where id =: con.Contact_Account_Integrator__c];
if(conAccountList.size() > 0)
  conAccount = conAccountList[0];
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.