Skip to content

Instantly share code, notes, and snippets.

View emoran's full-sized avatar
:octocat:
Developing

Edgar Moran emoran

:octocat:
Developing
View GitHub Profile
@emoran
emoran / munitReadFile
Created September 25, 2023 20:38
MUnit : Payload value from resources folder
output application/java --- readUrl('classpath://sample_data/gsheet_date.json')
@emoran
emoran / flattenScatterGather.dw
Created September 22, 2023 19:16
Flatten payload after Scatter Gather DW 2.0
%dw 2.0
output application/java
---
flatten(valuesOf(payload) map ((item, index) -> item.*payload))
public class RestServiceConsumerDW {
public static void consume(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://techcrunch.com/wp-json/wp/v2/posts?per_page=2&context=embed');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if(response.getStatusCode() == 200) {
@emoran
emoran / anagramGrouped.apex
Created October 23, 2022 16:27
Group Anagram words in Salesforce Apex.
List<String> listWords = new List<String>{'bored','robed','cat','act','tac','eme'};
Map<String,List<String>> mapWords = new Map<String,List<String>>();
for(String word: listWords){
List<String> splittedWord = word.split('');
splittedWord.sort();
String wordNew = '';
for(String newWord:splittedWord){
@emoran
emoran / getTopManager
Created October 17, 2022 17:24
get Top Manager in Salesforce Apex.
public Employee__c getTopManager(String employeeId){
Boolean topLevel = false;
Employee__c top_employee = new Employee__c();
while(!topLevel){
Employee__c employee = [Select Id,Name,Manager__c from Employee__c where Id =:employeeId limit 1];
@emoran
emoran / simple_Trigger_Handler.cls
Created March 20, 2022 23:21
trigger Handler basic for salesforce
public class SObject {
public static void run(){
switch on Trigger.operationType {
when BEFORE_INSERT {
//Perform Before Insert logic'
System.debug('BEFORE INSERT FIRED');'
} when BEFORE_UPDATE {
//perform Before Update logic
} when BEFORE_DELETE {
//perform Before Delete logic
@emoran
emoran / CheckRecursive.cls
Created March 14, 2022 18:35
Check recursive apex in Salesforce.
public Class CheckRecursive {
private static boolean run = true;
public static boolean runOnce(){
if (run) {
run = false;
return true;
}
else{
@emoran
emoran / AccountApprovalClone.page
Created March 11, 2022 15:15
Approval History Clone for Salesforce Account. Allows to show the Approval History for an Object.
<apex:page standardController="Account" extensions="AccountApprovalCloneExtension" >
<apex:pageBlock title="Approval History Clone">
<table class="list" border="0" cellspacing="0">
<tbody>
<tr class="headerRow">
<th class="actionColumn" scope="col">Action</th>
<th scope="col" class=" zen-deemphasize">Date</th>
<th scope="col" class=" zen-deemphasize">Status</th>
<!--<th scope="col" class=" zen-deemphasize">Assigned To</th>-->
@emoran
emoran / Walmart.cls
Created March 10, 2022 16:04
Sample apex code to make a request to Walmart API service and generate the signature for the WM_SEC.AUTH_SIGNATURE header from Salesforce
/**
* Edgar Moran
* March 2022
*/
public with sharing class Walmart {
@InvocableMethod(label='Send Message')
public static List<String> sendMessage(List<String> message) {
String consumerId ='CONSUMER_ID';
@emoran
emoran / WalmartHeaderSignature.java
Created March 10, 2022 11:58
Walmart Header Signature snippet. Allows to generate the WM_SEC.AUTH_SIGNATURE header to authenticate in Walmart API services.
import org.apache.commons.codec.binary.Base64;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
public class WalmartHeaderSignature {
private static String consumerId = "CONSUMER_ID"; // Trimmed for security reason
private static String baseUrl = "URL";