0

My new related list button should redirect me to the New VF page for the child object, with certain fields from the Master on this form pre-filled. I can't seem to be able to both prefill the fields belonging to the Master or associate the new Child with the same Master. The VF page has a custom controller.

I tried using the format /apex/pageName?retURL=sameAsStdNewButton&lookupField_lkid={!Master__c.id}&MasterFieldToBePrefilledId1={!Master__c.Field__c}&... but it doesn't seem to work.

It would also be helpful if someone could tell me how to structure the saveURL.

2

If you are using a custom visualforce page in redirect URL then simply leverage parameters as given below:

New Button URL:

/apex/myVisualforcePage?masterId={!master__c.Id}&retURL=/{!master__c.Id}

Actual link will be:

https://c.eu0.visual.force.com/apex/myVisualforcePage?masterId=a08200000148XpNAAU&retURL=%2F%2Fa08200000148XpN&nooverride=1

Now you can leverage parameter name "masterId" to fill in the Visualforce page input field.


If you are trying to redirect to a page which don;t have controller you can do it like:

New Button URL:

https://c.eu0.visual.force.com/apex/myVisualforcePage?{!IdOfMasterCustomField}={!Master__c.Name}&{!IdOfMasterCustomField}_lkid={!Master__c.id}

Actual link will be shown as:

https://c.eu0.visual.force.com/apex/myVisualforcePage?CF00N20000007hitQ=ER-000722&CF00N20000007hitQ_lkid=a0B2000000h3sgc
2
  • Hi Ashwani. Thanks for your response, but this doesn't seem to work at all. I keep ending up with a completely new parent record and with the child linked to it. I want to be able to link to the existing parent. – Sandra Dee Jun 2 '15 at 11:02
  • @SandraDee You may be using it different way. There is no way to insert a record having child linked automatically unit the parent exist. "masterId=a08200000148XpNAAU" or "CF00N20000007hitQ=ER-000722" are to reference parent record to a child record which your page will create. – Ashwani Jun 2 '15 at 11:07
0

Hi you have to write a controller class from where you can assign field values to your child obj fields in constructor and then display them on vf page as prepopulated. Try writing in following code design:

/*****controller*****/
public class className {

    ChildObj ch {get; set;}

    public className(ApexPages.StandardController con){
        MasterObj ms = [Select id,field1,feild2... from MasterObj where id = :ApexPages.currentPage().getParameters().get('masterId')];
        ch = new ChildObj();
        ch.field1 = ms.field1;
        ch.field2 = ms.field2;
        ....
    }
}

/*****VF Page*****/
<apex:page standardcontroller="ChildObj" id="mypage" extensions="className">
<apex:form>
    <apex:inputField value="{!ch.field1}"/>
    <apex:inputField value="{!ch.field2}"/>
</apex:form>
</apex:page>

/*****Button (URL)*****/
/apex/VFPageName?masterId='{!MasterObj.Id}'

Hope this may help.

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.