Skip to content

Instantly share code, notes, and snippets.

@lukethacoder
lukethacoder / set-of-ids-from-list-of-objects.cls
Last active January 17, 2024 20:48
APEX: Get a Set<Id> of Id's from a List<SObject> of Objects
// Query list of Accounts
List<Account> accounts = [
SELECT
Id, Name
FROM
Account
];
// get Set of Ids of the Object
Set<Id> ids = new Set<Id>(new Map<Id, Account>(accounts).keySet());
@mhamzas
mhamzas / BatchApexErrorTrigger.trg
Created August 30, 2019 15:11
Modify an existing batch Apex job to raise BatchApexErrorEvents
trigger BatchApexErrorTrigger on BatchApexErrorEvent (after insert) {
List<BatchLeadConvertErrors__c> List_LeadConvertError = new List<BatchLeadConvertErrors__c>();
for(BatchApexErrorEvent event: trigger.new){
BatchLeadConvertErrors__c lcerror = new BatchLeadConvertErrors__c();
lcerror.AsyncApexJobId__c = event.AsyncApexJobId;
lcerror.Records__c = event.JobScope;
lcerror.StackTrace__c = event.StackTrace;
List_LeadConvertError.add(lcerror);
@douglascayers
douglascayers / query-by-id
Last active December 2, 2020 14:05
Example SOQL to query for all fields using Dyanamic Query in Apex
ID recordId = '5001a00000CgCE2';
DescribeSObjectResult describeResult = recordId.getSObjectType().getDescribe();
List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() );
String query =
' SELECT ' +
String.join( fieldNames, ',' ) +
' FROM ' +
@MrCsabaToth
MrCsabaToth / yadcf filter reset button original
Created January 17, 2015 05:55
yadcf filter reset button original and with bootstrap
<div id="yadcf-filter-wrapper--reportTable-6" class="yadcf-filter-wrapper">
<input id="yadcf-filter--reportTable-6" class="yadcf-filter" type="text" .../>
<input id="yadcf-filter--reportTable-6-reset" class="yadcf-filter-reset-button" type="button".../>
</div>
@martyychang
martyychang / S1Reporting.cls
Last active May 26, 2018 15:41
Demonstration of using Apex as a conduit for accessing the Salesforce1 Reporting REST API in Lightning
public class S1Reporting {
/*
* @see Salesforce1 Reporting REST API Developer Guide
*/
public class GetAnalyticsReportsResponseBody {
@AuraEnabled
public String name;
@divideby0
divideby0 / first_name.synonyms.txt
Last active May 20, 2016 18:46
First Name Synonyms for Elasticsearch / Solr / Lucene (generated from Freebase name variations)
aadu => ado
aaliyah => aleaseya, alea, aliya, aliyah, allyiah, alia, aleeya, aleah
aaron => arron, aron, ahron
aarti => arti
aayesha => ayesha, ayasha, ayse, ayisha
aba => abod, abony, abos
abagail => abbe, abby, abbie, abilio, gail, abbey, abigale, abigail, abihail, abigayle
abba => abbot, abbott, absa, abbe
abbe => abba, abbot, abbott, absa, abbey, abby, abigail, abihail, abagail, abigayle, abilio, gail, abigale, abbie
abbey => abbe, abilio, gail, abigale, abigail, abihail, abagail, abigayle, abbie, abby
@CreativeNotice
CreativeNotice / test-query-to-csv-func.cfm
Created May 23, 2012 13:58
CF method to convert a query to csv output.
<cfscript>
/**
* queryToCsv
* Allows us to pass in a query object and returns that data as a CSV.
* This is a refactor of Ben Nadel's method, http://www.bennadel.com/blog/1239-Updated-Converting-A-ColdFusion-Query-To-CSV-Using-QueryToCSV-.htm
* @param {Query} q {required} The cf query object to convert. E.g. pass in: qry.execute().getResult();
* @param {Boolean} hr {required} True if we should include a header row in our CSV, defaults to TRUE
* @param {String} d {required} Delimiter to use in CSV, defaults to a comma (,)
* @return {String} CSV content
*/
@smrchy
smrchy / example.cfm
Created September 16, 2011 19:55
queryToObject
<!--- suppose your query you did with cfquery is stored in the variable myQuery --->
<script>
var q = #SerialzeJSON(myQuery,true)#;
// make an easy to use object
var newQuery = queryToObject(q);
console.log(newQuery);
</script>
@clintongormley
clintongormley / gist:1089201
Created July 18, 2011 11:05
Name query filtered by birthday and geo distance
curl -XGET 'http://127.0.0.1:9200/test/member/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"filter" : {
"and" : [
{
"term" : {
"birthday" : "1970-10-24"
}
@clintongormley
clintongormley / gist:1089180
Created July 18, 2011 10:58
Example name query
curl -XGET 'http://127.0.0.1:9200/test/member/_search?pretty=1' -d '
{
"query" : {
"bool" : {
"should" : [
{
"text" : {
"first_name" : {
"boost" : 1,
"query" : "rob smith"