+ Start a Discussion

Java Script is not working for Button click ?

I have created Detailed abutton and placed on the Task Record. The button should function like when we click the button a New opportunity page will opened and carry the data from Task to the Opportunity and need to display on Opportunity fields.  Below javascript created. But  it giving error like that    'Task.WhoId' is not exist like that. Please anyone correct bthis.


    var OpportunityCreate= new sforce.SObject("Opportunity");

OpportunityCreate.Contact_Name__c = '{!Task.WhoId}';

    var result = sforce.connection.create([OpportunityToCreate]);

    if (result[0].success == 'true')
   var newURL = '/' + result[0].id + '/e';
   window.top.location = newURL;
Hii Tillu,
check your this line :  var result = sforce.connection.create([OpportunityToCreate]);
             and try 
                      i think it should be like this :var result = sforce.connection.create([OpportunityCreate]);

     If your problem solved then please mark it as best answer so that it appear as a solved qusestion.

TC DeveloperTC Developer
If you are chrome chech with cntl+shift+j and check the problem and let me know what is happening there 
Ranjeet Singh (SFDC Developer)Ranjeet Singh (SFDC Developer)
Hi Tillu,
Use following code and pass the required field value based on your organizations.....

var OpportunityCreate = new sforce.SObject("Opportunity");
OpportunityCreate.Name = '{!Task.Status}'+' - '+'Opportunity by Task';
OpportunityCreate.CloseDate = '2016-10-26Z';
OpportunityCreate.StageName = 'Prosecting';
OpportunityCreate.ForecastCategoryName = 'Pipeline';
var result = sforce.connection.create([OpportunityCreate]);
window.location.href = '/'+result[0].id;

Thanks & Regards,
Ranjeet Singh.