0

When I add an apex:inputField for a master-detail relationship it does not allow you to choose a parent via the lookup icon - it only shows the name of a parent if I append a record ID in the URL. If no record ID is specified, it only shows the name of the field, but no lookup icon.

enter image description here

Code:

<apex:page standardController="Scholarship_Award__c">
    <h1>2020-2021 Academic Year</h1>
    <apex:form >
    <!-- Hi -->
    <apex:pageBlock title="Add Scholarship Awards">
        <apex:pageBlockSection columns="2">
            <apex:inputField value="{!Scholarship_Award__c.Name}"/>
            <apex:inputField value="{!Scholarship_Award__c.Year__c}"/>
            <apex:inputField value="{!Scholarship_Award__c.Recipient__c}"/> 
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>
6
  • I think you would need to use a custom controller to support entering detail records to a variable parent
    – cropredy
    Commented Sep 17, 2020 at 23:52
  • Thank you. How can I do this? Commented Sep 17, 2020 at 23:55
  • Is there a reason you can't pass in an ID for the parent? Detail records for M-D relationships can't be created in the standard SFDC UI without starting with a parent
    – cropredy
    Commented Sep 18, 2020 at 0:01
  • Yes. I am developing a custom VF page for our external partners who are non-SF users. They will be inputting data of which we don't have so they will choose from the lookup which parent they would like to associate their new record with. Commented Sep 18, 2020 at 0:04
  • 1
    I don't have time to try/prove this but a) write a controllerExtension whose constructor creates a in-memory placeholder parent object using an Id of keyPrefix000000000000000and a detail record (in memory) that points at the in-memory parent. b) then implement a controller extension save() that verifies that a real parent was chosen.
    – cropredy
    Commented Sep 18, 2020 at 0:08

1 Answer 1

0

You need to use actual lookup field value="{!Scholarship_Award__c}" instead of value="{!Scholarship_Award__c.Name}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .