首页 > 解决方案 > 我正在尝试在 Apex 中创建一个触发器,这有助于在阶段更新时增加计数

问题描述

基本上,当 Stage 被标记为 Closed Won 时,Opportunity 中标记为 Closed_Won__c 的数字字段应将其计数增加 1。有人可以帮我写代码吗

标签: salesforceapexapex-code

解决方案


这是代码

trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
for(Opportunity opp : [SELECT Id,StageName FROM Opportunity Where Id IN :Trigger.New])
{
    if(opp.StageName == 'Closed Won')
       {
           //add the code to increment the corresponding value here.
       }
}

}

推荐阅读