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
BERNARDOBERNARDO 

(Newbie) Problems populating custom object

Hi all.
 
I'm new to salesforce development, and I am trying to implement a custom button into Contact search layout and populate a custom object (including Contact Id). The part of the code where error appears is:
 
try {
 var recordIds = {!GETRECORDIDS($ObjectType.Contact)};
 if (recordIds.length > 0) {
  for (var i=0; i<recordIds.length ; i++) {
 
// This is the line that causes the catch ("ERROR [object Error]")
//
   inscrip = new sforce.SObject("SFDC_Enrollment__c");
//
// 

   inscrip.Class__c=claseValue[1];
   inscrip.Contact__c=recordIds[i];
   inscrip.Status__c= "Inscrito";
   result = sforce.connection.create([inscrip]);
   }
  } else {
  alert("No records selected"); //runs ok if no records were selected
 }
 
} catch (e) {
alert("ERROR "+e);
}
 
I'm not sure if it is because I'm trying to create a custom object (BTW, the script is larget and it goes fine up to these lines). I will appreciate any thoughts or ideas.
 
Thanks in advance.
Bernardo
sean33043sean33043
What is the error message? If you are sure that the line in question is causing the error, is the custom object spelled correctly? ("SFDC_Enrollment__c") Is it createable? A search of this board shows other problems related to this object and it appears the answer is in the error message.
 
Sean
 
 
michaelforcemichaelforce
Have you declared the variable 'inscrip' somewhere prior to this in the code?
BERNARDOBERNARDO

Hi Sean, and thanks for the quick reply.

The error message is simply "[object Error]".

The custom object's API name is "SFDC_Enrollment__c" and it is properly spelled .

Unfortunately I couldn't find other answers in this board related to this issue (in fact I didn't find other discussion related to problems with custom object creation). A question: can a custom object NOT be "createable"? Where should I make sure SFDC_Enrollment__c is createable?

BTW, I probably erased the "var" word when I wrote the "//"'s. The line is:

var inscrip = new sforce.SObject("SFDC_Enrollment__c");

Thanks again!
Bernardo

BERNARDOBERNARDO
Please discard this discussion. I found the error (problems with the requireScript in the first line), that I could check with catch(e)... alert(e.description).
 
The script runs ok.
 
Sorry for the inconvenience and thanks for the help!
 
Bernardo