I am completely new to Salesforce development. Custom button on Contact object needs to create a task and send email( email template) to the contact email when Language field is English or blank, when spanish, spanish email template needs to be sent. But this email needs to go out only one first click and after 180 days, if custom button clicked again, should send email. No action need in the interm. I have asked this question on Salesforce development forum too, but no solution yet. Custom button has been created using below Javascript to create a new task and hidden field Email sent date to populate the date field. Added if condition to verify "Is eligible to survey" formula field and send email only when it's true. But errors out as TRUE is not defined . Can someone help me please
{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}
if({!Contact.Is_Eligible_to_Survey__c} == "TRUE")
try{
var newTask = new sforce.SObject('Task');
newTask.OwnerId = '{!$User.Id}';
newTask.Subject = 'Officevisit: Walk-In';
newTask.Status = 'Completed';
newTask.WhoId = '{!Contact.Id}';
if({!Contact.Language__c}=="English"){
var message = new sforce.SingleEmailMessage();
message.targetObjectId = "{!Contact.Id}";
message.toAddresses = "{!Contact.Email}";
message.templateId = "00X4C000000QvzM";
var result = sforce.connection.sendEmail([message]);
}
else {
({!Contact.Language__c}=="Spanish")
var message = new sforce.SingleEmailMessage();
message.targetObjectId = "{!Contact.Id}";
message.toAddresses = "{!Contact.Email}";
message.templateId = "00X4C000000QvzM";
}
var result = sforce.connection.create([newTask]);
var ContactToUpdate = new sforce.SObject("Contact");
ContactToUpdate.Id = "{!Contact.Id}";
ContactToUpdate.Survey_Sent_Date__c = new Date();
sforce.connection.update([ContactToUpdate]);
window.location.reload();
if(result[0].success=='true'){
alert('The Task was created Successfully.');
}
else{
alert('An Error has Occurred. Error: Please Enter Language' + result);
}
}
catch(e){
alert('An Un-expected Error has Occurred: Error: ' + e);
}