2015-06-04 38 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

相關問題