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
Kevin Jackson 11Kevin Jackson 11 

SOQL Query Help - using one query to identify the next layer

I will preface this that I am fairly new at creating a controller so there several poor practices going on here.

The first Class (Contact) works fine.  and I am trying to use it to help me get the related membership to the identified contact.  I have tried several ways to get it done, but keep running into errors.  I feel I am close, but that is only good with hand grenades and horse shoes.

Here is part of my Controller:
 
public Contact getContact () {
        
        return[SELECT Id, name, email, MailingAddress, Phone, MailingCity, MailingState, MailingCountry, MailingPostalCode, MailingStreet 
               FROM Contact 
               WHERE Id IN (SELECT 	ContactId
                             From User
                             WHERE Id=:UserInfo.getUserId())
              LIMIT 1];

    }
  public Membership__c getMembership () {
        
        return[SELECT Id
               FROM Membership__c
               WHERE Contact_Associated__c = {!Contact.Id}
              LIMIT 1];
}

 
Best Answer chosen by Kevin Jackson 11
Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
public Contact getContact () {
        
        return[SELECT Id, name, email, MailingAddress, Phone, MailingCity, MailingState, MailingCountry, MailingPostalCode, MailingStreet 
               FROM Contact 
               WHERE Id IN (SELECT 	ContactId
                             From User
                             WHERE Id=:UserInfo.getUserId())
              LIMIT 1];

    }

  public Membership__c getMembership () {
        Contact con=getContact();
        return[SELECT Id
               FROM Membership__c
               WHERE Contact_Associated__c =: con.Id;
              LIMIT 1];
}
Let me know if it helps you.
 

All Answers

Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
public Contact getContact () {
        
        return[SELECT Id, name, email, MailingAddress, Phone, MailingCity, MailingState, MailingCountry, MailingPostalCode, MailingStreet 
               FROM Contact 
               WHERE Id IN (SELECT 	ContactId
                             From User
                             WHERE Id=:UserInfo.getUserId())
              LIMIT 1];

    }

  public Membership__c getMembership () {
        Contact con=getContact();
        return[SELECT Id
               FROM Membership__c
               WHERE Contact_Associated__c =: con.Id;
              LIMIT 1];
}
Let me know if it helps you.
 
This was selected as the best answer
Kevin Jackson 11Kevin Jackson 11
Super!  there is just an extra ; after con.id.

Thank you VERY much!