+ Start a Discussion
BaguiarBaguiar 

get value from a custom field in current page

I'm trying to get the value of a custom field that is on the current page (Account) where I have a VF page within.

 

I'm using this:

 

public class KeyL
{

 String strname = Apexpages.currentPage().getParameters().get('Congregation_ID__C');
  private List<Leadership_position_code__c> LeadersL;
  public List<Leadership_position_code__c> getLeadersL()
    
    

    {
      LeadersL = [ Select l.Contact__c, l.Contact__r.AccountId from Leadership_Position_Code__c l WHERE (Congregation_code__C = :strname )];
            
           return LeadersL;
    }
            
}

 

I can't get the value from my Custom Field (Congregation_ID__C) into the String strname.

 

 

Thanks!

B

Best Answer chosen by Admin (Salesforce Developers) 
BaguiarBaguiar

Got it. Here is what I did:

public class KeyL
{

  Account[] acc = [Select Congregation_ID__c from account where id = :System.currentPagereference().getParameters().get('id')];
  private List<Leadership_position_code__c> LeadersL;
  public List<Leadership_position_code__c> getLeadersL()
    
    

    {
      LeadersL = [ Select l.Contact__c, l.Contact__r.AccountId from Leadership_Position_Code__c l WHERE (Congregation_code__C = :acc[0].Congregation_ID__c )];
            
           return LeadersL;
    }
            
}

 

All Answers

forecast_is_cloudyforecast_is_cloudy

Can you please explain your use case in more detail? What do you mean by "current page (Account) where I have a VF page within"? Do you mean that you have embedded a custom VF page into the Account Page Layout and want to access some custom field of the Account record in your VF controller?

BaguiarBaguiar

Thats exactly right. The Vf page is embedded in the Account page layout and I'm trying to get a custom field "Congregation_ID__C" on my controller.

 

Thanks!

BaguiarBaguiar

Got it. Here is what I did:

public class KeyL
{

  Account[] acc = [Select Congregation_ID__c from account where id = :System.currentPagereference().getParameters().get('id')];
  private List<Leadership_position_code__c> LeadersL;
  public List<Leadership_position_code__c> getLeadersL()
    
    

    {
      LeadersL = [ Select l.Contact__c, l.Contact__r.AccountId from Leadership_Position_Code__c l WHERE (Congregation_code__C = :acc[0].Congregation_ID__c )];
            
           return LeadersL;
    }
            
}

 

This was selected as the best answer
forecast_is_cloudyforecast_is_cloudy

Perfect! That's exactly the right way to query for additional fields on an SObject when embedding a VF page in a Page Layout. You only get passed in the Salesforce Record Id in the VF controller/extension. You then have to explicitly query for any additional fields using that Id (as you've done).