Scenario:
The relationship between Member and Blog objects is Lookup. Member is parent and Blog is child.
When “New Blog” button is clicked from Blog related list in Member Detail page, the Blog owner field in Blog record should be auto populated from Member Name.
See the below steps for solution
To find object URL:
To find the Id of the inputText:
Visualforce page:
<apex:page standardController=”Blog__c” extensions=”NewBlogOverriddenExt” action=”{!onLoad}>
</apex:page>
Apex Class:
public class NewBlogOverriddenExt {
Blog__c blog = new Blog__c();
Id memberId;
public NewBlogOverriddenExt(ApexPages.StandardController controller) {
blog = (Blog__c)controller.getRecord();
memberId = blog.Member__c;
}
public PageReference onLoad() {
Member__c member = [SELECT Name FROM Member__c WHERE ID = : memberId];
PageReference pg = new PageReference(‘/a03/e?’);
pg.getParameters().put(‘00NU0000003SVOs‘,member.Name);
pg.getParameters().put(‘nooverride’,’1′);// Important to avoid recursion
return pg;
}
}
Override New button in Blog object:
Output:
Cheers!!!