You need to sign in to do that
Don't have an account?
kkaal
SObject Creation does not work
Hi, I have an SControl which needs to create an SObject. Everything would be fine, if creating of the object would work. When I call the function below, it shows the indicated alerts. After that (obviously in the "var result = sforce.connection.create([sample]);" line the program drops out without error, warning or any other sign. The object is not created. There are only the 2 datafields which have to be filled, no other fields are mandatory.
Does anybody have an idea what to do?
Thanks
Klaus
function createSample(){
alert("1" ); //shows up
var sample = new sforce.SObject( "Trip_Report__c" );
sample.Contact_Name_Department__c = sumlist;
sample.Account__c = "{!Account.Id}";
alert( sample.Account__c ); // shows val, thus indicating, that the object sample exists
alert( sample.Contact_Name_Department__c ); // shows val
alert("2"); // shows up
var result = sforce.connection.create([sample]);
alert( "3" ); // does not pop up
if (result[0].getBoolean("success")) {
alert( result[0].id );
//backToAccount();
window.top.location.href = "/" + result[0].id; //"/{!Account.Id}";
} else {
alert("failed to create Object " + result[0]);
}
}
Does anybody have an idea what to do?
Thanks
Klaus
function createSample(){
alert("1" ); //shows up
var sample = new sforce.SObject( "Trip_Report__c" );
sample.Contact_Name_Department__c = sumlist;
sample.Account__c = "{!Account.Id}";
alert( sample.Account__c ); // shows val, thus indicating, that the object sample exists
alert( sample.Contact_Name_Department__c ); // shows val
alert("2"); // shows up
var result = sforce.connection.create([sample]);
alert( "3" ); // does not pop up
if (result[0].getBoolean("success")) {
alert( result[0].id );
//backToAccount();
window.top.location.href = "/" + result[0].id; //"/{!Account.Id}";
} else {
alert("failed to create Object " + result[0]);
}
}
try {
var result = sforce.connection.create([sample]);
}catch(error) {
alert("Got error: " + error);
}
Change your code
object.field=value;
to
object.set("field", value);
And don't forget about "try and catch"
But here is my next question:
After creating my SControl, I would like to open it in its editor:
try {
var result = sforce.connection.create([sample]);
}catch(error){
alert("Got error: " + error);
}
if (result[0].getBoolean("success")) {
window.top.location.href = "/" + result[0].id;
} else {
alert("failed to create Object " + result[0]);
window.top.location.href = "/{!Account.Id}";
}
I really have problems to create proper urls to navigate to the form I want to go to. Which document helps me to understand the concept? I am searching for this now quite some hours.
Thank you for your advice.
Klaus