admin 管理员组

文章数量: 887016

创建一个触发器:

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.');
            }
        }
    }
}

本文标签: 字段 设置为 如何将 对象 Salesforce