Skip to content

Instantly share code, notes, and snippets.

View manzanit0's full-sized avatar

Javier García manzanit0

View GitHub Profile
@manzanit0
manzanit0 / ApexBatchExample.cls
Created October 23, 2017 12:50
Quick implementation of an Apex Batch, from the docs.
global class SearchAndReplace implements Database.Batchable<sObject>{
global final String Query;
global final String Entity;
global final String Field;
global final String Value;
global SearchAndReplace(String q, String e, String f, String v){
Query=q; Entity=e; Field=f;Value=v;
public class AsyncExecutionExample implements Queueable {
public void execute(QueueableContext context) {
Account a = new Account(Name='Acme',Phone='(415) 555-1212');
insert a;
}
}
// To execute: ID jobID = System.enqueueJob(new AsyncExecutionExample());
using Microsoft.Office.Interop.Word;
using System.IO;
namespace MSWordExample
{
public class LineNumberingKiller
{
static void Main(string[] args)
{
Application word = new Application();
@manzanit0
manzanit0 / ForceClient.cs
Last active June 27, 2018 10:52
HTTP client to authenticate to Salesforce Tooling API
public class ForceClient
{
public string AuthToken { get; set; }
public string ServiceUrl { get; set; }
public void Login(LoginInfo info)
{
HttpContent content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"grant_type", "password"},
@manzanit0
manzanit0 / SandboxInfo.cs
Created June 27, 2018 10:58
Sandbox manager to create and refresh sandboxes.
public class SandboxInfo
{
public SandboxInfo()
{
AutoActivate = true;
LicenseType = "DEVELOPER";
Description = "Sandbox created via API";
}
public string SandboxName { get; set; }
@manzanit0
manzanit0 / ForceClient.cs
Created June 27, 2018 11:00
More methods for the ForceClient.cs
public class ForceClient
{
// ... Further methods in the Force client.
public HttpResponseMessage Get(string endpoint)
{
return Callout(HttpMethod.Get, endpoint, "{}");
}
public HttpResponseMessage Post(string endpoint, string payload)
global class PrepareMySandbox implements SandboxPostCopy {
global void runApexClass(SandboxContext context) {
System.debug('Org ID: ' + context.organizationId());
System.debug('Sandbox ID: ' + context.sandboxId());
System.debug('Sandbox Name: ' + context.sandboxName());
// Insert logic here to prepare the sandbox for use.
}
}
@manzanit0
manzanit0 / deploy.ps1
Last active December 7, 2022 17:08
PowerShell Script to deploy repository to Salesforce. It uses SFDX CLI.
# https://codereview.stackexchange.com/questions/200870/powershell-script-to-deploy-repository-to-salesforce
param([string] $repositoryDirectory, [bool] $isProduction)
# TODO - git integration. Select a branch and check it out for deploy.
# TODO - break stuff into functions and reusable pieces. ¿piping? ¿cmdlets?
# TODO - Allow directory structures?
Write-Host -ForegroundColor green ":: Validating Repository ::"
$srcDirectory = [System.IO.Path]::Combine($repositoryDirectory, "src")
@manzanit0
manzanit0 / tictactoe_gameloop.rb
Created October 25, 2018 16:54
Refactor: keeping the same level of abstraction.
def play
clear_console
print_menu
option = get_menu_option
factory = GameFactory.new
@game = factory.create_game(option)
clear_console
print_board(@game.board)
@manzanit0
manzanit0 / .nvimrc
Last active February 28, 2019 12:53
My NeoVim config
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'crusoexia/vim-monokai' " Color theme