+ Start a Discussion
SunnyShinySunnyShiny 

List.add = initial term of field expression must be a concrete SObject: LIST<Object__c>

Hello

I try to add values in a list already populated... is it possible ?

 

 List<Object__c> p = [Select id,RecordTypeId
            from Object__c
            where PrincipalClient__c IN :ClientIds];

 

        p.add = [Select id,RecordTypeId
                 From Object__c p
                 where id in (select Object__c from RelatedClient__c where Related_ClientField__c IN :ClientIds)  
                 ];

 

BUTI've got an error > Initial term of field expression must be a concrete SObject

 

Thing is my PrincipalClient__c field is a lookup in ma Object table.

And Related_clientField__c field is a Master-Detail(Object) in the RelatedClient__c table.

 

 

I tried to do just one query like below but I've got an error because >>

 

        List<PatientProfile__c> p = [Select id,RecordTypeId
            from Object__c 
            where (PrincipalClient__c IN :ClientIds)
            OR (id in (select Object__c from RelatedClient__c where Related_ClientField__c IN :ClientIds) )]; 

 

 Semi join sub-selects are not allowed with the 'OR' operator

 

 

 Thanks for your help.

 

Best Answer chosen by Admin (Salesforce Developers) 
SunnyShinySunnyShiny

I've finally found that link which helped me >

http://boards.developerforce.com/t5/Apex-Code-Development/SOQL-How-to-query-with-multiple-sub-query/td-p/184241

 

list<ID> exclusion = new list<id>();
for(Account acc:[select ID from Account where Name like 'test%'])
{
exclusion.add(acc.id);
}

System.Debug(exclusion);

for(Account acc:[select ID from Account where Name like 'Acme%'])
{
exclusion.add(acc.id);
}

System.Debug(exclusion);

Account[] accs =  [select ID from Account where Id not in :exclusion];

System.Debug(accs);

All Answers

SunnyShinySunnyShiny

I've finally found that link which helped me >

http://boards.developerforce.com/t5/Apex-Code-Development/SOQL-How-to-query-with-multiple-sub-query/td-p/184241

 

list<ID> exclusion = new list<id>();
for(Account acc:[select ID from Account where Name like 'test%'])
{
exclusion.add(acc.id);
}

System.Debug(exclusion);

for(Account acc:[select ID from Account where Name like 'Acme%'])
{
exclusion.add(acc.id);
}

System.Debug(exclusion);

Account[] accs =  [select ID from Account where Id not in :exclusion];

System.Debug(accs);

This was selected as the best answer
Vinit_KumarVinit_Kumar

Try below it should work,

 

List<Object__c> p = [Select id,RecordTypeId
from Object__c
where PrincipalClient__c IN :ClientIds];

for( Object__c ob:[Select id,RecordTypeId
From Object__c p
where id in (select Object__c from RelatedClient__c where Related_ClientField__c IN :ClientIds)
];){

p.add(ob);
}