+ Start a Discussion
Dannilo FrancoDannilo Franco 

Challenge Not yet complete... here's what's wrong: Setting 'Match_Billing_Address__c' to true did not update the records as expected.

I'm getting the same error even though I'm using the code provided by other users here. The new field is also created.
 
trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c == true) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }
}

Is there anything wrong with it? 

Thanks in advance.
Best Answer chosen by Dannilo Franco
Dannilo FrancoDannilo Franco
Hey Sumit,

I just fixed the problem! For some reason the Trigger was inactive. I actived it and checked the Challenged and worked properly!

Best,

Dannilo

All Answers

Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Dannilo,

Can you pls tell me what error you are getting. It's working fine in my dev account.


Thanks, 
Sumit Kumar Singh
Dannilo FrancoDannilo Franco
Hi Sumit,

I'm getting the following error:

Challenge Not yet complete... here's what's wrong: 
Setting 'Match_Billing_Address__c' to true did not update the records as expected.

I created the Match Billing Address property and I rewrote my code like suggested in other posts but I'm still getting this error.

Any ideas? Can it be my dev account?

Thanks,

Dannilo
Dannilo FrancoDannilo Franco
Hey Sumit,

I just fixed the problem! For some reason the Trigger was inactive. I actived it and checked the Challenged and worked properly!

Best,

Dannilo
This was selected as the best answer
HK2SFDCHK2SFDC
trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.new){
/* from below if statement (a.BillingPostalCode != null)  checks "if an Account has a Billing Postal Code" from challenge
           if(a.BillingPostalCode != null && a.Match_Billing_Address__c == true){
                a.ShippingPostalCode  = a.BillingPostalCode;
            }
    }
}
tonante27tonante27
The way the problem description was worded it seems like we have to also create an if statement to check if the Billing Postal Code was valid (i.e.not empty)  as well as checking the Match field. So I still got the problem wrong by using something vey close to the solution that HK2SFDC provided. t was not until I removed the check for Null Billing Postal Code was my solution accepted.
MAYANK PANDEY 28MAYANK PANDEY 28
I am getting error that :::: "We updated an account that had 'Match_Billing_Address__c' set to true. We expected the trigger to fire, but it didn’t. Make sure the trigger fires if 'Match_Billing_Address__c' is true.".
kindly help me with this.
Prashant TembharePrashant Tembhare
I also get the same things in That (Create Apex Trigger trailhead assessment ) but not solve yet......I trying too many attempts as of now still same error occurs.
 -----> We updated an account that had 'Match_Billing_Address__c' set to false. We expected the Apex trigger not to fire, but it did. Make sure the Apex trigger fires only if 'Match_Billing_Address__c' is true.

If Anyone has done this Please How to solve it.
JGDevJGDev
I was getting this error because the test record did not have a value in the AccountNumber field which caused the insert to fail.  I added one, and it passed the check.

trigger AccountAddressTrigger on Account (before insert, before update) {
    for (Account a : Trigger.new) {
        a.AccountNumber = '12345678';
        if (a.Match_Billing_Address__c == true) {
                a.ShippingPostalCode = a.BillingPostalCode;
        }
    }
}
October ZhuOctober Zhu
JGDev is right. And when I tested trigger by inserting, it has required Name and AccoountNumber. But it didn't pass when I added two of fields. It has passed with only AccountNumber added. It's weird ~ hhh
YiYong HuangYiYong Huang
Try doing the challenge in another Org that does not have any triggers. I  used a different trailhead with no Apex triggers to pass this challenge.  The setup and code were identical.  There may be something else causing the check to fail. 
theAntonymtheAntonym
Thanks @YiYong Huang. Switching org has solved my issue. I later realized that I already had another trigger on account from previoud trailhead.
 
Deividas Kandrotas 9Deividas Kandrotas 9

for some reason i had to remove {} after IF statement...

 

trigger AccountAddressTrigger on Account (before insert, before update) {
    for(account add: Trigger.new){
        if(add.Match_billing_address__c == True)
        add.ShippingPostalCode = add.BillingPostalCode;
            
    }
        

}

tonante27tonante27
Im surprised that you can’t have a 1-line assignment inside of a compound IF statement using {} . Usually this works. Supposed you then re-add the {} and underneath the 1st assignment statement , you add a print statement so that you can truly have a compound statement with 2 lines of code within the {}.
Abhishek Sharma 527Abhishek Sharma 527
if there are multiple trigger created in one object, this might also be reason for this error because it randomly execute any trigger available on object.
for me, it was fixed by making other triggers inactive and only this one as active.
meghanadh Gmeghanadh G
I've found the reason for the error. It's all about two reasons as 

Reason 1: threre is no record already existed in the field so its been showing like empty and stopping the trigger to set the value. 
Reason 2: if there already another account object trigger on stand it hard to execute the same trigger at a time. 


I've used the following code to add a value to the  field :

 trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account acc:Trigger.new)
    {
        acc.AccountNumber = '1234567';
        if(acc.Match_Billing_Address__c == true)
            acc.ShippingPostalCode = acc.BillingPostalCode;
    }

}



and i've tried the challenge with another playground of different org account . So it got triggered successfullyand completed my challenge