Concepts or coding lessons of Salesforce that you can implement easily

Select * from X on apex (SOQL) in Salesforce

public static SObject[] selectAll(String objName,  String additionalFilters){
        
        //get object fields
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe()
                               .get(objName).getDescribe().fields.getMap().keySet());
        String fields = String.join(fieldList,',');
        
        return (SObject[])Database.query(
          'SELECT '+fields+' FROM '+objName+ ' '+additionalFilters
        );
    } 
System.debug( Helper.selectAll('Account', 'Order by CreatedDate Limit 10')); 


Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

loading...

No comments:

Post a Comment