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
Katherine Tucker 7Katherine Tucker 7 

How do you create the checkbox object for the apex trigger unit 1/2 challenge?

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!
Best Answer chosen by Katherine Tucker 7
pconpcon
What challenge are you refering to?  If you are looking to create a new Checkbox on an object, you can do that via the fields page under setup for that object.  If you are looking to copy the content of a checkbox field to a variable for later use then you'll want to use the Boolean object type.
 
Boolean checkboxValue = myObject.myCheckbox__c;

If you are trying to compare a checkbox field on a record you can do this
 
if (myObject.myCheckbox__c == true) {
    // More code
}

A small thing to note, Booleans do not quite act as expected if the feild value is null.  For more info, read this http://fourq.me/blog/what-the-hell-boolean-i-thought-i-knew-you/

All Answers

pconpcon
What challenge are you refering to?  If you are looking to create a new Checkbox on an object, you can do that via the fields page under setup for that object.  If you are looking to copy the content of a checkbox field to a variable for later use then you'll want to use the Boolean object type.
 
Boolean checkboxValue = myObject.myCheckbox__c;

If you are trying to compare a checkbox field on a record you can do this
 
if (myObject.myCheckbox__c == true) {
    // More code
}

A small thing to note, Booleans do not quite act as expected if the feild value is null.  For more info, read this http://fourq.me/blog/what-the-hell-boolean-i-thought-i-knew-you/
This was selected as the best answer
Katherine Tucker 7Katherine Tucker 7
This is the challenge:

For this challenge, you need to create a trigger that, before insert or update, checks for a checkbox, and if the checkbox field is true, sets the Shipping Postal Code (whose API name is ShippingPostalCode) to be the same as the Billing Postal Code (BillingPostalCode).The Apex trigger must be called 'AccountAddressTrigger'.
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.
monika shewalemonika shewale
first u need to create a Match_Billing_Address checkbox for account.
for that 
go to setup->custmize->accounts->field->Account Custom Fields & Relationships->checkbox-> label -> save
after that create a trigger.
trigger AccountAddressTrigger on Account (before insert, before update) {

      for(Account a : Trigger.new)
      {
          Boolean checkboxValue = a.Match_Billing_Address__c;
          if(a.Match_Billing_Address__c == true )
          {
              a.ShippingPostalCode = a.BillingPostalCode;
          }
      }
}
 

 
Tien Le 488Tien Le 488
Hello @monika shewal, thank you for the suggestion but I'm at a lost.  I'm in Setup and tried looking for Customize but not finding it.  Can you clarify this further?  Thanks in advance for your help.
User-added image
Tien Le 488Tien Le 488
User-added imageGoogled and found help/hint...
User-added image

and voila!