1

I keep getting 'unexpected token ==' when the button is clicked. I have been through the code and everything looks right to me. Can anyone see why? All field names are correct.

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

if({!Delegate__c.VC_Profile_ID__c} == ""
&& ({!Delegate__c.Online_SAP_Course__c} == "TR_ELE_037"
|| {!Delegate__c.Online_SAP_Course__c} == "TR_ELE_038"
|| {!Delegate__c.Online_Course_Name__c} == "18th Edition Full"
|| {!Delegate__c.Online_Course_Name__c} == "18th Edition Update")
&& {!Delegate__c.Delegate_Email__c} != "email@notprovided.com")
    {
     var newRecords = [];
     var del = new sforce.SObject("delegate__c");
     del.id ="{!Delegate__c.Id}";
     del.VCManualTrigger__c = true;
     newRecords.push(del);
     result = sforce.connection.update(newRecords);
     window.location.reload();
    }

else if({!Delegate__c.VC_Profile_ID__c}!= ""
&& {!Delegate__c.Delegate_Email__c} != "email@notprovided.com")
    {
     alert("This delegate is already on Virtual College, us the profile link to view")
    }

else if({!Delegate__c.Delegate_Email__c} == "email@notprovided.com")
    {
     alert("Invalid delegate email address")
    }
else
    {
     alert("Error")
    }
3

Wrap your apex merge variables in quotes. They're directly printed into the javascript, which can be useful, but needs to be handled a certain way.

if("{!Delegate__c.VC_Profile_ID__c}" == "") { ... }

result:

if("001U000000ASKk1" == "") { ... }

Instead of:

if(001U000000ASKk1 == "") { ... }
  • Knew it would be something ridiculously simple! Thanks so much, working fine now – Joe Hayes Sep 5 '18 at 14:35
1

I think you need to put merge fields with double quotes as follows, other than this I dont find anything

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

if("{!Delegate__c.VC_Profile_ID__c}" == ""
&& ("{!Delegate__c.Online_SAP_Course__c}" == "TR_ELE_037"
|| "{!Delegate__c.Online_SAP_Course__c}" == "TR_ELE_038"
|| "{!Delegate__c.Online_Course_Name__c}" == "18th Edition Full"
|| "{!Delegate__c.Online_Course_Name__c}" == "18th Edition Update")
&& "{!Delegate__c.Delegate_Email__c}" != "email@notprovided.com")
    {
     var newRecords = [];
     var del = new sforce.SObject("delegate__c");
     del.id ="{!Delegate__c.Id}";
     del.VCManualTrigger__c = true;
     newRecords.push(del);
     result = sforce.connection.update(newRecords);
     window.location.reload();
    }

else if("{!Delegate__c.VC_Profile_ID__c}" != ""
&& {!Delegate__c.Delegate_Email__c} != "email@notprovided.com")
    {
     alert("This delegate is already on Virtual College, us the profile link to view")
    }

else if("{!Delegate__c.Delegate_Email__c}" == "email@notprovided.com")
    {
     alert("Invalid delegate email address")
    }
else
    {
     alert("Error")
    }

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.