Skip to content

Instantly share code, notes, and snippets.

View renatoliveira's full-sized avatar

Renato Oliveira renatoliveira

View GitHub Profile
@renatoliveira
renatoliveira / init.lua
Created January 28, 2024 19:26
Nvim's Init script for setting up the Apex language server
-- Get the file path to the language server file provided by Salesforce.
local apex_jorje_lsp_file_path = vim.fn.expand("~/Downloads/apex-jorje-lsp.jar")
-- Set up the language server configuration for the Apex language, associating
-- it with the three main file types by extension, disabling telemetry, and
-- specifying the command.
require"lspconfig".apex_ls.setup {
apex_jar_setup = apex_jorje_lsp_file_path,
apex_enable_semantic_errors = false,
apex_enable_completion_statistics = false,
### Keybase proof
I hereby claim:
* I am renatoliveira on github.
* I am thelavasailor (https://keybase.io/thelavasailor) on keybase.
* I have a public key ASCi_4EZpwmK6UrnCFxM7pO72L_xqLu88alhYTzal-cphQo
To claim this, I am signing this object:
@renatoliveira
renatoliveira / MondayApi.cls
Created October 13, 2023 17:31
Apex to MondayAPI
public class MondayApi {
@SuppressWarnings('PMD.ApexSuggestUsingNamedCred')
public static Map<String, Object> execute(String query) {
HttpRequest request = new HttpRequest();
request.setEndpoint('callout:MondayApi');
request.setMethod('POST');
request.setBody(JSON.serialize(new Map<String, Object>{
'query' => query
}));
@renatoliveira
renatoliveira / TransferPermissionScript.cls
Last active September 22, 2023 14:05
Transfer Permissions
// 1. Erases permissions from current user
// 2. Copies permission set licenses and permission sets from another user.
// Rollback available at the end of the script.
Savepoint sp = Database.setSavepoint();
String fromUser = '[from username]';
String toUser = '[to username]';
// clean the user
@renatoliveira
renatoliveira / QuotePDFGenerator.apex
Created April 27, 2021 17:31 — forked from citrus/QuotePDFGenerator.apex
Generate Quote PDF via Salesforce REST API
global class QuotePDFGenerator {
@future(callout=true)
public static void AttachPDFToQuote(String Id) {
try {
CreateQuoteDocumentFromPDF(Id);
} catch(exception ex) {
System.debug('Error: ' + ex);
}
}
@renatoliveira
renatoliveira / main.py
Created December 25, 2019 14:14
Transform a POST call to a PATCH call
# Import the required libraries
# Flask is the web framework for dealing with web stuff (such as serving the app and handling
# the connections) We need to import the main "Flask" to run the app, and also its
# request and Response method and class to handle the request properly
from flask import Flask, Response, request
# requests is a simple http request library to handle... requests.
import requests
# Base64 is a standard module to help us encode/decode Base 64 strings
@renatoliveira
renatoliveira / AssignPermissions.cls
Last active April 26, 2019 19:25
Assigns a permission "PermissionName" to users from profiles that were specified.
// Permission set's name that I want to assign to all the users
String psName = 'PermissionName';
// Query the permission set
PermissionSet ps = [
SELECT
Id,
Label,
Name
FROM PermissionSet
public class ComparisonTableController {
@AuraEnabled(cacheable=true)
public static List<PricebookEntry> getProducts (Id pricebookId, Integer countLimit) {
return [
SELECT
Id
,Product2.Name
,Product2.Family
,Product2.ProductCode
@renatoliveira
renatoliveira / TimezoneRunAsSample.cls
Last active January 29, 2019 10:50
This gist shows that you can use the 'runAs' method to simulate timezone differences between one or more users in a test.
// Considering that 'neutral_user' has 'GMT' as its 'TimeZoneSidKey' field,
// and that the other two users run with 'America/Puerto_Rico' and
// 'America/Sao_Paulo'.
Datetime christmas2018utc;
System.runAs(neutral_user) {
// Creates a datetime instance on December 25th, at 12:00 (GMT).
// Using the 'runAs' method because if we don't, then the date instance will be
// on the same timezone as the test running user.
christmas2018utc = Datetime.newInstance(Date.newInstance(2018, 12, 25), Time.newInstance(12, 0, 0, 0));
@renatoliveira
renatoliveira / eraselogs2.py
Created December 27, 2018 16:24
Erase all specified ApexLog records from Salesforce
from simple_salesforce import Salesforce
import argparse
parser = argparse.ArgumentParser(description='Erase logs')
parser.add_argument('-q', '--query', dest='query', help='ApexLog query')
parser.add_argument('-u', '--username', dest='username', help='Salesforce username')
parser.add_argument('-p', '--password', dest='password', help='Salesforce password')
parser.add_argument('-t', '--token', dest='token', help='Salesforce token')