Apex 触发器 - Trailhead

Apex Triggers - Trailhead

代码本身没有给出任何错误,但每当我 运行 Trailhead 给我这个消息时:

"Challenge not yet complete... here's what's wrong: Executing the trigger did not work as expected. "

说明如下:

对于这个挑战,您需要创建一个触发器,在插入或更新之前检查复选框。如果复选框字段为 true,它会将 Shipping Postal Code(其 API 名称为 ShippingPostalCode)设置为与 Billing Postal Code (BillingPostalCode) 相同。

我的代码:

trigger AccountAddressTrigger on Account (before insert,before update) {

    for(Account a : [SELECT Id FROM Account WHERE  Match_Billing_Address__c = TRUE AND BillingPostalCode != NULL])
    {
        a.ShippingPostalCode = a.BillingPostalCode;
        update a;        
    }//end for     
}

你的触发器是这样的

trigger AccountAddressTrigger on Account (before insert,before update) {

    //Iterate all accounts that is updated or inserted.
    for(Account acc :Trigger.New){
        //if match is true set values.
        if(acc.Match_Billing_Address__c){
            acc.ShippingPostalCode = acc.BillingPostalCode;
        }
    }
}

在帐户上触发 AccountAddressTrigger(插入前,更新前){

    for(Account a : Trigger.new){
    If (a.Match_Billing_Address__c == true && a.BillingPostalCode!=Null) {
        a.ShippingPostalCode = a.BillingPostalCode;
    }   
} 

}

首先需要在帐户选项卡中创建名称匹配帐单地址的复选框字段,然后打开开发人员控制台并编写代码并保存。最后检查它是否再次在您的销售人员实例中工作

这是代码:

在帐户上触发 accountAddressTrigger(插入前,更新前){

for(Account acct : trigger.new){

      if(acct.Match_Billing_Address__c == true)

      acct.ShippingPostalCode = acct.BillingPostalCode;
      }

}

对象上触发Name_of_Trigger(事件1,事件2){

   for(Each Object's Event1/Event2) {
       if (Check box is selected) {
               Assign Billing address to Shipping address (i.e using '=' operator);
                                 }
                      }

}