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
Nitish Singh 22Nitish Singh 22 

How to open Contact Object page layout from visual force page

I have a page layout named "User_ContactLayout" for Contact object.  I want to open this as a tab on my service console on click of a button  on the visual force page.
Best Answer chosen by Nitish Singh 22
LBKLBK
Now I get it. You wanna open the Create Contact page onclick of a button.

Try this code.
public PageReference NewContact() { 
	PageReference page = new Pagereference('/003/e?retURL=%2F003%2Fo');
	page.setRedirect(true);
	return page;
}
Onclick of the button, you need to call this piece of code.
 

All Answers

LBKLBK
Hi Nitish,

Are you trying to open a Contact record using this page layout? Or, you want to edit the page layout on click of a button?

If you are trying to open a Contact record, you can create a PageReference in an APEX method and call it on click of a button.
Like the following.
public PageReference OpenContact() { 
	PageReference page = new Pagereference('/' + contactID);
	page.setRedirect(true);
	return page;
}
contactID in th above code is your ID of the contact record. You need to make sure this record uses the above mentioned Page Layout for the user.

Hope this helps.
 
Nitish Singh 22Nitish Singh 22
I am trying to edit the page layout on click of a button
LBKLBK
Edit Layout URL changes everytime you login, because it includes the token in it.

Anyways, you can try to copy it from Address bar (by editing the Pagelayout manually) and use it in the above Page Reference Code.

Let me know how it goes.
Nitish Singh 22Nitish Singh 22
Thanks for your answer.

I am looking to open the Contact edit page from where the details to add new contact can be enterred  
Nitish Singh 22Nitish Singh 22
User-added image

This page to add new contact , i am trying topen as a subatb on service console  from another vf page
LBKLBK
Now I get it. You wanna open the Create Contact page onclick of a button.

Try this code.
public PageReference NewContact() { 
	PageReference page = new Pagereference('/003/e?retURL=%2F003%2Fo');
	page.setRedirect(true);
	return page;
}
Onclick of the button, you need to call this piece of code.
 
This was selected as the best answer
Nitish Singh 22Nitish Singh 22
Thanks a lot @LBK.  I wanted to understand how did you figure out the URL  i.e. '/003/e?retURL=%2F003%2Fo' 
LBKLBK
Go to contacts tab, click on new button.

You can copy the "Relative URL" from the address bar.
Nitish Singh 22Nitish Singh 22
Also i am trying to open this page as a subtab on service console using  sforce.console.openSubtab.

what is the url that i should be passing. currently i did somethimg like this          :

    sforce.console.openSubtab(primaryTabId , 'https://cs17.salesforce.com/003/e?retURL=%2F003%2Fo', false,
                'salesforce', null, openSuccess, 'salesforceSubtab'); 

this is opening a blank tab for me
Nitish Singh 22Nitish Singh 22
Thanks a lot i have figurred it out . I was doing something wrong at my end.

Thanks for your help. It works