最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

salesforce 当 opportunity 的关联对象存在的话,如何将 currency 字段设置为不可修改

业界 admin 5浏览 0评论

创建一个触发器:

trigger OpportunityTrigger on Opportunity (before update) {
    for (Opportunity opp : Trigger.new) {
        if (opp.CurrencyIsoCode != Trigger.oldMap.get(opp.Id).CurrencyIsoCode) {
            // 检查关联对象是否存在,假设关联对象是CustomObject__c
            List<CustomObject__c> relatedObjects = [
                SELECT Id
                FROM CustomObject__c
                WHERE Opportunity__c = :opp.Id
            ];
            if (!relatedObjects.isEmpty()) {
                opp.addError('Currency field cannot be modified when related objects exist.');
            }
        }
    }
}

创建一个触发器:

trigger OpportunityTrigger on Opportunity (before update) {
    for (Opportunity opp : Trigger.new) {
        if (opp.CurrencyIsoCode != Trigger.oldMap.get(opp.Id).CurrencyIsoCode) {
            // 检查关联对象是否存在,假设关联对象是CustomObject__c
            List<CustomObject__c> relatedObjects = [
                SELECT Id
                FROM CustomObject__c
                WHERE Opportunity__c = :opp.Id
            ];
            if (!relatedObjects.isEmpty()) {
                opp.addError('Currency field cannot be modified when related objects exist.');
            }
        }
    }
}
发布评论

评论列表 (0)

  1. 暂无评论