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
Javier MaldonadoJavier Maldonado 

Trying to display Account.Name dynamically instead Id

I created a visualforce page that use account (standard object) as a realated field, in to the custom object Customer_s_Price_List__c, so that I want to do is dynamically show the name of the company in to the section header instead to show the ID (18 digits)...

Can somebody help me???

User-added image

My visualforce code below...
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC1" showHeader="false" tabStyle="account">
    <apex:sectionheader title="Customer Price -" subtitle="{!Customer_s_Price_List__c.Account__c}"/>
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >

THANKS in advance...
Best Answer chosen by Javier Maldonado
Alexander TsitsuraAlexander Tsitsura
Hi Javier

At first you need create new property in your extension
public String acctName {get; set}

After that you need add code to constructor, or if constructor not created, create it. your constructor must have name Plasma_controller_SFDC1
 
public Plasma_controller_SFDC1() {
	// your code here
	acctName = [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('accid')].Name;
}

and after this use {!acctName} insted of {!Customer_s_Price_List__c.Account__r.name}

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex

All Answers

Neetu_BansalNeetu_Bansal
Hi Javier,

Use this:
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC1" showHeader="false" tabStyle="account">
    <u><apex:sectionheader title="Customer Price -" subtitle="{!Customer_s_Price_List__c.Account__r.Name}"/></u>
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >
Let me know, if you need any other help.

Thanks,
Neetu
Alexander TsitsuraAlexander Tsitsura
Hi Javier

You need use Customer_s_Price_List__c.Account__r.Name.

Please, see code below
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC1" showHeader="false" tabStyle="account">
    <u><apex:sectionheader title="Customer Price -" subtitle="{!Customer_s_Price_List__c.Account__r.Name}"/></u>
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
 
Pramodh KumarPramodh Kumar
please use {!Customer_s_Price_List__c.Account__r.name} instead of {!Customer_s_Price_List__c.Account__c}..and let me know if you still facing any issues
 
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC1" showHeader="false" tabStyle="account">
    <u><apex:sectionheader title="Customer Price -" subtitle="{!Customer_s_Price_List__c.Account__r.name}"/></u>
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >

Thanks,
Pramodh
Javier MaldonadoJavier Maldonado
Hi guys...
Thanks for your quick response... I made the changes in my code, but is not working neither, now is not showing even the ID... THANKS for your help...
 
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC1" showHeader="false" tabStyle="account">
    <u><apex:sectionheader title="Customer Price -" subtitle="{!Customer_s_Price_List__c.Account__r.Name}"/></u>
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >

User-added image
Alexander TsitsuraAlexander Tsitsura
Hi Javier Maldonado

You need put Customer_s_Price_List__c record id to url(it's because u use standart controller). Please put id param to url for needed Customer_s_Price_List__c record, and Account Name automatic retrieved.

Or you can add logic to constructor if your extension
acctName = [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('id')].Name;

and use this acctName on your page

Thanks,
Alex
Neetu_BansalNeetu_Bansal
Hi,

Updation in Alexandar code:

If you go with extension record, you need to query like this:
acctName = [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('accid')].Name;
Let me know, if you need any other help.

Thanks,
Neetu
Javier MaldonadoJavier Maldonado
Thanks a lot for your replies...
I tried to make this works, but I don't know how to do it... Can you please help me, getting more information about what to do??? THANKS...
Neetu_BansalNeetu_Bansal
Hi Javier,

I can do this for you, if it is possible for you to share the salesforce org login credentials. You can contact me either on my gmail id: neetu.bansal.5@gmail.com or Skype id: neetu.bansal.5

Thanks,
Neetu
Alexander TsitsuraAlexander Tsitsura
Hi Javier

At first you need create new property in your extension
public String acctName {get; set}

After that you need add code to constructor, or if constructor not created, create it. your constructor must have name Plasma_controller_SFDC1
 
public Plasma_controller_SFDC1() {
	// your code here
	acctName = [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('accid')].Name;
}

and after this use {!acctName} insted of {!Customer_s_Price_List__c.Account__r.name}

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
This was selected as the best answer
Javier MaldonadoJavier Maldonado
Alex THANKS... it's working now... I appreciate all your help...
By the way, is there anything that I can do to avoid this message:
"List has no rows for assignment to SObject
An unexpected error has occurred. Your development organization has been notified.",
that happen when the visualforce page is running out of the account page, without account id???User-added image
Alexander TsitsuraAlexander Tsitsura
This error indicates that your query returns no results. Salesforce throws this error when you assign a query result to a singular instance of an object. To solve your current issue you should use a try/catch block around the query.

Please, see code below, i try to query accounts in to list, if nothing return i put error message to visualforce page
String accId = ApexPages.currentPage().getParameters().get('accid');
Account[] accs = [SELECT Id FROM Account WHERE Id = :accId];

if (accs.isEmpty()) {
  // handle logic when nothing found
  ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No exists accounts');
  ApexPages.addMessage(myMsg);
} else {
  acctName = accs[0].Name;
}


and you need add to your page apex tag for show error messages
<apex:pageMessages />

Thanks,
Alex
 
Javier MaldonadoJavier Maldonado
THANKS Alex... Thank you very much...
Javier MaldonadoJavier Maldonado
Hi Alex,
Sorry bother you, but I have not found the way this code works, I still getting the same error... please see What I did, and if you could let me know your suggestion... THANKS
APEX - No errors
public Customer_s_Price_List__c cpl ;
    
    String accId = ApexPages.currentPage().getParameters().get('accid');
    Account[] accs = [SELECT Id FROM Account WHERE Id = :accId];
    
    public String acctName {get; set;}
    public Plasma_controller_SFDC1(ApexPages.StandardController controller) {
        cpl = (Customer_s_Price_List__c)controller.getRecord();
        System.debug('!!!----!!!' + cpl);
        System.debug('!!!----!!!get accid-' + ApexPages.currentPage().getParameters().get('accid'));
        cpl.Account__c = ApexPages.currentPage().getParameters().get('accid');
        acctName = [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('accid')].Name;
    
    if (accs.isEmpty()) {
      // handle logic when nothing found
      ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No exists accounts');
      ApexPages.addMessage(myMsg);
    } else {
      acctName = accs[0].Name;
    }
    
    
    }


Visualforce - No errors
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC1" showHeader="false" tabStyle="account">
    
    
    
    <apex:sectionheader title="Price for - " subtitle="{!acctName}" />
    <apex:PageMessages/>
    
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >