function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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


 
Sippy yowtherSippy yowther
Finally Solved this!!! below is my code

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

https://youtu.be/sqIkewmXOZk
After you have created this trigger make sure to follow along with this tutorial, you can skip to the part where he creates the code. To test your trigger go into Saleforce classic and create a new Account record, titled whatever and make sure the match billing address is checked. Fill in the shipping address and billing address and make sure they match (you can use a seudo adress or your own).
Last step (VERY IMPORTANT) to be able to create your new account record and test the trigger to pass the test you MUST go to your AddRelatedRecord Trigger and deactivate it because that trigger is ran when creating the record, otherwise you will get an error, after you finished that you can then succesfully complete the trailhead! Hoped it helps!!!
Pooja RautPooja Raut
Thanks @Sippy yowther. It finally got triggered successfully.
 
chinmaya sahoochinmaya sahoo
I am using the below code and getting issue and came here to check if i have done wrong. seems others suggested same code but still unable to find the reason behind the error in trailhead and not getting the task completed. any help is appciated.

trigger AccountAddressTrigger on Account (before insert,before update) 
{
    //Condition: Match Billing Address is true
    //Operation: set the Shipping Postal Code to match the Billing Postal Code
    for (Account a:trigger.new)
    {
        if(a.Match_Billing_Address__c==true && a.BillingPostalCode != null) 
        {
            a.ShippingPostalCode=a.BillingPostalCode;
        }
     }
}
Issue i am facing is: 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.
Payal .Payal .
I was facing the same issue as there was other triggers on same Account object. I made other triggers inactive and AddressTrigger as active, then it worked fine and I was able to submit my answer. Please try this once.
Try using other org where you don't have any trigger on Account object. It will work.


If you liked my answer and it solved your issue, please mark it best answer.
Thanks,
Payal