Giter VIP home page Giter VIP logo

force.com-helper-classes's Introduction

Helper Classes for Force.com

I am building a collection of useful helper classes for Salesforce and Force.com.

Contributing

You should contribute...

  1. Fork this repo

  2. Add some awesomeness (either classes of your own or enhancements to existing classes)

  3. Submit pull request

  4. Enjoy

Helper Classes

Async.cls

The Async class aims to circumvent a limitation of asynchronous (@future) methods in Salesforce. The current @future implementation will only allow for primitives or collections of primitives to be passed into an @future method. The Async class uses native JSON serialization/deserialization to allow for passing an SObject, or List into an asynchronous method for DML operations. A helper method is also included for making the serialization processes simpler.

Usage:

List<Lead> leads = [SELECT Id, FirstName, LastName FROM Lead LIMIT 10];
  
for(Lead l : leads) {
  l.FirstName = 'Somethingelse';
}

// this will update asynchronously
Async.updateSObjects(Async.prepare(leads));

InvokeUpdateTriggerBatch.cls

I find myself needing to run mass-updates on records once I finish an "On Update" trigger. I created this simple utility batch class that runs an update on all records retrieved by a SOQL query string that is supplied as the classes only argument. There is a static method that will run this in one line.

Usage:

String batchId = InvokeUpdateTriggerBatch.invoke('SELECT Id FROM Lead');

StateFormatter.cls

I created this class to automatically format US State names and State Codes from raw user input. The result is better reporting and cleaner data. The class has a single static method called getState() that accepts a String as its argument. It returns a State object with the formal State Name and State Code as its properties. See the test method for usage examples.

Usage:

String myState = 'mich';

// This will return MI
myState = StateFormatter.getState(myState).statecode;

// This will return Michigan
myState = StateFormatter.getState(myState).statename;

SuperMap.cls

I created this class to help circumvent the 1000 element maximum in Map collections. It's not a wonderful solution, but until parameterization is allowed in Apex, this is a decent workaround.

Usage:

SuperMap mySuperMap = new SuperMap();

for(Integer i=1; i<=10000; i++) {
  mySuperMap.put(String.valueOf(i), 'value' + String.valueOf(i));
}

// remember to cast as the supermap stores generic objects
String val = (String) mySuperMap.get('10000');

Contributors

  • Kevin O'Hara
  • {{Your Name Here}}

force.com-helper-classes's People

Contributors

kevinohara80 avatar

Watchers

Clint Lee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.