Create a detail page button associated to execute javascript function selected on Account object and place it in account layout.
place the below code on javascript code to create an opportunity record Account related list
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;
var newopportunity= new sforce.SObject("Opportunity");
newopportunity.Name = "{!Account.Name}";
newopportunity.AccountId="{!Account.Id}";
newopportunity.StageName="Active";
newopportunity.CloseDate=new Date();
result = sforce.connection.create([newopportunity]);
alert(result );
That's it, oncliking the button a record Id will be appeared, refresh the page and you will see a record in the opportunity related list.
place the below code on javascript code to create an opportunity record Account related list
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;
var newopportunity= new sforce.SObject("Opportunity");
newopportunity.Name = "{!Account.Name}";
newopportunity.AccountId="{!Account.Id}";
newopportunity.StageName="Active";
newopportunity.CloseDate=new Date();
result = sforce.connection.create([newopportunity]);
alert(result );
That's it, oncliking the button a record Id will be appeared, refresh the page and you will see a record in the opportunity related list.
No comments:
Post a Comment