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 / 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');
@emoran
emoran / Group Information in a Map
Last active April 27, 2022 14:30
Adding list values to apex map<String,List<Sobject>>
Map<Id, List<Id>> userRoleToUsers = new Map<Id, List<Id>>();
for(User newUser : [SELECT UserRoleId FROM User LIMIT 50000]) {
if(userRoleToUsers.containsKey(newUser.UserRoleId)) {
List<Id> usersId = userRoleToUsers.get(newUser.UserRoleId);
usersId.add(newUser.Id);
userRoleToUsers.put(newUser.UserRoleId, usersId);
} else {
userRoleToUsers.put(newUser.UserRoleId, new List<Id> { newUser.Id });
}
@emoran
emoran / Export_to_excel_custom Name
Created September 22, 2014 18:13
Export to Excel with custom name
<script>
(function ($) {
var rules = document.styleSheets[document.styleSheets.length-1].cssRules;
for (var idx = 0, len = rules.length; idx < len; idx++) {
$(rules[idx].selectorText).each(function (i, elem) {
elem.style.cssText += rules[idx].style.cssText;
});
}
$('style').remove();
})(jQuery);
@emoran
emoran / Get_LatLon_Trigger
Last active August 29, 2015 14:09
Allow use it when you need to get information about longitude and latitude from a trigger
/**
* A google Maps function to get Latitude and Longitude from Goole Maps API
* @author Edgar Yucel Morán Sanchez
* @version 1.0
* @date 11/10/2014
*/
public class CL_GoogleMaps_Geolocations {
public CL_GoogleMaps_Geolocations() {}
@emoran
emoran / duplicates_values
Created November 18, 2014 16:43
Query to get duplicates
select N_mero_de_contrato__c, count(id) num from Contract group by N_mero_de_contrato__c having count(N_mero_de_contrato__c) > 1
@emoran
emoran / Sync_Quote
Created December 8, 2014 18:00
Sync a quote automatically (Quote needs to be activated)
Opportunity opp = [Select Id,SyncedQuoteId from Opportunity where Id =:this.id_Opportunity];
opp.SyncedQuoteId = q.Id;
@emoran
emoran / get_users
Created December 9, 2014 23:45
Get ASANA Users from Apex salesforce
public static List<ASANA_User_wrapper> getUsers() {
List<ASANA_User_wrapper> list_asana_users = new List<ASANA_User_wrapper>();
HttpRequest aRequest = new HttpRequest();
aRequest.setEndpoint('https://app.asana.com/api/1.0/users');
aRequest.setMethod('GET');
String username = API_KEY;
@emoran
emoran / pageBlockSection_Custom_color
Created December 10, 2014 21:06
Change PageBlockSection color
<style>
.pbSubheader{
background-color: red !important;
border-color: none !important;
}
</style>
@emoran
emoran / Default_User_Profile_Apex
Created December 12, 2014 01:11
Get the default user profile
//find all Opportunity record types
List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Event.RecordTypeInfos;
Id defaultRecordTypeId;
//check each one
for (Schema.RecordTypeInfo info : infos) {
if (info.DefaultRecordTypeMapping) {
defaultRecordTypeId = info.RecordTypeId;
}
}