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">
    <script>
      function doRedirect()
      {
       window.parent.location.href = '{!URLFOR($Action.Opportunity.New)}';
     }
    </script>
    <apex:form >
    <apex:pageBlock title="Opportunities">
        <apex:pageBlockButtons location="top">
            <apex:commandbutton onClick="doRedirect()" value="New Opportunity"/>
        </apex:pageBlockButtons>
        <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>
            <apex:column value="{!item.StageName}" />               
            <apex:column value="{!item.Amount}" />
            <apex:column value="{!item.CloseDate}" />
            <apex:column value="{!item.OwnerId}" />
        </apex:pageBlockTable>
    </apex:pageBlock>  
    </apex:form>
</apex:page>

 

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)}';

 

REKREK

You can try like this : using a Cutom Buttonand running Java script

 

https://na1.salesforce.com/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL={!Account.Id}&save_new_url=<url>&opp={!Account.Name}