I have a custom button which is using the javascript code given below. I am getting the error that it is not able to get the Id. Please suggest where am in going wrong.
"cannot read property of Id undefined".


    var orderObj = new sforce.SObject("MiC_Order__c"); 
    orderObj.Id = '{!Order__c.Id}'; 
    var recType = sforce.connection.query("SELECT Id from RecordType where developername = 'Consumer_Open'");
    var records = recType.getArray("records");
    orderObj.RecordTypeId = records[0].Id;

  • Have you check which line is throwing the error? If not use alert() and check for it. I'm suggesting you to replace orderObj.Id with orderObj.id and try – highfive Aug 17 '14 at 17:26
  • Are you sure the query is returning any results? The issue is coming mostly at the line orderObj.RecordTypeId = records[0].Id; because the records has no data and you're trying to the Id property of records. Try putting an alert (records) or write the records to the console using console.log('the records are '+ records). – Sam Aug 17 '14 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.