You need to sign in to do that
Don't have an account?
Dave Berenato
Prepopulate Lookup Field in Standard Controller Visualforce Page
I have a Visualforce Page to make a new record of a custom object we call "Notes"
I want to display a link to the URL off the Account, which is the Parent object in a Master-Detail Relationship field (Account__c).
Can I preopulate the Lookup Field with this value using a URL from the Account?
I've tried:
1.
But none of them work. Any ideas?
<apex:page standardController="Note__c" showHeader="false"> <apex:form id="theForm"> <table> <tr> <th rowspan="2">Note Type</th> <th>Note Name</th> <th>Note Body</th> <th rowspan="2"><apex:commandButton value="Save" action="{!Save}" rerender="theForm" /></th> </tr> <tr> <th><apex:inputField value="{!Note__c.Name}"/></th> <th><apex:inputField value="{!Note__c.Content__c}"/></th> </tr> </table> </apex:form> </apex:page>
I want to display a link to the URL off the Account, which is the Parent object in a Master-Detail Relationship field (Account__c).
Can I preopulate the Lookup Field with this value using a URL from the Account?
I've tried:
1.
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?Account__c=0016A000001p8GD2.
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?Account__r.Id=0016A000001p8GD3.
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?00N6A000008PlNb=0016A000001p8GD4.
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?Account__c=12345+Test+Drive
But none of them work. Any ideas?
All Answers
/apex/NewNoteiFrame?Id=<Note__C Id>
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?AccountId=00N6A000008PlNb
Regards,
Pawan Kumar
User this URL
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?Account__c=0016A000001p8GD
This will prepopulate the Account field. Not sure is that what you wanted because I don't see which lookup field you wanted to populate.
This is close. I am trying to populate the Lookup field "Account__c" which is why I called the parameter "Account__c" but how to do I put that Parameter into the InputField?
In this case, youwould use URL:
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?Account__c=12345+Test+Drive
And then you would have to copy and paste the output Text from the first cell into the inputField Note__c.Account__c. Is there any way it could show this parameter inside the inputField on load?
Navigate to any Account. You should be able to see the Related List as shown below
You can navigate to any account like
https://corere--c.na50.visual.force.com/0016A000001p8GD (https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?Account__c=0016A000001p8GD)
If it doesn't show, you need to update the layout and add the Related List.
The New button there will automatically populate the Account and you just need to update the other two fields. Why to complicate life when out of box solution available
I know the out of the box functionality for new Related Records is one solution. I'm actually displaying this page on another Visualforce page, so I won't have access to the New Note button the Account record, I only have the account ID or name to plug into this Visualforce page to make a new note. Is there any way to do like:
VF:
---------------
<apex:page standardController="Note__c" extensions="NoteExtensionCtrl" showHeader="false">
<apex:form id="theForm">
<table>
<tr>
<th rowspan="2">Note Type</th>
<th>Note Name</th>
<th>Note Body</th>
<th rowspan="2"><apex:commandButton value="Save" action="{!Save}" rerender="theForm" /></th>
</tr>
<tr>
<th><apex:inputField value="{!Note__c.Name}"/></th>
<th><apex:inputField value="{!Note__c.Content__c}"/></th>
</tr>
</table>
</apex:form>
</apex:page>
--------------------------
Controller
---------------------
public class NoteExtensionCtrl{
private ApexPages.StandardController stdCtrl{get;set;}
//Public Id Id = ApexPages.currentPage().getParameters().get('id');
public NoteExtensionCtrl(ApexPages.StandardController std) {
stdCtrl = std;
note = (Note__c) stdCtrl.getRecord();
note.Account__c = ApexPages.currentPage().getParameters().get('AccountId');
}
}
-----------------
URL:
https://corere--c.na50.visual.force.com/apex/NewNoteiFrame?AccountId=00N6A000008PlNb
Please let me know in case of any further issue.
Regards,
Pawan Kumar
if it works for you then please close this thread. Thanks.
Regards,
Pawan Kumar
You forgot to state the Note variable as a new Note, but that works perfectly, thank you!
Also, thanks to Abdul for sharing OOB solution.