0

I have overridden the New action for a custom object which will take me to a Visualforce. It works well until there. So now my custom object has a lookup relationship to Account. So when trying to create/add a new custom object from the Account record I want a field in my Visualforce to be filled with the Account Name of that record.

This is what I tried -
<apex:outputText id="name" value="Name of the Customer/Business: {!escalation.Account__r.Name}"/>

  • What exactly is the result? – Adrian Larson May 27 '15 at 23:16
  • so that output text should populate the Account name on the VisualForce page since the custom object in this case is being created from the Account record level. – Sanjay May 27 '15 at 23:18
  • That is the expected result. What is the actual result? – Adrian Larson May 27 '15 at 23:19
  • it doesn't show anything. Blank .. – Sanjay May 27 '15 at 23:23
  • Sanjay - is escalation the name of your custom object(which will make the api name escalation__c)? – sw6 - KTBFFH May 28 '15 at 0:23
2

I was able to do this myself here is what I did, Visualforce- <apex:pageblocksectionitem> <apex:outputlabel value="Account Name"/> <apex:outputtext id="name" value="{!accname}" /> </apex:pageblocksectionItem>

Apex-

public string accname{get;set;}   
    public EscalationController(ApexPages.StandardController sc) {
    accname=apexpages.currentpage().getparameters().get('CF00NR0000001UuHR');
    }

CF00NR0000001UuHR was copied from the URL(On clicking new button from Account record level)

  • Sanjay - I was just about to post a similar solution to what you just posted. When you click the new escalation button on the account related list the URL gives you two ids - one for the name of the account (starting with CF and the other for the Id of the account(starting with CF and ending with _lkid). I am glad you figured it out yourself. Kudos and +1. – sw6 - KTBFFH May 28 '15 at 6:01
1

Your problem is likely that escalation.Account__r is not defined in this context. If you have the Id, you will want to query for the Account in order to display it. Making some assumptions about your structure, the below should work.

Extension

public with sharing class MyExtension
{
    public Account parentAccount { get; private set; }
    public MyExtension(ApexPages.StandardController controller)
    {
        Id accountId = ApexPages.currentPage().getParameters.get('accountId');
        parentAccount = [SELECT Name FROM Account WHERE Id = :accountId];
    }
}

Page

<apex:page standardController="My_Object__c" extensions="MyExtension">
    <apex:outputText value="{!parentAccount.Name}" />
</apex:page>
  • I'm receiving this error - 'List has no rows for assignment to SObject ' – Sanjay May 27 '15 at 23:28

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.