You need to sign in to do that
Don't have an account?

List has no rows for assignment to SObject
May be my brain is just not working this morning, but I am not sure how to do what I am looking at doing.
for(Account_To_Import__c ai : [select id, name from Account_To_Import__c where Census_Import__c=:ApexPages.currentPage().getParameters().get('id')]){ account a = [select id, name from account where ssn__c = :ai.ssn__c]; if(a.id != ''){
What I am trying to do is take one piece of information Account_to_import__c and compare it to the actual account. The first line " for(Account_To_Import__c ai :...." gets the original data. Then for each object in that list I want to see if an account exists with the same SSN. if it does I run one bit of code if it does not I run another bit of code. The issue I am having is that when I run it if the account does not exist I get the error that the list has no rows for assignment. How should I have this built? Thanks for the help.
You may need to change the map to <String, Account_To_Import> depending on what type ssn__c is, but try this:
All Answers
You should assign the Account a to List<Account> accs, because assigning a query result to just one object causes the error when the result is empty. Also, you shouldn't put any SOQL queries inside any for loops ..
I can move the initail query out of the for loop easy enough, but how would I move the second one out?
How do I do the account soql outside of the for loop and how would I add it to a list? everytime I try a list instead of an individual account I get the error that the Initial term of field expression must be a concrete SObject:
You may need to change the map to <String, Account_To_Import> depending on what type ssn__c is, but try this: