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 

Create New Contact Button

Hello, I am trying to create a New Contact button to go along with my new visualforce page.  Can you someone please help me better understand how to create buttons, specifically the New Contact button, and how the action urlfor works?  Thanks!

Chris DaviesChris Davies

Hi Eric,

 

try this:

<apex:outputLink value="{!URLFOR($Action.Contact.New)}">New</apex:outputLink>

 

You can change it to button by using apex:commandbutton tag instead.

Eric FortenberryEric Fortenberry

Here's what I've got so far, but the problem is that when I click New Contact button it renders itself within the visualforce page that I have added to the Account layout page.  I would like it to work just like the standard New Contact button that navigates to the create new contact page. 

 

<apex:page standardController="Account" extensions="AccountExt" sidebar="false" showHeader="false">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons location="top">
            <apex:commandbutton action="{!URLFOR($Action.Contact.NewContact)}" value="New Contact"/>
        </apex:pageBlockButtons>
        <apex:pageBlockTable value="{!AllContacts}" var="item">
            <apex:column value="{! item.name}"/>
            <apex:column value="{! item.account.name}"/>
            <apex:column value="{! item.phone}"/>
            <apex:column value="{! item.email}"/>            
        </apex:pageBlockTable>
    </apex:pageBlock>  
    </apex:form>
</apex:page>

 Screenshot available here:  http://cl.ly/1R330v0n2e0H2U2o2N0t

Richie DRichie D

Hi Eric,

 

The problem is that Salesforce is putting your VF page into an iframe and so the location of the iframe is being changed and not the 'opener' window. try something like

<apex:commandbutton action="{!URLFOR($Action.Contact.NewContact)}" onclick="window.opener.document.location = '{!URLFOR($Action.Contact.NewContact)}'" value="New Contact"/>

 

You may need to fiddle with this a bit but you should be able to get it to work when the Javascript is correct.

 

Cheers,

Rich.


James LoghryJames Loghry

Is there a way to pass in the current account id to the new contact wizard in order to specify a default parent?

dev_firedev_fire

Hi Eric,

 

If you are trying to create a button on Account pagelayout ,please add Contact related list in Account Page Layout to achieve this.

 

If you are going for a custom VF then

  1. Create a VF & Apex class[Fetch the currentID from Account Detail page URL & redirect user to ('//003/e?retURL=%'+currentID+'&accid='+currentID)
  2.  You can create a button on the related list.

     

    • First of all the create list button in the object on which related list you want to display the button[Select VF page]
    •  After creating the list button add the list button in related list and the page layout by following the below steps
    • Edit the page layout of the object where you want to display the button
    • Go to the object related list ->click on the related list properties button ->click on the plus (+) of the buttons section add the custom button and click on save button

 

If my solution worked for you mark it as resolved.

 

Thanks.

dev_firedev_fire

Hi EDLJames,

 

Create a VF & Apex class[Fetch the currentID from Account Detail page URL & redirect user to ('//003/e?retURL=%'+currentID+'&accid='+currentID)

 

If my solution worked for you mark it as resolved.

 

Thanks.

James LoghryJames Loghry

From what I understand, using the sObject prefix and constructing the URL above is not supported, and it's better to use the Action global variable instead.  Here's what I came up with for the new contact button on the contact related list for an account.. 

{!URLFOR($Action.Contact.NewContact,null,[con4_lkid=id],true)}.  Id is the id of the current account.  con4_lkid is the html id attribute for the related account id on the standard new contact page.  Maybe it is better to use the accid param instead, but I haven't tried that.

 

Also, the following works for impementing the Merge contact button: 

{!URLFOR($Action.Contact.Merge,Id)}

 

Cheers,

- James

visual force.ax1886visual force.ax1886
James,

I tried the Merge URL and its working fine, But after we merge, the page is going to Contact related list Visualforce Page. it has to go to accounts page as standard button goes to. 
I tried couple of options but could not get it.

can you help me with this.

thanks!!