With the sponsorship of the phenomenal company Hoopla Software, I’ve put together a number of enhancements to the SOQLBuilder as included in Apex-lang, a community project headed by developer hero Richard Vanhook. For those who don’t know, SOQL Builder allows you to simply and reliably create queries like this:

new al.SoqlBuilder()
 .selectx('name')
 .fromx('Opportunity')
 .wherex(new al.FieldCondition('employees').lessThan(10))
 .toSoql();

I’ve added support for aggregate queries:

Count:

new al.SoqlBuilder()
 .selectCount('Id')
 .fromx('Opportunity')
 .toSoql();

Sum:

new al.SoqlBuilder()
 .selectSumx('Amount')
 .fromx('Opportunity')
 .toSoql();

Average:

new al.SoqlBuilder()
 .selectAveragex('Amount')
 .fromx('Opportunity')
 .toSoql();

Max:

new al.SoqlBuilder()
 .selectMaxx('Amount')
 .fromx('Opportunity')
 .toSoql();

Min:

new al.SoqlBuilder()
 .selectMinx('Amount')
 .fromx('Opportunity')
 .toSoql();

I’ve also added support for Group by:

new al.SoqlBuilder()
 .selectx('OwnerId')
 .fromx('Opportunity')
 .groupBy('OwnerId')
 .toSoql();

Get Apex-lang here.

Here’s a video showing the sort of things that are possible with this library:

Advertisement