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?

1 Answer 1

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.');
    }
});
5
  • Missed a single quote. Nice catch. Can't believe my code editor didn't highlight that. Thanks!!
    – jonnybro
    Commented Apr 20, 2016 at 20:04
  • welcome!! Tips: always check browser console for error you will that with line no. :)
    – Himanshu
    Commented Apr 20, 2016 at 20:05
  • @jonnybro I'm pretty sure most editors don't highlight open string quotes. Try using Programmer's Notepad.
    – sfdcfox
    Commented Apr 20, 2016 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
    Commented Apr 20, 2016 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
    Commented Apr 20, 2016 at 20:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .