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
moverdorfmoverdorf 

(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;    
    
}

kirkevonphillykirkevonphilly

"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.

 

 

Rahul_sgRahul_sg

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;
    }    
 
}
    
}