Generic sObject means, it can be of any persisted SFDC objects type. For ex: Vehicle is generic type and Car, Motor Bike all are concrete types of Vehicle. In SFDC,sObject is generic and Account, Opportunity, CustomObject__c are its concrete type. Generic sObject abstracts the actual representation of any object assigned to it. sObject is the name of the generic abstract type that can be used to represent any persisted object type.
i am going to create one search button ...have one text box ...inside the text box i will give some text when i click search btn textbox text matching all object will be displayed ...so i need some details about sobjects where its stored and how we retrive info about sobject through soql quries??
Please check the below code we should use predefined methods which are provided in schema class and also check the code to retrieve object through SOQL Queries.
public class schemademo2 {
public string selectedobject{get;set;}
public List<selectoption> objname{get;set;}
public string selectedfield{get;set;}
public List<selectoption> fldname{get;set;}
public string selectedvalue{get;set;}
public List<selectoption> valname{get;set;}
public boolean pb1{get;set;}
Map<string,schema.sobjectType> mobj = schema.getGlobalDescribe();
public schemademo2(){
objname = new List<selectoption>();
Map<string,schema.sobjectType> mobj = schema.getGlobalDescribe();
List<string> entities = new List<string>(mobj.keyset());
entities.sort();
objname.add(new selectoption('---Select Object---','----Select Object---'));
for(string f:entities){
if (f.contains('__c'))
// if (!f.contains('__c'))
objname.add(new selectoption(f,f));
}
}
public PageReference searchFields() {
Map<string,sobjectField> mfld = mobj.get(selectedobject).getDescribe().fields.getMap();
fldname = new List<selectoption>();
List<string> fldentities = new List<string>(mfld.keyset());
pb1=true;
fldentities.sort();
fldname.add(new selectoption('---Select Field---','----Select Field---'));
for(string sf:fldentities){
fldname.add(new selectoption(sf,sf));
}
return null;
}
public PageReference searchValues() {
string dquery = 'select '+selectedfield+' from '+selectedobject;
List<Sobject> vals = Database.query(dquery);
valname= new List<selectoption>();
for(sobject val:vals){
if(val.get(selectedfield)!=null)
valname.add(new selectoption(string.valueof(val.get(selectedfield)),string.valueof(val.get(selectedfield))));
}
return null;
}
}
I hope it will be helpful.
Please mark it as solved.so they removed from unanswered questions.and more appear as the proper solution to similar kind of issue. Best Regards RahulKumar
Generic sObject means, it can be of any persisted SFDC objects type.
For ex: Vehicle is generic type and Car, Motor Bike all are concrete types of Vehicle.
In SFDC,sObject is generic and Account, Opportunity, CustomObject__c are its concrete type.
Generic sObject abstracts the actual representation of any object assigned to it. sObject is the name of the generic abstract type that can be used to represent any persisted object type.
please check the below link for further references in trailhead module which on sobject.
https://trailhead.salesforce.com/apex_database/apex_database_sobjects
Hope this helps you!Please let me know If you need further help.
Please mark it as best answer if it resolved your problem.
Best Regards
RahulKumar
hi Rahul kumar
i am going to create one search button ...have one text box ...inside the text box i will give some text when i click search btn textbox text matching all object will be displayed ...so i need some details about sobjects where its stored and how we retrive info about sobject through soql quries??
For The Above requirement, you should need to use "Schema Class" Check the below document which salesforce has provided in apex developer guide.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_schema.htm
Please check the below code we should use predefined methods which are provided in schema class and also check the code to retrieve object through SOQL Queries.
VisualForce Page: ApexClass:
I hope it will be helpful.
Please mark it as solved.so they removed from unanswered questions.and more appear as the proper solution to similar kind of issue.
Best Regards
RahulKumar