[英]Salesforce.com Trigger- Require primary contact to save opportunity
There are currently two AppExchange apps that do this, but I was wondering if anyone has figured out how to do this without installing an app, as the number of apps I can install in my organization is limited. 当前有两个AppExchange应用程序可以执行此操作,但是我想知道是否有人知道如何在不安装应用程序的情况下执行此操作,因为我可以在组织中安装的应用程序数量有限。
The trigger needs to check to see if there is a contact listed, if not, then an error message should display. 触发器需要检查以查看是否列出了联系人,如果没有,则应显示一条错误消息。 I tried this with validation rules, but had no luck because the OpportunityContactRole is a separate object.
我尝试了验证规则,但是运气不好,因为OpportunityContactRole是一个单独的对象。
Could someone provide their thoughts? 有人可以提供他们的想法吗?
trigger OpportunityBeforUpdate on Opportunity (before update) {
set<Id> oppIdSet = new set<Id>();
set<Id> OpportunityContactRoleIdSet = new set<Id>();
for(Opportunity opp:trigger.new){
if("Some condition")oppIdSet.add(opp.Id);
}
for(OpportunityContactRole ocr:[select Id,OpportunityId from OpportunityContactRole where OpportunityId in:oppIdSet]){
OpportunityContactRoleIdSet.add(ocr.OpportunityId);
}
for(Opportunity opp:trigger.new){
if(oppIdSet.contains(opp.Id) && !OpportunityContactRoleIdSet.contains(opp.Id))
opp.addError('Some error');
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.