String acName ='Blue Moon Hotel'; List<Account> acList = [SELECT Id, Name FROM Account WHERE name =: acName]; if(acList.size()==0){ Account ac = new Account(); ac.Name=acName; } insert ac;