You need to sign in to do that
Don't have an account?
Umair Khan 19
java script -how open the record inserted in same page
I created a custom button on the account detail page and when I click the button a new contact record is created using account data and the page is reloaded. I want to open the contact page after it is inserted,.
This is what i tried
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var con=new sforce.SObject("contact");
con.Lastname='{!Account.Name}';
con.accountId='{!Account.Id}';
result = sforce.connection.create([con]);
window.location.reload();
and this is for referring the page but is showing Undefined.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var con=new sforce.SObject("contact");
con.Lastname='{!Account.Name}';
con.accountId='{!Account.Id}';
result = sforce.connection.create([con]);
window.location.assign("https://ap15.salesforce.com/"+con.id);
This is what i tried
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var con=new sforce.SObject("contact");
con.Lastname='{!Account.Name}';
con.accountId='{!Account.Id}';
result = sforce.connection.create([con]);
window.location.reload();
and this is for referring the page but is showing Undefined.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
var con=new sforce.SObject("contact");
con.Lastname='{!Account.Name}';
con.accountId='{!Account.Id}';
result = sforce.connection.create([con]);
window.location.assign("https://ap15.salesforce.com/"+con.id);
Greetings to you!
Just add below line in your code:
window.location = "/" + result[0].id;
Please try below code:
If you want to open in edit mode then you need to add + "/e"
window.location = "/" + result[0].id + "/e";
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Just add below line in your code:
window.location = "/" + result[0].id;
Please try below code:
If you want to open in edit mode then you need to add + "/e"
window.location = "/" + result[0].id + "/e";
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
It worked!! :)