You need to sign in to do that
Don't have an account?
Layout change on click of a custom button
I have 1 custom button on a detail page's (standard layout ) of a custom object. It is already having a functionality of redirecting to a URL(lets say functionality 1). Now I have to add 1 additional functionality that if a user clicks this button, the record type(hence page layout) should change and functionality 1 should also work.
Currently content source is URL.
(I thought of adding some JavaScript to this button but I am confused how to add JavaScript along with the URL, or will both the functionality will work simultaneously or not.)
Any help would be highly appreciated.
Thanks
R_Shri
I think that button through whoch you want to chang the layout, just create a new vf page of standard look and feel and assign that vf page to that button, and then addd the same functionality to that button too.
So then when the user will click the button a new page will appear on the same window, whick looks it changes the layout.
There are two approach to do this.
If you know what the recordtype is then hardcode in the URL.
for example
https://ap1.salesforce.com/{!Account.Id}/e?RecordType=01290000000spKa
The text in the red is recordtype id.
Another approach would be dynamic, You will have to make query to fatch recordtype.
For this you need to use content source for button is java script. Here I am sharing some code you can refer and let me know
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
var results= sforce.connection.query("SELECT id,Name
FROM RecordType " +
"WHERE SobjectType='Contact ' AND Name='PrimaryContact'");
var records = results.getArray("records");
var arr = new Array();
var id;
for (var i = 0; i < records.length; i++)
{
id = records[0].id;
}
var url = 'yourlink or extrra&RecordType ='+id;
window.open(url,target=_blank');
Hi asish1989,
Thanks for your help.
I tried your first solution but it is redirecting to edit page page layout (with layout of new recordType say RecordType2) of custom object and not to my link. And also when I checked the record of that custom object it had same layout (of RecordType1)
I also tried second approach but here I am getting a popup with error as : A problem with OnClick JavaScript for this button or link was encountered : Unexpected Token ILLEGAL
For second sol. I tried as follows:
1.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
var results= sforce.connection.query("SELECT id,Name
FROM RecordType " +
"WHERE SobjectType='CustomObject__c ' AND Name='RecordType2'");
var records = results.getArray("records");
var arr = new Array();
var id;
for (var i = 0; i < records.length; i++)
{
id = records[0].id;
}
var url = 'https://www.google.com&RecordType ='+id;
window.open(url,target=_blank');
2.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}
var url = 'https://www.google.com&RecordType ='+my 18 digit RecordType2 (harcoded )Id;
window.open(url,target=_blank');
Every time I got the same popup.
(In name I also tried Name = 'CustomObjectName')
Please let me know if I missed smoething or if I misunderstood something.
Can you provide that link whatever you have given in the button code.
I will try to do in the first approach.
If you want to be in the second approcah then give me Object name and recordtype name.
This is the link which I have given
https://ap1.salesforce.com/{!Account.Id}/e?RecordType=01290000000spKa
Do one thing, just append this at end of your link ?RecordType=01290000000spKa
Let me know If it works for you
Thanks for your efforts, but Sorry! The data you have asked for is client's confidential data. u can use any customObject and any website for the link. As I have to just change the layout in RecordType2 (and in RecordType2 I am just replacing this button with a new button)
In first approach where should I put my link??
Thanks
R_Shri
is that link about some salesforce link?
if that link entirly different from salesforce then Its impossible,If not then just append "RecordType=01290000000spKa" at end of your link