With a Visualforce page for my Community, I am trying to limit the records returned from a SOQL based on criteria of child records.
I have a custom object Sale (parent) and custom object Sale Related Contact (child via a master/detail relationship). Sale Related Contact has a lookup to the standard Contact object and the standard User object also has a lookup to Contact.
What I want to do is return only Sale records where the current user is a contact in a related Sale Related Contact record and Type = Realtor.
My controller will compile (applicable code below) but whenever a user logs in that meets this criteria (ie a sale record should be returned) I get the generic "Error: Error occurred while loading a Visualforce page. Please email us if you need to get in touch." screen.
When logging in as a user who does meet this criteria (ie a sale record should be returned), I get no error.
Thoughts on what I'm doing wrong?
private User thisUser;
private List<Sale_Related_Contact__c> srcRealtors;
private List<Id> saleRealtor;
private List<Sale__c> saleRec;
User thisUser = [select Id, AccountId, ContactId from User where Id = :UserInfo.getUserId() ];
srcRealtors = [select Id, Contact__c,Sale__c, Type__c from Sale_Related_Contact__c where Contact__c = :thisUser.ContactId AND Type__c = 'Primary Realtor' ];
for(Sale_Related_Contact__c src : srcRealtors){
saleRealtor.add(src.Sale__c);
}
saleRec = [select Id from Sale__c where Id in :saleRealtor);