You need to sign in to do that
Don't have an account?
(Should Be An Easy Answer) Trigger Syntax Error
I am getting an error saying "Variable myAccount does not exist". Thanks for any help
trigger trig_BatchLoadDaily on Account (before insert)
{
for(Account myAccount : trigger.new)
{
//Person
if (myAccount.payout__Tax_Id_Type__c == 'S')
{
myAccount.FirstName = myAccount.Payout__Client_First_Name__c;
myAccount.LastName = myAccount.payout__Client_Last_Name__c;
//Update Person Account fields
myAccount.PersonMailingCity = myAccount.BillingCity;
myAccount.PersonMailingStateProv = myAccount.BillingState;
myAccount.PersonMailingStreet = myAccount.BillingStreet;
myAccount.PersonMailingZip = myAccount.BillingPostalCode;
}
}
Update myAccount;
}
"update myAccount" is outside of the for loop where it is declared. You're doing a before insert trigger, so an update statement isn't necessary. Just remove that line.
kirkevonphilly is correct use this code:
trigger trig_BatchLoadDaily on Account (before insert)
{
for(Account myAccount : trigger.new)
{
//Person
if (myAccount.payout__Tax_Id_Type__c == 'S')
{
myAccount.FirstName = myAccount.Payout__Client_First_Name__c;
myAccount.LastName = myAccount.payout__Client_Last_Name__c;
//Update Person Account fields
myAccount.PersonMailingCity = myAccount.BillingCity;
myAccount.PersonMailingStateProv = myAccount.BillingState;
myAccount.PersonMailingStreet = myAccount.BillingStreet;
myAccount.PersonMailingZip = myAccount.BillingPostalCode;
}
}
}