You need to sign in to do that
Don't have an account?
Form with master-detail lookup field automatically populated with parameter id
Hi,
I'm facing a problem. I want the user to fill a form which has 3 fields name,email and a lookup(master detail field). The lookup field should be automatically populated with the parameter passed in URL. So, the user has to fill only 2 field with lookup field automatically populated and when he saves the record, it should be a detail record of the master record choosen.
I'm in two minds here whether to choose detail as the controller or master as the controller. I tried to find somthing online which deals with filling a lookup field but in vain. Please can someone guide me here?
Arrghh, use AccountId: <apex:inputField value="{!Contact.AccountId}"/>
Had thought about this, but to make sure asked your code.
All Answers
So you are using a VF page right?
Use <apex:inputField> for the lookup field - automatically the field will be filled if you are being navigate to the current page through the master record, i.e. this page is opened as a result of clicking a button in related list of master record.
Hi Abhi,
Yes this is a VisualForce page.I want the user to fill this form with lookup field automatically populated. When he saves the form it should be detail record of the Master record choosen.
Sure. Write a visualforce page, standard controller would be detail object. Override the new button with this VF page ( Go to detail object - Standard Buttons and Links - Click on edit next to New button - choose this VF page.
In the VF markup, use <apex:inputField> for the master-detail relationship field. Automatically the master record will be populated in that field.
When I try to output the Account lookup field for a Contact, I get the following message:
" Expression value does not resolve to a field
Did I miss something? Why am I able to use <apex:inputfield value="{!Contact.Account}"/> for custom fields I created, but not for this standard SalesForce field? Any insight would be greatly appreciated.
Thanks.
Can you post the VF code?
This is what I have. It doesn't matter, where I put that item though. I get the same message. Thoughts?
<apex:page standardController="Contact" sidebar="true">
<apex:sectionHeader title="Contact Edit" subtitle="{!Contact.name}"/>
<apex:form >
<apex:pageBlock title="Contact Edit" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!Contact.FirstName}"/>
<apex:inputField value="{!Contact.LastName}"/>
<apex:inputField value="{!Contact.Former_GE_Employee__c}"/>
<apex:inputField value="{!Contact.Title}"/>
<apex:inputField value="{!Contact.Contact_for_a__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock" status="status"/>
</apex:inputField>
</apex:pageBlockSection>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:actionRegion>
<apex:pageBlockSection columns="2"
rendered="{!Contact.Contact_for_a__c == 'Prospect'}">
<apex:inputfield value="{!Contact.Account}"/>
</apex:pageblocksection>
<apex:pageBlockSection columns="2"
rendered="{!Contact.Contact_for_a__c == 'Association'}">
<apex:inputfield value="{!Contact.Association__c}"/>
</apex:pageblocksection>
<apex:pageBlockSection columns="2"
rendered="{!Contact.Contact_for_a__c == 'Competitor'}">
<apex:inputfield value="{!Contact.Competitor__c}"/>
</apex:pageblocksection>
<apex:pageBlockSection columns="2"
rendered="{!Contact.Contact_for_a__c == 'Consultant'}">
<apex:inputfield value="{!Contact.Consultant__c}"/>
</apex:pageblocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
Arrghh, use AccountId: <apex:inputField value="{!Contact.AccountId}"/>
Had thought about this, but to make sure asked your code.
This worked! Thanks for your help!