function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShaikAShaikA 

Compile Error: Initial term of field expression must be a concrete SObject: List<Test__c>

Hi,

Please help me to solve below error:

Error: Compile Error: Initial term of field expression must be a concrete SObject: List<Test__c>

Class:
public PageReference login() {
    list<Test__c> userList=[select id from Test__c where name=:Name AND Password__c=:password];
    system.debug('userList>>>' +userList);
    PageReference Page = new PageReference('/' +userList.id);
    Page.setRedirect(true);
    return Page;
    }

Regards,
Anand
 
AnjithKumarAnjithKumar
Hello Anand,

The query will return list but you are using "list.Id ". Following is the update code
public PageReference login() {
    list<Test__c> userList=[select id from Test__c where name=:Name AND Password__c=:password];
    system.debug('userList>>>' +userList);
    PageReference Page = new PageReference('/' +userList[0].id);
    Page.setRedirect(true);
    return Page;
    }

Hope it helps you.

Thanks,
Anjith
Adam OlshanskyAdam Olshansky
Alternatively, you could also do it this way if you know there is just going to be one entry returned in the SOQL query.
 
public PageReference login() {
    Test__c user=[select id from Test__c where name=:Name AND Password__c=:password LIMIT 1];
    system.debug('user>>>' +user);
    PageReference Page = new PageReference('/' +user.id);
    Page.setRedirect(true);
    return Page;
}