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
sushsush 

Creation of opportunity at backend

Hi,
My requirement is to create an opportunity at backend on click of a button.
So i'm using an s-control with ajax but an error is showing up saying
'Exception thrown but not caught'.
 
But with the similar code i'm able to create a account...
 
i was using this code in between script
 

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

opportunity.Name = "My Opportunity";

opportunity.StageName="Prospecting";

opportunity.CloseDate="8/22/2007";

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

var accid=result[0].Id;

alert(accid);

if (result[0].getBoolean("success")) {

alert("new account created with id " + result[0].id);

} else {

alert("failed to create account " + result[0]);

}

 
any help is appreciated.
thanks in advance.
NazeerNazeer
Hi Sush,

I dont know much in S-Controls.

But in your statement  of creating Opty we need to populate Account (Id) as necessary field.

The same would work for Account since this is Master object and no need to populate any other obj related info upon creation of new.

Am I correct.

Nazeer

Ron HessRon Hess
you can see the error message if you add try { } catch it

try {
var result = sforce.connection.create([opportunity]);
} catch ( e) { alert(e); }


or this may work, add to your scontrol somewhere.
Code:
window.onerror = function(msg , url, line){ 
 alert('Message\n' + msg +'\nline:' +  line  +'\nfrom:' +url ); 
}

to my eye, that date does not look like a javascript date which the AJAX toolkit expects, see the ajax documentation.




sfdcfoxsfdcfox
Ron's right; a string isn't necessarily a date, so it needs to be converted to be certain. Try using:

opportunity.CloseDate=new Date("8/22/2007")

That should fix the issue, as the date will be properly translated when it's in a Date object representation.

~ sfdcfox ~