0

I am getting error message 'Variable does not exist:' for 3 updateDA. variables. What is the cause? Thank you!

else if (Trigger.isUpdate) {        
    for (Account accNew : Trigger.new) {
        List<Dealer__c> updateDA = 
            [Select Account_Name__c from Dealer__c where Account_Name__c = :accNew.Name];
        updateDA.Account_Name__c             = accNew.Name;
        updateDA.Shipping_City__c            = accNew.ShippingCity;
        updateDA.Shipping_State_Province__c  = accNew.ShippingState;
       }

1 Answer 1

1

updateDA is typed as a List<Dealer__c>. The type that has fields Account_Name__c etc. is Dealer__c, which is the type of the elements of this list. The list itself does not have these properties.

You would need to iterate over this list in another for loop to access those properties on each element.

But... there are much bigger problems here.

  1. This trigger is not bulkified. You will consume SOQL limits very quickly. You need to bulkify the trigger using the principles taught in this Trailhead module.
  2. The Account Name field is not unique. If your org has multiple Accounts with the same name, you may see strange behaviors.
  3. You don't need a trigger here at all. You need a lookup or master-detail relationship between Dealer and Account, and three formula fields to cascade values down from the parent. Or better still, just use a Lightning Related Record component on your Record Page for the Dealer object to show the parent data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .