function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Linda KalasnikovaLinda Kalasnikova 

Apply Selector Layer Principles in Apex

I wrote AccountsSelector class but I still can't pass the challange.
Where could I be wrong?
Code:

public with sharing class AccountsSelector extends fflib_SObjectSelector{
    
   public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.Id,
            Account.Description,
            Account.Name,
            Account.AnnualRevenue };
    }
    
    List<Account> selectById(Set<ID> idSet) {
      return (List<Account>) selectSObjectsById(idSet);
    }

     public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

}
 
Best Answer chosen by Linda Kalasnikova
NagendraNagendra (Salesforce Developers) 
Hi Linda,

May I request you please post the error message which you are getting so that it results in easy troubleshooting and a better understanding of the issue which helps accordingly to resolve the issue.

Please try with below code once and let me know if you have any success:
public class AccountSelector extends fflib_SObjectSelector {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description
            Account.Name,
            Account.AnnualRevenue };
    }

    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

    public List<Account> selectById(Set<ID> idSet) {
        return (List<Account>) selectSObjectsById(idSet);
    }
}
Please mark this as solved if it's resolved.

Best Regards,
Nagendra.

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Linda,

May I request you please post the error message which you are getting so that it results in easy troubleshooting and a better understanding of the issue which helps accordingly to resolve the issue.

Please try with below code once and let me know if you have any success:
public class AccountSelector extends fflib_SObjectSelector {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description
            Account.Name,
            Account.AnnualRevenue };
    }

    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

    public List<Account> selectById(Set<ID> idSet) {
        return (List<Account>) selectSObjectsById(idSet);
    }
}
Please mark this as solved if it's resolved.

Best Regards,
Nagendra.
This was selected as the best answer
Fayazuddin Mohammed 9Fayazuddin Mohammed 9
Hi Nagendra, 
The above code you have posted does not work. Firstly the class name is "AccountsSelector" not "AccountSelector", secondly a comma is missing in line 06 after Account.Description,  I rectified the above two typos and created the class as below, still I could not pass the challenge. Can you please check as to why am getting this error :
"Challenge Not yet complete... here's what's wrong: 
The AccountsSelector did not work as expected. At least one of the fields was not returned correctly using the AccountsSelector().selectById method."

My code below-
----------------------------------------------------------------------------------------------------------------------------------------------------------------
public class AccountsSelector extends fflib_SObjectSelector {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description,
            Account.Name,
            Account.AnnualRevenue };
    }

    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

    public List<Account> selectById(Set<ID> idSet) {
        List <Account> acclist = new List <Account>();
        acclist =(List<Account>) selectSObjectsById(idSet);
        //System.debug('accountlist' +acclist);
        return acclist;
        //return (List<Account>) selectSObjectsById(idSet);
        //System.debug('account');
        //AccountsSelector().selectById
    }
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Javier Peña LucenaJavier Peña Lucena
any clue?
azaz siddiqui 10azaz siddiqui 10
Following code works for me.

public class AccountsSelector extends fflib_SObjectSelector {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description,
            Account.Name,
            Account.AnnualRevenue };
    }

    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

    public List<Account> selectById(Set<ID> idSet) {
        return (List<Account>) selectSObjectsById(idSet);
    }
}
Ravi ModiRavi Modi
Below Code works flaw less for me
public class AccountsSelector extends fflib_SObjectSelector  {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description,
            Account.Name,
            Account.AnnualRevenue };
    }
    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }
    public List<Account> selectById(Set<ID> idSet){
        return (List<Account>) selectSObjectsById(idSet);
    }
}
Igor SemenkoIgor Semenko

I have removed Account.AnnualRevenue field and it was enough.

public class AccountsSelector extends fflib_SObjectSelector  {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
                Account.ID,
                Account.Description,
                Account.Name };
    }
    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }
    public List<Account> selectById(Set<ID> idSet){
        return (List<Account>) selectSObjectsById(idSet);
    }
}

Kamesh SinghKamesh Singh
Here is the workigng code for this challenge.

public class AccountsSelector extends fflib_SObjectSelector {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description,
            Account.Name,
            Account.AnnualRevenue };
    }

    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

    public List<Account> selectById(Set<ID> idSet) {
        return (List<Account>) selectSObjectsById(idSet);
    }
}
Renu Soni 1Renu Soni 1

Working code, please make sure to deactivate your AccountsTrigger before check your challenge. 

public class AccountsSelector extends fflib_SObjectSelector {

    public List<Schema.SObjectField> getSObjectFieldList() {
        return new List<Schema.SObjectField> {
            Account.ID,
            Account.Description,
            Account.Name,
            Account.AnnualRevenue };
    }

    public Schema.SObjectType getSObjectType() {
        return Account.sObjectType;
    }

    public List<Account> selectById(Set<ID> idSet) {
        return (List<Account>) selectSObjectsById(idSet);
    }
}