0

I'm trying to create a custom button that executes javscript on the Case object. I simply want to check if the Case has a specific child record already and forward the user to that record if it exists or to create a new record with specific fields defaulted.

Here is the code I'm using:

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

var result = sforce.connection.query("SELECT Id FROM Estimate_Price__c WHERE Case__c='{!Case.Id}' AND (Name='Base Price' OR IsBasePrice__c=true)", {
    onSuccess : function(result) {
      console.debug('RESULT:', result);
      var records = result.getArray("records");
      if(records.length == 0) {
        window.location = '/a0q/e?CF00NL0000003hMbW=00001340&CF00NL0000003hMbW_lkid=500L0000008INOa&retURL=%2F500L0000008INOa&Name=Base Price';
      } else {
        window.location = '/' + records[0].Id + '/e;
      }
    },
    onFailure : function(error) {
      console.debug('ERROR:', error);
      log("An error has occurred " + error);
      alert('An error occurred. Please contact an admin.');
    }
});

This was working about an hour ago and then all of sudden I started receiving the following message: enter image description here

Any ideas on why this is occurring or how to fix?

2

Try with following code i can see that you have issue with line no. 11

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

var result = sforce.connection.query("SELECT Id FROM Estimate_Price__c WHERE Case__c='{!Case.Id}' AND (Name='Base Price' OR IsBasePrice__c=true)", {
    onSuccess : function(result) {
      console.debug('RESULT:', result);
      var records = result.getArray("records");
      if(records.length == 0) {
        window.location = '/a0q/e?CF00NL0000003hMbW=00001340&CF00NL0000003hMbW_lkid=500L0000008INOa&retURL=%2F500L0000008INOa&Name=Base Price';
      } else {
        window.location = '/' + records[0].Id + '/e';
      }
    },
    onFailure : function(error) {
      console.debug('ERROR:', error);
      log("An error has occurred " + error);
      alert('An error occurred. Please contact an admin.');
    }
});
  • Missed a single quote. Nice catch. Can't believe my code editor didn't highlight that. Thanks!! – jonnybro Apr 20 '16 at 20:04
  • welcome!! Tips: always check browser console for error you will that with line no. :) – Himanshu Apr 20 '16 at 20:05
  • @jonnybro I'm pretty sure most editors don't highlight open string quotes. Try using Programmer's Notepad. – sfdcfox Apr 20 '16 at 20:06
  • @Himanshu Yeah the browser console didn't receive any errors on this occasion. The only feedback I got was that alert. – jonnybro Apr 20 '16 at 20:10
  • @sfdcfox I wrote it in sublime text first which normally would show that a string hasn't been closed. Must not of had it set to javascript when I originally wrote it. – jonnybro Apr 20 '16 at 20:12

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.