gpt4 book ai didi

javascript - 更新 Salesforce 案例信息

转载 作者:行者123 更新时间:2023-11-28 01:37:01 24 4
gpt4 key购买 nike

我创建了一个按钮来升级案例。我正在尝试更改记录类型“所有者”并将“案例升级”附加到“注释”字段。

代码:

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

var objCase = new sforce.SObject('Case');
objCase.Id = '{!Case.Id}';
objCase.Owner__c = 'Global Salesforce Team';
objCase.RecordTypeId = '012C00000007l5WIAQ';
objCase.Notes__c += 'Case Escalated';

var result = sforce.connection.update([objCase]);
if(result[0].success=='true'){
alert('The Case was Updated Successfully');
location.reload(true);
} else if(result[0].success=='true'){
alert('There was an issue updating the case');
}

但是,这会删除“注释”字段并添加“undefinedCase Escalated”,而不是将字符串“Case Escalated”附加到其中任何内容的末尾。

我是 JavaScript 新手,请多多关照:)

最佳答案

我看到了代码,问题似乎是您正在创建要更新的案例的新实例,因此注释字段上没有任何内容,一旦您插入记录,它就会用那里唯一的文本覆盖,' Case Escalated',要使其正常工作,您必须执行查询来查找该字段之前的值,然后将该值附加到notes__c字段。

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

var result = sforce.connection.query("select Id, Owner__c, RecordTypeId, Notes__c from Case WHERE Id='{!Case.Id}' LIMIT 1");
var records = result.getArray('records');

var objCase = records[0];
objCase.Owner__c = 'Global Salesforce Team';
objCase.RecordTypeId = '012C00000007l5WIAQ';
objCase.Notes__c += 'Case Escalated';

var result = sforce.connection.update([objCase]);
if(result[0].success=='true'){
alert('The Case was Updated Successfully');
location.reload(true);
} else if(result[0].success=='true'){
alert('There was an issue updating the case');
}

包含示例的开发人员指南的链接位于 http://www.salesforce.com/us/developer/docs/ajax/apex_ajax.pdf

尚未对其进行测试,并且我的代码中需要进行一些错误处理,但它应该可以工作。

关于javascript - 更新 Salesforce 案例信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21431385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com