Activity Forums Salesforce® Discussions How to create a universal search box in Salesforce?

  • Mohit

    Member
    September 27, 2016 at 1:36 pm

    Hi Tanu,

    This is a code for the universal search for searching any kind of object and custom setting in your salesforce org it will give all value of all field available on the salesforce object:-

    String s1 ='';
    Integer i =0;
    String[] types = new String[]{'Account'};//sobject name
    Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
    for(Schema.DescribeSobjectResult res : results){
    for(Schema.SObjectField s : res.fields.getMap().values())
    {
    i=i+1;
    if(res.fields.getMap().size()>i){
    s1 = s1+s+',';
    }else
    s1=s1+s;
    }
    }
    sObject a = Database.query('Select '+s1+' From '+types[0]+' limit 1');
    System.debug('@@'+a);

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos