2015-06-04 37 views
0
{!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”的用户配置文件中添加了一个自定义复选框字段该代码假设根据用户是否检查了此框来区分要更新的字段。如果是更新该字段,则不更新该字段。相反,虽然它返回了'非预期令牌非法。不知道为什么。Salesforce自定义按钮返回'非预期令牌非法?

回答

1

好像你在下面一行 contactToUpdate.Last_Advisor_Touch__c = new Da​ te();

字日期 如果你只是把它改写它应该工作有特殊的隐藏字符。 具体来说,你和Da之间臭名昭着的ZERO WIDTH SPACE可能来自this。要消除这种情况,您可以使用this toolthis one

相关问题