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

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


trigger DuplicatePrevention on Account (before insert) {

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

  • 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 '18 at 13:38

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)
List<Account> duplicates = [SELECT Name FROM Account WHERE Name IN :names];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.