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
mukesh gupta 8mukesh gupta 8 

Trailhead trigger check chellange button

Hi Expert,

I am doing trailhead trigger and using code this

trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.new){
       If (a.Test_LightingCo__Match_Billing_Address__c == true && a.Test_LightingCo__BillingPostalCode__c != Null) {
            a.Test_LightingCo__ShippingPostalCode__c = a.Test_LightingCo__BillingPostalCode__c ;
        }   
    } 
}

but code is working fine and Account object records update perfect. but if i clicks on "check chellange" button on trailhead trigger page then  , i got an error 
User-added image

Please suggest

Thanks
Mukesh
Best Answer chosen by mukesh gupta 8
sfdcMonkey.comsfdcMonkey.com
yes ShippingPostalCode and BillingPostalCode these are Compound Address Fields on account object
when you create new account record you can see it on screen
User-added image

go to below link for understand compund address fields
https://releasenotes.docs.salesforce.com/en-us/spring14/release-notes/rn_schema_compound_fields_address.htm
and below link for account object all api standard fields
here you can find both fields in the list
https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_account.htm
i hop it helps you
Please mark it best answer if it helps you so it make proper solution for others
Thanks
 

All Answers

EldonEldon
Hi Mukesh 

The name of the custom field should be 'Match_Billing_Address__c' . Edit it . Then try the below trigger.
 
trigger AccountAddressTrigger on Account (before insert,before update) {

  
    for(Account acc :Trigger.New){
     
        if(acc.Match_Billing_Address__c && acc.BillingPostalCode != NULL){
            acc.ShippingPostalCode = acc.BillingPostalCode;
        }
    }
}

Regards
mukesh gupta 8mukesh gupta 8
I am using "Test_LightingCo__Match_Billing_Address__c" here "Test_LightingCo__" is namespace prefix. how i can edit this.

Please suggest.

Thanks
Mukesh
 
sfdcMonkey.comsfdcMonkey.com
hi mukesh
you can create another developer fresh org for doing this trailhead challange.
and use above code provided by Eldon
Thanks
 
EldonEldon
As Piyush said you will have to use a new org for doing your trailhead challenges if you have set a namespace.

Also you are using Test_LightingCo__BillingPostalCode__c instead of the std field BillingPostalCode . Change that also.
mukesh gupta 8mukesh gupta 8
Hi All,

I have create new DE for this issue but now have a same problem ""

User-added image
trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.new){
       If (a.Match_Billing_Address__c == true && a.BillingPostalCode__c != Null) {
            a.ShippingPostalCode__c = a.BillingPostalCode__c ;
        }   
    } 
}

Acount record is update perfectly. But check chellange button show the error.

Please suggest.

Thanks
Mukesh 
sfdcMonkey.comsfdcMonkey.com
hi Mukesh
try this code
trigger AccountAddressTrigger on Account (before insert ,before update) {
    for(Account a: trigger.new){
        if(a.Match_Billing_Address__c && a.BillingPostalCode  != NULL)
            a.ShippingPostalCode = a.BillingPostalCode ;
    }
    
}
Thanks
let me inform if it helps you
 
mukesh gupta 8mukesh gupta 8
Hi Piyush,

Here "BillingPostalCode"  and "ShippingPostalCode" is a custom object, so API name will be "BillingPostalCode__c"  and "ShippingPostalCode__c" without "__c" suffix , how we cam menage.

Thanks
Mukesh
sfdcMonkey.comsfdcMonkey.com
here BillingPostalCode and ShippingPostalCode are standard fields of account so we have not need to add __c  after standard fields
and Match_Billing_Address__c is a boolean custom feld on account
i hop it helps you
thanks
EldonEldon
Hi Mukesh,

Use the code i gave above. Challenge is to create one custom field Match_Billing_Address__c use the std fields BillingPostalCode   and ShippingPostalCode . For std field you dont have to append __c. The code is given below again
 
trigger AccountAddressTrigger on Account (before insert,before update) {

  
    for(Account acc :Trigger.New){
     
        if(acc.Match_Billing_Address__c && acc.BillingPostalCode != NULL){
            acc.ShippingPostalCode = acc.BillingPostalCode;
        }
    }
}



Regards
mukesh gupta 8mukesh gupta 8
Hi All, 

But "ShippingPostalCode"  and "BillingPostalCode" is not available in Account object list.

User-added image

How i can get these standard fields in my Account object.

Thanks
Mukesh
sfdcMonkey.comsfdcMonkey.com
yes ShippingPostalCode and BillingPostalCode these are Compound Address Fields on account object
when you create new account record you can see it on screen
User-added image

go to below link for understand compund address fields
https://releasenotes.docs.salesforce.com/en-us/spring14/release-notes/rn_schema_compound_fields_address.htm
and below link for account object all api standard fields
here you can find both fields in the list
https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_account.htm
i hop it helps you
Please mark it best answer if it helps you so it make proper solution for others
Thanks
 
This was selected as the best answer
EldonEldon
Hi Mukesh,

Those fields come under Shippingaddress and billingaddress. Please try the above code let us know the result.

Regards