+ Start a Discussion
Diane Roberts 3Diane Roberts 3 

select from where structure

I'm sure that this is something very simple that I'm missing in my SOQL structure. My current code is:
public class NewActionListController {
    
public List<ACT_Action__c> getnewActions() { 
        List<ACT_Action__c> results = Database.query(
        'SELECT ID, Name FROM ACT_Action__c'
            'WHERE username=:UserInfo.getUserName()');
    return results;
}
}

I am getting an error that says the following:
Extra ')', at 'WHERE username=:UserInfo.getUserName()'

Can someone help? Thanks!
PawanKumarPawanKumar
Please try below.

public List<ACT_Action__c> getnewActions() { 
        String currentUserName = UserInfo.getUserName();
        List<ACT_Action__c> results = Database.query('SELECT ID, Name FROM ACT_Action__c  WHERE username=:currentUserName');
    return results;
}
}

Please mark it best if it helps you. Thanks.
Raj VakatiRaj Vakati
You need to move UserInfo.getUserName() out side of String 
 
public List<ACT_Action__c> getnewActions() { 
        List<ACT_Action__c> results = Database.query('SELECT ID, Name FROM ACT_Action__c WHERE username=:'+UserInfo.getUserName());
    return results;
}
}

 
Raj VakatiRaj Vakati
public List<ACT_Action__c> getnewActions() { 
        List<ACT_Action__c> results = Database.query('SELECT ID, Name FROM ACT_Action__c WHERE username='+UserInfo.getUserName());
    return results;
}
}
 
Akshay_DhimanAkshay_Dhiman
Hi Diane Roberts 3,

Some modification is needed as i shown below in code. check it out. It helpfull for you.


public class NewActionListController {
    
public List<ACT_Action__c> getnewActions() { 
        List<ACT_Action__c> results = Database.query('SELECT ID, Name FROM ACT_Action__c WHERE username = UserInfo.getUserName()');
        return results;
}
}
Please mark it best if it helps you. 

Thanks.