Activity Forums Salesforce® Discussions Test Database.query

  • Gourav

    Member
    June 13, 2016 at 2:46 pm

    You cannot query fields that are not existent in your org. First you'd have to create it either manually or using the api. Anyway in your test class you also need to create the records you want to test the query on. So you'd have something like:

    List<Account> acclist = new List<Account>();

    for(Integer i=0 ;i<200;i++){
    Account a = new Account(Name='test'+i, customfield__c='abcd');
    acclist.add(a);
    }

    insert acclist;
    List<Account> accList = Database.query('select Name,customfield__C
    from Account');
    System.debug(accList);

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos