Javascript snippet button not working

Eugene RinehartEugene Rinehart ✭✭✭
edited September 4, 2019 in Questions
I have a button in a Skuid Opportunity overlay that is not working. When pressed, nothing happens at all, not even an error message. Any idea why this might be happening? I and my team are stuck! 
Button Type: Run Skuid Snippet
Snippet Properties: 
Resource location: In-Line (Snippet)
Snippet Body
var $ = skuid.$;
var opp = skuid.model.getModel("Opportunity").getFirstRow();
var o = new sforce.SObject("Opportunity");
o.Id = opp.Id;
var contactId = sforce.connection.query("SELECT ID FROM Contact WHERE Name LIKE '%" + opp.Installer_Salesperson_Text__c + "%' AND AccountId  = '" + opp.AccountId + "'");
if (contactId.getArray("records")[0] === null || contactId.getArray("records")[0] === '' || contactId.getArray("records")[0] === undefined) { 
    alert('We were not able to find a contact record for the Salesperson contact on this opportunity. To login as user, please go to their contact page.');
} else {
    var result = sforce.apex.execute('GhostingUtil','login',{partnerConId:contactId.getArray("records")[0].Id});
    if (result.includes('ERROR: ')) {
    } else {,'_blank');


  • edited September 3, 2019
    Thanks for showing useful coding approaches I haven't used before! Gives me a new tool to try.

    To debug, you could put alerts after all (or most) statements and see if and when the script dies; I prefer console.log() for this.

    But my guess is that when the query returns nothing, contactId doesn't get a getArray() object, and the if statement dies. Wrap the if with an outer if ( contactId.getArray() ) or maybe if ( contactId.getArray().size ) or similar construct.  (Would that be .length instead of .size?)

  • Eugene RinehartEugene Rinehart ✭✭✭
    edited December 27, 2018
    Hi Mike, I appreciate your response! I had my team review your suggestion, and the sticking point is that this is older code that's worked properly in the past and we haven't made any recent updates. We're wondering whether Skuid's changed anything on their end where our code might need to be adjusted to accomodate. 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!