Skip to content

Instantly share code, notes, and snippets.

@LokeshSagi
Last active March 28, 2020 12:46
Show Gist options
  • Save LokeshSagi/aece63540a2e05bc8dd41b63513cdb72 to your computer and use it in GitHub Desktop.
Save LokeshSagi/aece63540a2e05bc8dd41b63513cdb72 to your computer and use it in GitHub Desktop.
public without sharing class AccountSelector extends fflib_SObjectSelector {
// super(false, false, false) - Constructor
// 1st param -> includeFieldSetFields (Set to true if the Selector queries are to include Fieldset fields as well)
// 2nd param -> enforceCRUD (To enforce object level permissions)
// 3rd param -> enforceFLS (To enforece Field Level Security)
public AccountSelector() {
super(false, false, false);
}
// Define all the fields required
public List<Schema.SObjectField> getSObjectFieldList() {
return new List<Schema.SObjectField> {
Account.Name,
Account.Precinct__c,
Account.ShippingCity,
Account.Company_Name__c,
Account.Propritor_Name__c,
Account.ShippingAddress,
Account.ShippingStreet,
Account.ShippingCity,
Account.ShippingCountry,
Account.ShippingPostalCode,
Account.ShippingState,
Account.Phone,
Account.Mobile_Number__c,
Account.Email__c,
Account.ParentId,
Account.Federal_EIN__c,
Account.DBA_Business_Name__c,
Account.Corporate_Tax__c,
Account.Use_Tax__c,
Account.Withholding_Tax__c,
Account.IsPartner,
Account.Entity_Type__c,
Account.Is_Public_Trading_Company__c,
Account.NonProfitStatus__c,
Account.Is_Batched__c,
Account.OwnerId,
Account.Standing__c,
Account.Status__c,
Account.CBI__c,
Account.Parent.Entity_Type__c,
Account.KY_Site__c,
Account.Type
};
}
public Schema.SObjectType getSObjectType() {
return Account.sObjectType;
}
public List<Account> selectById(Set<ID> idSet) {
return (List<Account>) selectSObjectsById(idSet);
}
public List<Account> selectLocationsByParent(Set<Id> idSet) {
String quotaLicenseCode = 'LP';
String licenseStatus = 'Active';
List<String> statuses =
new List<String> {'Approved', 'Denied','Withdrawn', 'Inactive', 'Revoked', 'Rejected', 'Active', 'Migrated'};
List<String> quoteTypes = new List<String>();
quoteTypes.add('Transfer Alcohol');
quoteTypes.add('Private Event');
quoteTypes.add('Minor Premises');
quoteTypes.add('Free Sample');
quoteTypes.add('Renewal');
String family = 'Supplemental';
// Add all the select fields.
fflib_QueryFactory oQf = newQueryFactory(false)
.selectField(Account.Name)
.selectField(Account.ShippingCity)
.selectField(Account.Company_Name__c)
.selectField(Account.Propritor_Name__c)
.selectField(Account.ShippingAddress)
.selectField(Account.ShippingStreet)
.selectField(Account.ShippingCity)
.selectField(Account.ShippingCountry)
.selectField(Account.ShippingPostalCode)
.selectField(Account.ShippingState)
.selectField(Account.Phone)
.selectField(Account.Mobile_Number__c)
.selectField(Account.Email__c)
.selectField(Account.ParentId)
.selectField(Account.Federal_EIN__c)
.selectField(Account.DBA_Business_Name__c)
.selectField(Account.Corporate_Tax__c)
.selectField(Account.Use_Tax__c)
.selectField(Account.Withholding_Tax__c)
.selectField(Account.IsPartner)
.selectField(Account.Entity_Type__c)
.selectField(Account.Is_Public_Trading_Company__c)
.selectField(Account.NonProfitStatus__c)
.selectField(Account.Is_Batched__c)
.selectField(Account.OwnerId)
.selectField(Account.Business_Type__c)
.selectField(Account.Standing__c)
.selectField(Account.Status__c)
.selectField(Account.Acquired_by_other_business__c)
.selectField('Parent.Standing__c')
.selectField('Parent.Status__c')
.setCondition('ParentId IN :idSet AND Acquired_by_other_business__c=false');
// Add sub query. call getSobjectFieldList() to select all the fields from another selector class
oQF.subselectQuery('SBQQ__Quotes__r')
.selectFields(new QuoteSelector().getSobjectFieldList()).setCondition(
'SBQQ__Status__c NOT IN :statuses AND SBQQ__Type__c NOT IN:quoteTypes');
// Add another sub query. Add fields manually if all fields are not required.
oQf.subselectQuery('SBQQ__Subscriptions__r')
.selectField('SBQQ__Product__c.Name')
.selectField('SBQQ__Product__c.ProductCode')
.selectField(SBQQ__Subscription__c.Status__c)
.setCondition('SBQQ__Product__r.ProductCode =:quotaLicenseCode AND Status__c =:licenseStatus');
// Generate the query
return Database.query(oQf.toSOQL() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment