Skip to content

Instantly share code, notes, and snippets.

View scolladon's full-sized avatar

Sebastien scolladon

View GitHub Profile
@scolladon
scolladon / XMLParser.cls
Created August 2, 2024 07:48
apex iterative XML parser
public class XMLParser {
public Object parse(Dom.XMLNode root) {
return new XMLNodeProcessor(root).process();
}
private class XMLNodeProcessor {
private final Dom.XMLNode root;
private final Map<Dom.XMLNode, Object> resultMap;
private final Map<Dom.XMLNode, Map<String, Object>> pendingNodes;
private final Map<Dom.XMLNode, Map<String, Integer>> nodeNameCountMap;
/**
* Split a string of any size, while avoiding the dreaded 'Regex too complicated'
* error, which the String.split(String) method causes on some large inputs.
*
* Note that this method does not avoid other errors, such as those related to
* excess heap size or CPU time.
*/
List<String> safeSplit(String inStr, String delim)
{
Integer regexFindLimit = 100;
@scolladon
scolladon / ApexID15to18.cls
Last active September 23, 2016 18:40
Apex ID 15 to 18
public static string generate18CharId(final string id){
final String abecedair = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345';
if (String.isBlank(id) || (id.length() != 15 && id.length() != 18)) {
return null;
}
if (id.length() == 18) {
return id;
}
string suffix = '';
for (integer i = 0; i < 3; i++) {
@scolladon
scolladon / RecordTypeHandler.cls
Created May 16, 2016 16:20
Apex RecordType Handler
public with sharing class RecordTypeHandler {
// Build a local cache so that we don't request this multiple times
private static Map<Schema.SObjectType,Map<String,Id>> rtypesCache;
static {
rtypesCache = new Map<Schema.SObjectType,Map<String,Id>>();
}
// Returns a map of active, user-available RecordType IDs for a given SObjectType,
@scolladon
scolladon / UserRoleInserter.cls
Last active May 10, 2016 21:00
UserRoleInserter Salesforce
public class UserRoleInserter{
final private Map<String,String> roleNamePerParentRoleName;
public UserRoleInserter(){
this.roleNamePerParentRoleName = new Map<String,String>();
}
public void PutUserRoleHierarchy(final String aUserRole, final String aParentUserRole) {
this.roleNamePerParentRoleName.put(aUserRole,aParentUserRole);
}