+ Start a Discussion
VempallyVempally 

Given Accountid, SOQL not retrieving Contacts

Hi Folks,

Plz check with the following code of a class for custom button on Account..

I need to get the contacts when account id is passed through the custom button to a global class.
 
Global class AccountContactFieldUpdate{

    public static Id accountid;
    public static List<Account> lst_acc;
   
   
    webservice static void contactFieldsConcat(Id accid){
        
        accountid = accid;
              
        string query ='select id, name, (select id, name from Contacts) from account where id =: accountid';
        lst_acc = Database.query(query);
        system.debug(lst_acc);
}

}

 
Mudasir WaniMudasir Wani
Hello Vempally,

Modify your query as
 
string query ='select id, name, (select id, name from Contacts) from account where id =: '+accountid;

Thanks,
Mudasir 

 
Mudasir WaniMudasir Wani

Hello Vempally,

if this solves your issue.
Please mark this as solved.

Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.