Skip to content

Instantly share code, notes, and snippets.

View renatoliveira's full-sized avatar

Renato Oliveira renatoliveira

View GitHub Profile
@renatoliveira
renatoliveira / getRecordWithAllFields.cls
Created November 14, 2018 15:02
Method in which the platform gets all the fields for an object, and then executes a dynamic query with all of the fields. Retrieves one or more records.
public List<SObject> getObjects (Set<Id> recordIds) {
Id dummyId = (new List<Id>(recordIds))[0];
String objectName = Id.valueOf(dummyId).getSObjectType().getDescribe().getLocalName();
Set<String> fields = Id.valueOf(dummyId).getSObjectType().getDescribe().fields.getMap().keySet();
String query = 'SELECT ';
for (String f : fields) {
query += f + ', ';
}
@renatoliveira
renatoliveira / IDGeneratorTest.cls
Created August 2, 2018 22:58
Test for IDGenerator.cls
/**
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@renatoliveira
renatoliveira / IDGenerator.cls
Created August 2, 2018 22:58
Class that generates a valid Salesforce ID given a object type.
/**
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@renatoliveira
renatoliveira / GoogleDriveCalloutMock.cls
Last active October 2, 2023 16:39
This is a refactored class that uploads files to Google Drive using the service's REST API.
/**
* Callout mock for the Google Drive API class
*
* Please note that the "generateRandomString" was not originally part of this class. I've added this method because there
* were lots of IDs hardcoded into the URL's inside the JSON responses. Those should not, in theory, affect the tests where
* this mock is used.
*/
@IsTest
global class GoogleDriveCalloutMock implements HttpCalloutMock {
global HTTPResponse respond (HTTPRequest req) {
global class Telegram {
public static void sendMessage (String message, User user) {
sendMessage(message, user.TelegramId__c);
}
public static void sendMessage (String message, String telegram_id) {
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.telegram.org/bot' + TelegramBot__c.getOrgDefaults().Token__c + '/sendMessage');
req.setMethod('POST');
req.setHeader('content-type', 'application/json');
@renatoliveira
renatoliveira / app.py
Created October 13, 2016 16:08
Simple script to get a XML from a service and translate it to JSON
import requests
from json import dumps
from xmljson import parker as pk
from xml.etree.ElementTree import fromstring
endpoint = 'http://webserviceurlhere/number'
xml = requests.get(endpoint).text
result = dumps(pk.data(fromstring(xml)))
print(result)