创建一个触发器:
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.');
}
}
}
}