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
SFDC16SFDC16 

How to use where clause for string variable in soql?

Hello,
 I am not able to fetch the dashboard name based on the string variable.

Below highlighted code is not working. 

  List<User> userList=[Select id,BMCServiceDesk__Account_ID__c, BMCServiceDesk__Account__c  from user where id=:userInfo.getUserId()];
  System.debug('userList-------->'+userList); // return value
 
  List<String> userAccount=new List<String>();
   for(User u:userList)
   {
       userAccount.add(u.BMCServiceDesk__Account__c);
       
   }
  
    System.debug('User Account------->'+userAccount);
     String sData = String.valueof(userAccount);
    System.debug('String----->'+sData);//return Values
    List<Dashboard> dash=[Select id,title From Dashboard where title=:sData]; 
    if(dash.size()>0)
    System.debug('Dashboard Name------>'+dash);//return null    List<Dashboard> sobjList = Database.query('Select id,title From  Dashboard where title IN:userAccount');
    if(sobjList.size()>0)
    System.debug('Dashboard---------------->'+sobjList);   //return null
    

          
 
Raj VakatiRaj Vakati
Change it as below 
 
List<User> userList=[Select id,BMCServiceDesk__Account_ID__c, BMCServiceDesk__Account__c  from user where id=:userInfo.getUserId()];
  System.debug('userList-------->'+userList); // return value
 
  List<String> userAccount=new List<String>();
   for(User u:userList)
   {
       userAccount.add(u.BMCServiceDesk__Account__c);
       
   }
  
    List<Dashboard> dash=[Select id,title From Dashboard where title IN :userAccount]; 
    if(dash.size()>0)
    System.debug('Dashboard Name------>'+dash);//return null    List<Dashboard> sobjList = Database.query('Select id,title From  Dashboard where title IN:userAccount');

 
SFDC16SFDC16
still, it's not working. log 22:19:40:030 USER_DEBUG [15]|DEBUG|----------->() 22:19:40:024 USER_DEBUG [13]|DEBUG|Dashboard Name------>()
Raj VakatiRaj Vakati
Can you check two thinks .. 
  1. What is the value in BMCServiceDesk__Account__c
  2. What this SOQL returning Select id,title From Dashboard 
SFDC16SFDC16
1. What is the value in BMCServiceDesk__Account__c------------>Account Name (String) 2. What this SOQL returning Select id,title From Dashboard -----------> Dashboard title(String) Example : Account Name: SWD Pvt Ltd. Dashboard title: SWD Pvt Ltd.