function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eric FortenberryEric Fortenberry 

How to populate a new opportunity with the current account name?


I have created a custom button to create a New Opportunity and I'd like to pass in the Account Name, but am not sure how.  Here is the code I have in my visualforce page.  I think I need to add additional paramaters to the !URLFOR part, but if someone could help me out I'd appreciate it!  Thanks.


<apex:page standardController="Account" extensions="AccountExt" sidebar="false" showHeader="false">
      function doRedirect()
       window.parent.location.href = '{!URLFOR($Action.Opportunity.New)}';
    <apex:form >
    <apex:pageBlock title="Opportunities">
        <apex:pageBlockButtons location="top">
            <apex:commandbutton onClick="doRedirect()" value="New Opportunity"/>
        <apex:pageBlockTable value="{!AllOpportunities}" var="item">
            <apex:column headervalue="Opportunity Name">
                <apex:outputLink value="/{!item.Id}" target="_parent"><apex:outputField value="{!item.Name}" /></apex:outputLink>
            <apex:column value="{!item.StageName}" />               
            <apex:column value="{!item.Amount}" />
            <apex:column value="{!item.CloseDate}" />
            <apex:column value="{!item.OwnerId}" />


Eric FortenberryEric Fortenberry

I tried this, but it's not working:


window.parent.location.href = '{!URLFOR($Action.Opportunity.New, null, [Account=Account.Id, retURL=URLFOR($Action.Account.View,account.Id)], false)}';



You can try like this : using a Cutom Buttonand running Java script{!Account.Id}&save_new_url=<url>&opp={!Account.Name}