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
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);
@emoran
emoran / MapBox_Visualforce Sample
Created July 25, 2014 22:48
MapBox with visualforce sample, markers
<apex:page standardController="Inventario_de_Guardias__c" extensions="CM_GSM_Guard_Location">
<head>
<title>Single marker</title>
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
@emoran
emoran / Exception_to_email
Created July 29, 2014 21:42
Send an email when an exception is catched.
try{
update account;
}
catch (DMLException e){
ApexPages.addMessages(e);
Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'developer@acme.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('developer@acme.com');