Hello All, I have just started using Trialhead and got stuck at this module.. Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field..please help me in this..
I created checkbox with field label 'Match Billing Address' and it is checked after that created trigger named as 'AccountAddressTrigger' with following code:
trigger AccountAddressTrigger on Account (before insert, before update) { for(Account a : Trigger.New) { if(a.BillingPostalCode!=null && a.Match_Billing_Address__c==true){ a.ShippingPostalCode = a.BillingPostalCode; } } } and saving it. I am just clicking check challenge button and it is giving me error as:
Challenge Not yet complete... here's what's wrong: No Apex trigger named 'AccountAddressTrigger' was found please tell me what wrong i am doing here? Thanks..
It seems the Trailhead connected to your org has not even the Trigger. It means either you have created the Trigger in a different org ? I would say refresh the Trailhead page and then at the bottom where it says 'Launch your dev org' and make sure it is same where to made the code changes.
Hi Yogesh, I think you didn't created a Apex Trigger, you had created a Class Apex so you must delete this one and creating a new one with the Apex Trigger : File -> New -> Apex Trigger
Ashish....I have a doubt so would you help me understand this....
When i saw this challenge, I was confused as I did not see any postal code fields on my account object and I just went on googling for answer. I got your answer and that worked perfectly fine after creating the checkbox property. But I still am unsure that how the postal code came into picture where it shows nowhere on object manager for Account object.
Then I saw billing and shipping address fields with type as Address, and I thought if you create address type field then it will give you the postal code. And I just went on trying to create one more address type field but I did not find that data type when I clicked on "New" for fields...How did this happen?????
or is it like, Account is an starndard object so these fields just came up with it... (however i did see the postal codes when I tried to creat new account object, under address field section)
Please use this.
All Answers
for(Account a : Trigger.New) {
if(a.BillingPostalCode!=null && a.Match_Billing_Address__c==true){
a.ShippingPostalCode = a.BillingPostalCode;
}
}
}
Please use this.
I created checkbox with field label 'Match Billing Address' and it is checked after that created trigger named as 'AccountAddressTrigger' with following code:
trigger AccountAddressTrigger on Account (before insert, before update) {
for(Account a : Trigger.New) {
if(a.BillingPostalCode!=null && a.Match_Billing_Address__c==true){
a.ShippingPostalCode = a.BillingPostalCode;
}
}
}
and saving it. I am just clicking check challenge button and it is giving me error as:
Challenge Not yet complete... here's what's wrong:
No Apex trigger named 'AccountAddressTrigger' was found
please tell me what wrong i am doing here?
Thanks..
I think you didn't created a Apex Trigger, you had created a Class Apex so you must delete this one and creating a new one with the Apex Trigger :
File -> New -> Apex Trigger
Can you please mark by response as best answer since it helped you resolving the error ? thanks.
Hi Abderrahman,
I folllowed the same procedure but i created trigger in different org. Now it is working fine.
Thanks
When i saw this challenge, I was confused as I did not see any postal code fields on my account object and I just went on googling for answer. I got your answer and that worked perfectly fine after creating the checkbox property. But I still am unsure that how the postal code came into picture where it shows nowhere on object manager for Account object.
Then I saw billing and shipping address fields with type as Address, and I thought if you create address type field then it will give you the postal code. And I just went on trying to create one more address type field but I did not find that data type when I clicked on "New" for fields...How did this happen?????
or is it like, Account is an starndard object so these fields just came up with it... (however i did see the postal codes when I tried to creat new account object, under address field section)
Help me to understand how this happened !!!!!