1

I created a new object to store reasons for a case to be deleted. My JS is returning an error:

"Cannot read property 'Id' of undefined" AND "Id not specified in an update call"

I was wondering if anyone can see the issue with my code.

{{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 

var confirmation = window.confirm("Do you want to delete?");

if (confirmation == true) { 
  var recordtypes = sforce.connection.query("SELECT Id, Reson_for_Deletion__c FROM Deleted_Cases__c").getArray("records"); 

  var reason = prompt("Please define the Reason for delete");

  if (reason != null) { 
    var CallObj = new sforce.SObject("Deleted_Cases__c"); 
    CallObj.Id = '{! Deleted_Cases__c.Id}'; 
    CallObj. Reason_for_Deletion__c = reason;
    CallObj.Status__c = 'Delete'; 
    var result = sforce.connection.update([CallObj]); 

    console.log('result'+result[0]); 

    if (result[0].success=='false') { 
      alert(result[0].errors.message); 
    }
    else { 
      location.reload(true); 
    } 
  } 
}

Thanks for reading.

  • 1
    Where does this button live? (In which object) – Sebastian Kessel Dec 21 '15 at 16:20
  • 1
    Is Reson_for_Deletion__c a typo? – Dan Jones Dec 21 '15 at 16:33
  • 1
    Just to confirm. I have with above code (including typo). It is working for me same code with different object and fields – Ratan Paul Dec 21 '15 at 17:08
0

Problem is with this line:-

CallObj.Id = '{! Deleted_Cases__c.Id}'; 

CallObj should have proper Id so that it can update that particular record. Deleted_Cases__c is a record type, not a record. You have queried it before by using this line:-

var recordtypes = sforce.connection.query("SELECT Id, Reson_for_Deletion__c FROM Deleted_Cases__c").getArray("records"); 

Use recordtypes var for assign correct Id to CallObj.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.