简体   繁体   English

Salesforce.com触发器-需要主要联系人以节省机会

[英]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.

相关问题 Salesforce.com触发条件:将联系人线索源复制到机会 - Salesforce.com Trigger: Copy Contact Lead Source to Opportunity SalesForce.com-报告批准流程的解决方法 - SalesForce.com - Reporting on approval process workarounds 批量删除前触发器(太多Soql语句)Salesforce.com - Bulk Before Delete Trigger (Too Many Soql Statements) Salesforce.com Apex-Salesforce.com-我需要编写APEX类来测试我的工作触发器,需要帮助-聊天-监控特定关键字 - Apex - Salesforce.com - I need help writing an APEX class to test my working trigger - Chatter - Monitor specific keywords 创建触发器,每当Salesforce中存在新机会时,都会创建一个新的机会所有者 - Creating a Trigger that will create a new Opportunity Owner every time a there is a new Opportunity in Salesforce Salesforce.com:UNABLE_TO_LOCK_ROW,无法获得对此记录的排他访问 - Salesforce.com: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record 在Salesforce中的用户触发器中更新联系人电子邮件 - Updating contact email in user trigger in Salesforce Oracle触发器 - 而不是删除,更新行 - Oracle trigger- instead of delete, update the row 在Salesforce中更改机会对象的所有者 - Changing the owner of Opportunity object in Salesforce 在salesforce中更新相应的联系人字段时,触发更新帐户提交 - trigger to Update account filed, when a corresponding contact field is updated in salesforce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM