• Kunal Bhatia 11
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Could someone let me know what's wrong with the below code.
It was all working fine until I introduced the IF statement, which should be a simple thing.
I'm now getting errors ranging from IF is not defined to Missing ) after arguments.
I'm must be missing something obvious.....

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
// single mail request 
(function() { 
var mail = new sforce.SingleEmailMessage(); 
var templatedId = "00Xb0000000ZiYS"; 
var contactId = ""; 

{IF({!Opportunity.Branch__c } == "Birmingham Opportunity", 
contactId = "0037E00000GpjxR", 
contactId = "0037E00000GpjeO")} 

opportunityId = "{!Opportunity.Id}"; 
mail.replyTo = "{!$User.Email}"; 
mail.targetObjectId= (contactId); 
mail.whatId= (opportunityId); 
mail.templateId = (templatedId); 
var result = sforce.connection.sendEmail([mail]); 
if(result[0].success == 'true') { 
alert("Your email has been sent."); 
} else { 
alert("I had a booboo."); 

}());
I am trying to update the Sample_QB_Error__c field with Hello
This code throws "an Invalid or unexpected token"  

Thanks
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} 
var record = new sforce.SObject("Opportunity"); 
record.Id = ‘{!Opportunity.Id}’; 
record.Sample_QB_Error__c ="Hello"; 
sforce.connection.update([record]); 
window.location.reload();