salesforce

How to query more than 200 field; Salesforce SOQL Fields


I am facing an issue using Salesforce API. While querying I am getting the following exception: "The SOQL FIELDS function must have a LIMIT of at most 200". Now, I understand SF expects a max of 200 only. So, I wanted to ask how can I query when the results are more than 200?

I can only use REST API to query, but if there is another option, then please let me know and I will try to add it in my code.

Thanks in Advance


Solution

  • Try this it is Helpful:

    // Get the Map of Schema of Account SObject
    Map<String, Schema.SObjectField> fieldMap = Account.sObjectType.getDescribe().fields.getMap();        
    
    // Get all of the fields on the object
    Set<String> setFieldNames = fieldMap.keySet();
    list<String> lstFieldNames = new List<String>(setFieldNames);
             
    // Dynamic Query String.
    List<Account> lstAccounts = Database.query('SELECT ' + String.join(lstFieldNames, ',') + ' FROM Account');
    
    system.debug('lstAccounts'+lstAccounts);