You need to sign in to do that
Don't have an account?

query the records from different objects?
Hi,
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.
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.
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.
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
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.
e.g.
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)
{
testSobj.add(test.getLabel());
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);
system.debug('ssssssssss'+sobjectList);
for(Sobject s1:sobjectList)
{
sobjectList1.add(s1);
}
}
system.debug('ssssssssss'+sobjectList1);
}
}
in Page:
<apex:page controller="TestObject" action="{!testrecords}">
</apex:page>
like this will get records.