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
maninder singh 50maninder singh 50 

Apex Triggers Challenge

When attempting to create my Apex trigger for this Trailhead development exercise, I receive about 20 errors similar to Unexpected token '<'. , Unexpected token 'and'. etc.

trigger AccountAddressTrigger on Account (before insert, before update) {
  List<Account> acc = [Select id from account where Id in :trigger.new and BillingPostalCode!= null and Match_Billing_Address__c == true];
       for(Account a: acc)
    {
      a.ShippingPostalCode = a.BillingPostalCode;        
    }  
}

If i use below query there are no errors.
List<Account> acc = [Select id, Match_Billing_Address__c from account where Id in :trigger.new and BillingPostalCode!= null];

So, there is something wrong with the other Match_Billing_Address__c field and I validated that the API name is correct. I know there are other solutions available for same challenge but please help in debugging this.
 
Best Answer chosen by maninder singh 50
Jainam ContractorJainam Contractor
Hi Maninder,

It seems that the Field Match_Billing_Address__c is of type Checkbox. Is my Understanding correct..???

Also you need not put '==' in the SOQL query. It should be single '=' sign

So, if Match_Billing_Address__c is of type Checkbox, Update your SOQL as below:
 
List<Account> acc = [Select id from account where Id in :trigger.new and BillingPostalCode!= null and Match_Billing_Address__c = true];

Let me know if it helps. Mark this as the solution if it solved your purpose.

Let me know if you need any more assistance.

Thanks & Regards,
Jainam Contractor,
Salesforce Consultant,
Varasi LLC
www.varasi.com

All Answers

Jainam ContractorJainam Contractor
Hi Maninder,

It seems that the Field Match_Billing_Address__c is of type Checkbox. Is my Understanding correct..???

Also you need not put '==' in the SOQL query. It should be single '=' sign

So, if Match_Billing_Address__c is of type Checkbox, Update your SOQL as below:
 
List<Account> acc = [Select id from account where Id in :trigger.new and BillingPostalCode!= null and Match_Billing_Address__c = true];

Let me know if it helps. Mark this as the solution if it solved your purpose.

Let me know if you need any more assistance.

Thanks & Regards,
Jainam Contractor,
Salesforce Consultant,
Varasi LLC
www.varasi.com
This was selected as the best answer
Vinod ChoudharyVinod Choudhary
Hi Maninder,

try this:
 
trigger AccountAddressTrigger on Account (before insert) {

   
  List<Account> acc = [Select id,Match_Billing_Address__c from account where Id in :trigger.new];
     for(Account a: acc){
          If (a.Match_Billing_Address__c = true && a.BillingPostalCode!=Null) {
      			a.ShippingPostalCode = a.BillingPostalCode;    
          }
    }  
    
    

}
Hope this will help :)

Thanks
Vinod