You need to sign in to do that
Don't have an account?
Manish Anand 10
Trailhead challenge: Apex with Triggers
Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.
I am writing following code:-
trigger AccountAddressTrigger on Account (before insert,before update)
{
List <Account> act= [Select id,name from Account where BillingPostalCode != NULL and Match_Billing_Address__c='True' ];
For(Account a:act)
{
a.ShippingPostalCode=BillingPostalCode;
}
}
It gives error-Varibale Doesn't exist:BillingPostalCode.
What I am missing here?
Note- In the challenge, it's given, ShippingPostalCode and BillingPostalCode are the API name,
I am writing following code:-
trigger AccountAddressTrigger on Account (before insert,before update)
{
List <Account> act= [Select id,name from Account where BillingPostalCode != NULL and Match_Billing_Address__c='True' ];
For(Account a:act)
{
a.ShippingPostalCode=BillingPostalCode;
}
}
It gives error-Varibale Doesn't exist:BillingPostalCode.
What I am missing here?
Note- In the challenge, it's given, ShippingPostalCode and BillingPostalCode are the API name,
Please find the below code:
Here you need to replace the if condition with your Custom Field API name along with the proper condition, if it is checkbox type then just changing the name will be enough. If it is other Data Type then have to change the condition using == operator.
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
Please find the below code:
Here you need to replace the if condition with your Custom Field API name along with the proper condition, if it is checkbox type then just changing the name will be enough. If it is other Data Type then have to change the condition using == operator.
Please do let me know if it helps you.
Regards,
Mahesh
for(Account a : trigger.new)
{
If (a.Match_Billing_Address__c == true && a.BillingPostalCode!=Null) {
a.ShippingPostalCode = a.BillingPostalCode;
}
}
}