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
POOJA DESHPANDEPOOJA DESHPANDE 

Apex Triggers Error

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 insert,  before update) {

       for(Account a:Trigger.New){
            If (a.Match_Billing_Address__c && a.BillingPostalCode!= Null) {
                a.BillingPostalCode= a.ShippingPostalCode ;  
        } 
    }



Im getting the following error message :

Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddRelatedRecord: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Discount_Percent__c]: [Discount_Percent__c] Trigger.AddRelatedRecord: line 23, column 1: []

I had same errors on both my demo triggers as well.Please drop your suggestions.:)

SalesFORCE_enFORCErSalesFORCE_enFORCEr
The error is self-explanatory. Discount_Percent__c is a required field so it cannot be blank
Amit Chaudhary 8Amit Chaudhary 8
Hi Pooja,

It look like you created one field "Discount_Percent__c" as required field. Please edit the field and uncheck the required checkbox and try your challenge again.

Let us know of this will help you
Ajay K DubediAjay K Dubedi
Hi Pooja,
Try this :
trigger AccountAddressTrigger on Account (before insert,before update) {
List<Account> accs= new List<Account>();
For (Account acc : Trigger.new)
{
if(acc.Match_Billing_Address__C == TRUE)
{
acc.ShippingPostalCode = acc.BillingPostalCode;
accs.add(acc);
}
}
update accs;
}
Regards,
Ajay
 
POOJA DESHPANDEPOOJA DESHPANDE
Hey Guys,
Thank you for your suggestions,I have completed the challenge.
manu manu 23manu manu 23
There might be the issue in your code line 23; where you might have queried without mentioning the required field Discount_Percent__c and trying to access it in somepart of the code