Skip to content

Instantly share code, notes, and snippets.

@arufian
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save arufian/6395de554f93a8adb9c5 to your computer and use it in GitHub Desktop.

Select an option

Save arufian/6395de554f93a8adb9c5 to your computer and use it in GitHub Desktop.

Revisions

  1. arufian revised this gist Dec 26, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions withMethod.cls
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    * Bring Select * into SOQL
    * @param tableName tableName
    * @param whereCondition cover WHERE, GROUP BY, ORDER BY, AND LIMIT
    * @param isCustomFieldOnly set true if only to get custom fields
    * @return String string concat query
    **/
    public static String getSelectAllQuery(String tableName, String whereCondition, Boolean isCustomFieldOnly) {
  2. arufian revised this gist Dec 26, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions withMethod.cls
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    /**
    * SOQLの"Select *"のクエリStringを取得する
    * @param tableName テーブル名
    * @param whereCondition クエリのWHEREやGROUPBYやORDERBYやLIMITなど
    * @return SOQLクエリString
    * Bring Select * into SOQL
    * @param tableName tableName
    * @param whereCondition cover WHERE, GROUP BY, ORDER BY, AND LIMIT
    * @return String string concat query
    **/
    public static String getSelectAllQuery(String tableName, String whereCondition, Boolean isCustomFieldOnly) {
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ;
  3. arufian revised this gist Dec 26, 2014. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions withMethod.cls
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * SOQLの"Select *"のクエリStringを取得する
    * @param tableName テーブル名
    * @param whereCondition クエリのWHEREやGROUPBYやORDERBYやLIMITなど
    * @return SOQLクエリString
    **/
    public static String getSelectAllQuery(String tableName, String whereCondition, Boolean isCustomFieldOnly) {
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ;
    Schema.SObjectType s = m.get(tableName) ;
    Schema.DescribeSObjectResult r = s.getDescribe() ;
    Map<String, Schema.SObjectField> fields = r.fields.getMap() ;
    string soql = '';
    for (String fieldName : fields.keyset()) {
    if (soql != '') {
    soql += ', ';
    }
    if(isCustomFieldOnly && (fieldName.indexOf('__c') < 0)) {
    continue;
    }
    soql += fieldName;
    }
    soql = 'SELECT ' + soql + ' FROM ' + tableName + ' ' + whereCondition;
    return soql;
    }
  4. arufian revised this gist Oct 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.cls
    Original file line number Diff line number Diff line change
    @@ -12,5 +12,5 @@ for (String fieldName : fields.keyset()) {
    }
    soql = 'SELECT ' + soql + ' FROM ' + table;
    System.debug(soql);
    List<InternalReport__c> acs = Database.query(soql);
    List<TableName> acs = Database.query(soql);
    System.debug(acs.get(0));
  5. arufian renamed this gist Oct 16, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. arufian created this gist Oct 16, 2014.
    16 changes: 16 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    String table = 'TableName'; // with __c if use Custom Object
    Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ;
    Schema.SObjectType s = m.get(table) ;
    Schema.DescribeSObjectResult r = s.getDescribe() ;
    Map<String, Schema.SObjectField> fields = r.fields.getMap() ;
    string soql = '';
    for (String fieldName : fields.keyset()) {
    if (soql != '') {
    soql += ', ';
    }
    soql += fieldName;
    }
    soql = 'SELECT ' + soql + ' FROM ' + table;
    System.debug(soql);
    List<InternalReport__c> acs = Database.query(soql);
    System.debug(acs.get(0));