+ Start a Discussion

query the records from different objects?

i have an objects Like A,A1,A2........and so on.(No Relation Ship Between Objects).

Now i want to  get id,name fields objects where object name like '%A%'.(get all records where object name contains A)
how can i please tell me.
Have you heard about SOSL ? they are for the same purpose, you can try to read more about them here http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_sosl.htm
i have little idea about sosl.(to get records from different objects at a time we use sosl) . 
Shyam BhundiaShyam Bhundia

The from clause in a query must be concrete (i.e you cannot do From %A%).

If you can give a bit more context on what you are trying achieve, we may be able to suggest another approach.
my context is simple that is i have objects like A,A1.....
i want to query the records in batch class from all objects where object name contains A .then i will pass that list to execute method
if any one help for this must be appreciated.
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)

You can use SOSL as mentioned by Avidev. It is not possible to query like 'select id from %A%' in salesforce.
Other approach is to query as list<sObject> where you can dynamically pass object name one at a time.

public list<sObject> fetchReferenceData(String objectName) {
     String query = 'SELECT id, Name FROM '+objectName+' LIMIT 1000' ;
     list<sObject> sobjectList = Database.query(query);
     return sObjectList;

then how can i get list of objects where object Name Like 'A'
public class TestObject {
   Public string ObjectSelected{get;set;}
    Public Map<String, Schema.SObjectType> AllObjmap;
    Public TestObject(){
        AllObjmap = New Map<String, Schema.SObjectType>();
        AllObjmap = Schema.getGlobalDescribe();
        System.debug('******All object Names :'+ AllObjmap.keyset());
    public void testrecords()
         List<selectoption> objList = new List<selectoption>();
         List<String> testSobj=new List<String>();
         list<sObject> sobjectList=new list<sObject>();
         list<sObject> sobjectList1=new list<sObject>();
        for(string s:AllObjmap.keyset()){
            if(s.startsWith('test')&&s.endsWith('__c') ) {
                objList.add(new selectoption(s,s));
        for(selectoption test:objList)
        system.debug('33333333'+test.getLabel() );
        for(String s:testSobj)
             String query = 'SELECT id FROM '+s+' Where Name LIKE\'%test%\' LIMIT 1000' ;
             sobjectList = Database.query(query);
              for(Sobject s1:sobjectList)

in Page:
<apex:page controller="TestObject" action="{!testrecords}">

like this will get records.