自動將權益從 Web、電子郵件與 Experience 新增至個案
權益不會自動套用至使用「線上個案」、「電子郵件轉個案」或 Experience 所建立的個案。但是,您可以使用 Apex 程式碼將權益新增至這些功能。
必要版本
| 檢視支援的版本。 |
| 需要的使用者權限 | |
|---|---|
| 若要定義 Apex 觸發: | Author Apex |
當透過「線上個案」、「電子郵件轉個案」或 Experience 建立個案時,個案不會自動與權益相關聯。當個案的「權益」欄位為空白時,此範例觸發會檢查個案連絡人是否有已啟用的權益。如果連絡人有已啟用的權益,權益會新增至個案。如果連絡人沒有已啟用權益,則觸發會檢查個案帳戶是否具備已啟用權益。如果個案帳戶有已啟用的權益,權益會新增至個案。觸發有助於根據您的客戶支援契約解決個案。
- 針對 Classic,進入「設定」,在「快速尋找」方塊中輸入「個案觸發」,然後選取「個案觸發」。
- 按一下「新增」。
- 複製下方程式碼並將其貼到文字欄位中。
- 按一下「儲存」。
- 針對 Lightning,從開發人員主控台中選取「檔案 > 新增 > Apex 觸發」。
- 輸入觸發的名稱,然後選取「物件」作為「個案」。
- 按一下「提交」。
- 複製下方程式碼並將其貼到文字欄位中。
- 按一下「儲存」。
範例
trigger DefaultEntitlement on Case (Before Insert, Before Update) {
Set<Id> contactIds = new Set<Id>();
Set<Id> acctIds = new Set<Id>();
for (Case c : Trigger.new) {
contactIds.add(c.ContactId);
acctIds.add(c.AccountId);
}
List <EntitlementContact> entlContacts =
[Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId
From EntitlementContact e
Where e.ContactId in :contactIds
And e.Entitlement.EndDate >= Today
And e.Entitlement.StartDate <= Today];
if(entlContacts.isEmpty()==false){
for(Case c : Trigger.new){
if(c.EntitlementId == null && c.ContactId != null){
for(EntitlementContact ec:entlContacts){
if(ec.ContactId==c.ContactId){
c.EntitlementId = ec.EntitlementId;
if(c.AssetId==null && ec.Entitlement.AssetId!=null)
c.AssetId=ec.Entitlement.AssetId;
break;
}
}
}
}
} else{
List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate,
e.AccountId, e.AssetId
From Entitlement e
Where e.AccountId in :acctIds And e.EndDate >= Today
And e.StartDate <= Today];
if(entls.isEmpty()==false){
for(Case c : Trigger.new){
if(c.EntitlementId == null && c.AccountId != null){
for(Entitlement e:entls){
if(e.AccountId==c.AccountId){
c.EntitlementId = e.Id;
if(c.AssetId==null && e.AssetId!=null)
c.AssetId=e.AssetId;
break;
}
}
}
}
}
}
}
另請參照:
此文章是否解決您的問題?
請讓我們知道,以便我們改進!
