• ishwar panjari 10
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I have to check that the record exist in view List or not. So for this i wrote the following code for checking that records exist in list view or not.

List<sObject> sobjectList=[select Name,Id from TestObj where Id='a0gG000000B8W2HIAV']; 
String query = 'Select Name from TestObj LIMIT 1'; 
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(Database.getQueryLocator(query)); 
List<System.Selectoption> ListViewList=ssc.getListViewOptions(); 
set<SObject> testset=new set<SObject>(); 
List<sObject> listChildObject=null; 
for (System.Selectoption selopn : ssc.getListViewOptions()){ 
    string viewid,viewlabel; 
    viewid=selopn.getValue();
    viewlabel=selopn.getlabel(); 
    ssc.setSelected(sobjectList); 
    ssc.setFilterId(viewid); 
    testset.addAll((List<sObject>)ssc.getSelected()); 

System.debug('testset-'+testset);

This above code is returning the testset is empty. Event this record exist in the list view of this user. But if i change the sequence like following:
ssc.setFilterId(viewid);
ssc.setSelected(sobjectList);
Now it will set records in each list view even though that records is not exist for this list view.
Actually i want to check that specific records exist in list view or not. I do not know which is best way to do in salesforce without iterating all records and checking.
Can anyone tell me what is the error in the following code, I'm getting the above error:
Public class AccountUtils
{
    List<Account> accountsByState (String Str)
    {
        List<Account> accList = new List<Account>();
        accList=[SELECT ID,name from Account where BillingState=:Str];
        return accList;
    }
}