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
Ronnie Paton 8Ronnie Paton 8 

Oneclick java script issues

HI,

I am trying to create a custom button on a custom Object that when clicked creates Account\Contact\Opportunity (like convert button on Lead).

The code I have is 
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   Prospect__c.Converted_Date__c = dt;
var result = sforce.connection.update([ProspectObj]);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippinggCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId = '{!Account.Id}';
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = '{!Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Perception Analysis';
   opp.Type = 'New Business';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Initial_Meeting_Scheduled__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/a05?fcf=00Bb0000003wFhp';
}

when I click the button I get an error saying that Prospect__c is not defined.

Any pointers would be a great help.

Thanks in Advance

Ronnie

 
Best Answer chosen by Ronnie Paton 8
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

Try changing this line:
 
// original code   
Prospect__c.Converted_Date__c = dt;

// change to
ProspectObj.Converted_Date__c = dt;

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

All Answers

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

Try changing this line:
 
// original code   
Prospect__c.Converted_Date__c = dt;

// change to
ProspectObj.Converted_Date__c = dt;

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
This was selected as the best answer
Ronnie Paton 8Ronnie Paton 8
Nice spot been looking at this for a couple of hours, 
Thanks for all your help