0
list<Book__c> b = [select id ,account__c,Account1__c from Book__c ];
system.debug(b);

list<account> acc = new list<account>([select id,name from account where name in :b.account__c]);
system.debug(acc);

Line: 4, Column: 83
Initial term of field expression must be a concrete SObject: List

  • account__C contain account name – pravin May 22 '17 at 12:31
1

In your code b is a list of objects. This would compile:

where name in :b[0].account__c

but is probably not what you want as it is only then looking at the first item.

Perhaps you want something like this is what you need:

// Get the set of accounts first
Set<String> accounts = new Set<String>();
for (Book__c b : [select account__c from Book__c where account__c != null]) {
    accounts.add(b.account__c);
}

list<account> acc = [select id,name from account where name in :accounts];
system.debug(acc);

If Book__c.Account__c is an Id, you should be matching the Id field in your second query.

  • this code work for me.. Book__c.Account__c is not id it is name of account. – pravin May 24 '17 at 4:47
  • can you guide me more.. now I have taken lookup field of account on book__c now what i want whatever name in account__c that account should append to that lookup field how shall i do that.. i written code which now work for me see below – pravin May 24 '17 at 4:50
3

IN used to compare any field with List of available values. From the error message it is quite clear that b.account__c is not of type list. Refer below example:

List<String> accountNames = new List<String>();
accountNames.add('Account1');
accountNames.add('Account2');

list<account> acc = new list<account>([select id,name from account where name in :accountNames]);
2

Salesforce can give some pretty unhelpful errors at time. This one isn't the clearest, but if you pause for a moment and take a good look at it, it starts to make sense.

Besides the line number, this is the most important part of the error:

must be a concrete SObject: List

So somewhere, on that line, Salesforce is expecting an SObject, but you're giving Salesforce a List.

We know it's on line 4. A SOQL query returns a List, and you're storing the result in a List, so there's no problem there (you actually don't need to use the List constructor here, or do any casting for that matter, but that's beside the point).

The only other place on line 4 that can be causing your error is this:

where name in :b.account__c

If we take a look at the lines above, b is defined as a List<Book__c>. This fits the error that you're getting. b is a List, but using dot notation to reference a field is something that needs to be done on an SObject.

Your list stored in b does contain Book__c records (Book__c is also an SObject), so to be able to access the Account__c field, you need access to one of the actual records in your list (for which you'd use [<some integer>] or .get(<some integer>)).

At the very least (and I do emphasize that this is the very least you could do), to make this work, you'd do the following

// I've omitted the rest of the query for brevity
// Notice how we use square brackets before trying to reference the field
// Apex is 0-indexed, meaning the first item in the array is at index 0 (instead of 1)
where name in :b[0].account__c];

Keith C's answer goes over better practices for accomplishing what you're looking to do.

  • yes it work properly but it work for only particular index record. – pravin May 24 '17 at 4:45
0
list<Book__c> b = [select id,name,account__c,Account1__c from Book__c ];
system.debug(b);

list<string> s = new list<string>();
Map<Id,account> newmap = new Map<Id,account>();    

for(book__c b1 : b){
    s.add(b1.account__c);
}
system.debug(s);

list<account> acc =[select id,name from account where name IN :s];

for(account a : acc){
    newmap.put(a.id,a);

}

system.debug(newmap);

for(account a1 : acc){
       for(book__c b1 : b){ 
               if(b1.Account1__c != null){}
                    if(b1.account__c == a1.name){

                        b1.Account1__c = a1.id;
                    }
               }
        }   
}
update b; 
system.debug(b);

how to solve it by using map..

  • This should be a new question not an answer. In the question give the type of the fields account___c and Account1__c and explain what you want to happen and what is happening. The normal way to relate two objects is using the Id value; if you also want a separate name field you can use a formula for that, but most Salesforce user interface will automatically present the name in place of the Id value so a separate name field isn't needed. – Keith C May 24 '17 at 8:29
  • account___c is text field which contains account name... I have exitsing data now I want to take lookup field Account1__c on book__c and fill this by account whos name in account__C... so by above program it solve but As I am new in apex i not able to solve it using map – pravin May 25 '17 at 10:25
  • if you want more information let me know – pravin May 25 '17 at 10:25
-3

Where Condition Should be Return Name But It is Compared By Ids. You Should be Compare with Id's. Like [select id,name from Account where id : b.account__c];

  • 1
    Does not address the issue. Will throw same error – Eric May 22 '17 at 13:08
  • account__C is text field which contains account name. and now i am taking lookup field of account on book__C. now i want who name in account__c field that account should reflect in lookup field – pravin May 25 '17 at 10:28

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.