我正在尝试在Apex中创建一个触发器,该触发器有助于在阶段更新时增加计数

时间:2018-11-09 08:12:10

标签: salesforce apex apex-code

基本上,当“阶段”标记为“已关闭”时,“机会”中一个编号为“已关闭_成功__c”的数字字段应将其计数增加1。有人可以帮我提供代码吗

2 个答案:

答案 0 :(得分:0)

您是说您是新来的。从Salesforce的Trailheads开始。它们非常适合开始使用SF的人们。

以下是有关触发器的模块链接: https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro

尽管如此,我还是建议您从Apex Basics开始检查其他模块: https://trailhead.salesforce.com/content/learn/modules/apex_database

答案 1 :(得分:0)

这是该代码

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.
       }
}

}