Skip to content

A handy library to simplify filtering sObject lists in Salesforce

License

Notifications You must be signed in to change notification settings

mritzi/FilterRecords

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FilterRecords

Deploy to Salesforce

Why FilterRecords

  • While developing custom feature in Salesforce, often times we need to write repetitive code to filter list based on certain filter criteria. We have to write for loop to iterate over list of sObjects & get records relevant to the use case, and it's repeated at several places in the org.
  • Similar situation comes up regularly while handling records in Trigger context, where Trigger.new & Trigger.old gives up upto 200 records of all record types. However, we only need to run a use case on records of a certain record type.

This library aims to remove that re-work and make the org's code size smaller.

List<Account> ecom_account_list =
    new FilterRecords(Trigger.new)
    .byFieldValueEq('Industry', 'E-Commerce')
    .getList();

Easy, isn't it!!!

Features

  • Allows functional programming inspired method chaining while using object oriented programming paradigm of Apex

  • It improves developer efficiency, as developer can quickly get relevant data and pass it to relevant apex method/class for further processing.

  • It's designed to be easily readable for devs & admins alike.

Examples

Filter records by RecordType

This will return a list of all Accounts where RecordTypeId = '1234abcd..AAC'

List<Account> supplier_account_list =
    new FilterRecords(Trigger.new)
    .byRecordTypeIdEq('RecordTypeId', '1234abcd..AAC')
    .getList();

Filter records by Picklist value

This will return a list of all Accounts where Indusry = 'E-Commerce'

List<Account> account_list = <collection of all types of accounts>
List<Account> ecom_account_list =
    new FilterRecords(account_list)
    .byFieldValueEq('Industry', 'E-Commerce')
    .getList();

Filter records by negative filter condition

This will return a list of all Accounts where Indusry != 'E-Commerce'

List<Account> account_list = <collection of all types of accounts>
List<Account> filtered_account_list =
    new FilterRecords(account_list)
    .byFieldValueNotEq('Industry', 'E-Commerce')
    .getList();

Filter records in Trigger context where field values have changed

This will return a list where City changed from Miami to Texas

List<Account> filtered_account_list =
    new FilterRecords(Trigger.new, Trigger.oldMap)
    .byOldValueEq('ShippingCity', 'Miami')
    .byNewValueEq('ShippingCity', 'Miami')
    .getList();

More changes under development, stay connected!!

About

A handy library to simplify filtering sObject lists in Salesforce

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages