New to apex to please bear with me. I'm using database.query for a SOQL statement from a Custom Setting. I'm then trying to retrieve data from that Custom Setting, but it seems everything is an sObject[]. In the scenario below, SearchFields__c is a single String (e.g. Name), but it won't let me assign it to a String. Any help would be appreciated. Thanks in advance.

Sample Code

public YAHS_PRT_Table_Component__c tableComponent {get;set;}

public String searchField { get; set; }

public List<String> Buttons { get; set; }

public GenericPaginationComponentContrl(){
    tableComponent = [SELECT Name, IsActionColumnEnabled__c, SearchFields__c, SOQLQuery__c, 
ActionButtons__c, Fields__c FROM YAHS_PRT_Table_Component__c WHERE Name = :recordName]; // Works
    sObjLst = database.query(tableComponent.SOQLQuery__c); // Works

    searchField = database.query(tableComponent.SearchFields__c); // Illegal assignment from List<SObject> to String
    Buttons = database.query(tableComponent.ActionButtons__c.split(',')); // Doesn't work either

1 Answer 1


Your OP is somewhat unclear, but if the types are correct, then you simply need to pull the data from the fields, with no need for any additional queries.

searchField = tableComponent.SearchFields__c;
buttons = String.isBlank(tableComponent.ActionButtons__c) ?
    new List<String>() : tableComponent.ActionButtons__c.split(',');
  • Thank you very much. I think I misunderstood the purpose of database.query when I used it for sObjLst . I thought it was relevant to pulling and assignment for all my variables.
    – Kevin
    Jun 28, 2016 at 1:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .