• Katherine Tucker 7
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Please help! I am having trouble with the appex trigger challenge 1/2.  I think I know how to do the logic, I am just forgetting how to create a checkbox on here.  Thanks!
Please help! I am having trouble with the appex trigger challenge 1/2.  I think I know how to do the logic, I am just forgetting how to create a checkbox on here.  Thanks!
Hi All,

Below are the requirements to complete Challenge

The Account object will need a new custom checkbox that should have the Field Label 'Match Billing Address' and Field Name of 'Match_Billing_Address'. The resulting API Name should be 'Match_Billing_Address__c'.
With 'AccountAddressTrigger' active, if an Account has a Billing Postal Code and 'Match_Billing_Address__c' is true, the record should have the Shipping Postal Code set to match on insert or update.


I have created new custom Checkbox(MatchBillingAddress) and Below is my trigger:

trigger AccountAddressTrigger on Account (before update,before insert)
{
   List<Account> list1=[SELECT Id,Match_Billing_Address__c,ShippingPostalCode,BillingPostalCode from Account];
  for(Integer i=0;i<list1.size();i++)
   {
    if(list1[i].Match_Billing_Address__c=true && list1[i].BillingPostalCode!=NULL)
    {
    list1[i].ShippingPostalCode=list1[i].BillingPostalCode;
    update list1[i];
    }
   }
  }

I got Error like : Executing the trigger did not work as expected.

Can anyone please help me to achieve this. Thanks