You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
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: Please mark this as solved if it's resolved.
Best Regards,
Nagendra.
All Answers
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: Please mark this as solved if it's resolved.
Best Regards,
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
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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);
}
}
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);
}
}
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);
}
}
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);
}
}