Salesforce自定义按钮返回'意外令牌非法

Salesforce custom button returning 'Unexpected Token ILLEGAL?

本文关键字:意外 令牌 非法 自定义 按钮 返回 Salesforce      更新时间:2023-09-26
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
/*Getting the Running User Details*/
var result = 
sforce.connection.query(
    "SELECT Advisor__c " + 
    "FROM User " +
    "WHERE Id = '{!$User.Id}'"
);
/*Grab the Records returned by executing the above SOQL Query*/
var userDetails = result.getArray("records")[0];
/*Initializing the Contact record for Update*/
var contactToUpdate = new sforce.SObject("Contact");
contactToUpdate.Id = "{!Contact.Id}";
/*If the Running User is an "Advisor" then set the
Contact With and associated fields*/
if(userDetails.Advisor__c === true){
contactToUpdate.Contact_With__c = "{!$User.Id}";
contactToUpdate.Last_Advisor_Touch__c = new Da​te();
}
/*If the Running User isn't an "Advisor" then set the
Contact With 2 and associated fields*/
else{
contactToUpdate.Contact_With_2__c = "{!$User.Id}";
contactToUpdate.Last_Non_Advisor_Touch__c = new Date();
}
var result = sforce.connection.update([contactToUpdate]);
if(result[0].success === true){
location.reload();
}
else{
alert(result[0].errors.message);
}

我在我们的用户配置文件中添加了一个名为"Advisor"的自定义复选框字段,该代码应该根据用户是否选中该复选框来区分要更新哪个字段。如果是,则更新此字段,如果不是,则更新该字段。相反,它返回一个"意外令牌非法"。不知道为什么

似乎你有一个特殊的隐藏字符在下一行contactToUpdate.Last_Advisor_Touch__c = new Da​ te();

在word Date中

如果你把它重写一下,它应该可以工作。特别是你有臭名昭著的零宽度空格之间的Da和te可能来自这个。为了消除这些东西,你可以使用这个工具或者这个