0

Why am I getting this error? How can I fix it?

Error: Compile Error: Variable does not exist: Name at line 8 column 87

Code:

trigger DuplicatePrevention on Account (before insert) {

        List<Account> acclist = new List<Account>();
        for(Account a:Trigger.new)
        {
                 acclist.add(a);
        }
        List<Account> olist = [SELECT Id,Name FROM Account WHERE Name IN 
        :acclist.Name];


}
1
  • If you also created this account, please contact the community team to get them merged. It is especially important you do not maintain multiple accounts if one of yours got question-banned, as that is then seen as trying to circumvent the system, which is abusive behavior.
    – Adrian Larson
    Feb 14, 2018 at 13:38

1 Answer 1

4

Your acclist variable is a List<Account>, which has no Name property. If you want to collect the Name values, use a Set<String>:

Set<String> names = new Set<String>();
for (Account record : trigger.new)
{
    names.add(record.Name);
}
List<Account> duplicates = [SELECT Name FROM Account WHERE Name IN :names];

You must log in to answer this question.

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