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 / gist:9073623
Created February 18, 2014 15:53
c# FTP Controller
using System.Diagnostics;
using System.Data;
using System.Collections;
using Microsoft.VisualBasic;
using System.Collections.Generic;
using System;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
@emoran
emoran / Salesforce Pricebook testMethod
Last active July 29, 2019 14:23
Salesforce TestMethod for PriceBook and PriceBookEntry
/**
* This class contains unit tests for validating the behavior of Apex classes
* and triggers.
*
* Unit tests are class methods that verify whether a particular piece
* of code is working properly. Unit test methods take no arguments,
* commit no data to the database, and are flagged with the testMethod
* keyword in the method definition.
*
* All test methods in an organization are executed whenever Apex code is deployed
global class CL_BATCH_update_Purchases implements Database.Batchable<sObject> {
public CL_BATCH_update_Purchases(){}
global Database.QueryLocator start(Database.BatchableContext BC){
String query='Select Id from SFDC_Purchase_Order__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<SFDC_Purchase_Order__c> scope){
global class CL_Schedulable_update_Purchases implements Schedulable {
global void execute(SchedulableContext SC){
CL_BATCH_update_Purchases batch_ordenes=new CL_BATCH_update_Purchases();
Database.executeBatch(batch_ordenes);
}
}
@emoran
emoran / gist:775c0c8371fa8c0029d6
Created May 6, 2014 14:54
Start and End Date of each Month (Force.com apex)
Date firstDayOfMonth = System.today().toStartOfMonth();
Date lastDayOfMonth = firstDayOfMonth.addDays(Date.daysInMonth(firstDayOfMonth.year(), firstDayOfMonth.month()) - 1);
public Class checkRecursive
{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}
else
{
function deleteAccent(str){
for (var i=0;i<str.length;i++){
//Change "á é í ó ú"
if (str.charAt(i)=="á") str = str.replace(/á/,"a");
if (str.charAt(i)=="é") str = str.replace(/é/,"e");
if (str.charAt(i)=="í") str = str.replace(/í/,"i");
if (str.charAt(i)=="ó") str = str.replace(/ó/,"o");
if (str.charAt(i)=="ú") str = str.replace(/ú/,"u");
}
return str;
@emoran
emoran / Show_formated_currency_Visualforce
Created June 21, 2014 15:04
It shows the formated currency in a visualforce page
<apex:outputText value="{0, number, ###,###,###,##0.00}">
<apex:param value="{!Opportunity.Amount}"/>
</apex:outputText>
@emoran
emoran / Weekday Count Formula
Created July 1, 2014 22:22
Weekday Count Formula
CASE(MOD( StartDate__c - DATE(1985,6,24),7),
0 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,4,4,5,5,5,6,5,1),
1 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,4,4,4,5,4,6,5,1),
2 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,3,4,3,5,4,6,5,1),
3 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,2,3,2,4,3,5,4,6,5,1),
4 , CASE( MOD( EndDate__c - StartDate__c ,7),1,1,2,1,3,2,4,3,5,4,6,5,1),
5 , CASE( MOD( EndDate__c - StartDate__c ,7),1,0,2,1,3,2,4,3,5,4,6,5,0),
6 , CASE( MOD( EndDate__c - StartDate__c ,7),1,1,2,2,3,3,4,4,5,5,6,5,0),
999)
@emoran
emoran / HashCodeGenerator
Created July 21, 2014 14:51
HashCode generator Apex code
public class HashCodeGenerator{
public static integer getHashCode(object obj){
Map<string, integer> vals = new Map<string, integer>{'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15};
string objJS = JSON.serialize(obj);
Blob b = Blob.valueOf(objJS);
Blob bHash = Crypto.generateMac('hmacSHA1', b, blob.valueOf('a key that does not matter'));
string objHex = EncodingUtil.convertToHex(bHash);