You need to sign in to do that
Don't have an account?
John Neilan 18
Pass Account ID Using URLFOR
I have a Visualforce Page that uses the standard Contact controller with a controller extension. The page is embedded on the Contact record layout and displays a related list of a custom object that has a master-detail to the Contact and Account records.
I am trying to create a custom button on the embedded VF page to create a new record that pre-populates the associated Contact and Account (from the Contact) IDs to 2 lookup fields on the custom object record. I am using a CommandButton with !URLFOR($Action attributes to open the new record creation page (in Lightning), however, I cannot figure out how to get the Account pre-populated and then redirect back to the contact record once saved.
The line below opens the pop-up and pre-populated the Contact ID, but I need to select the Account and then it directs to the new record created, not the original Contact record. Is it possible to do what I am trying to do with a CommandButton?
I am trying to create a custom button on the embedded VF page to create a new record that pre-populates the associated Contact and Account (from the Contact) IDs to 2 lookup fields on the custom object record. I am using a CommandButton with !URLFOR($Action attributes to open the new record creation page (in Lightning), however, I cannot figure out how to get the Account pre-populated and then redirect back to the contact record once saved.
The line below opens the pop-up and pre-populated the Contact ID, but I need to select the Account and then it directs to the new record created, not the original Contact record. Is it possible to do what I am trying to do with a CommandButton?
<div style="margin-left: 30%;"> <apex:commandButton action="{!URLFOR($Action.Type__c.New)}" value="New Type" oncomplete="window.open('/{ContactId}&retURL=(ContactId}')"/> </div>
Yes, whatever you are trying to do with CommandButton is correct, onComplete is generally used like this. Verify if your URL is correct
If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!
Anudeep