Skip to content

Instantly share code, notes, and snippets.

View olopsman's full-sized avatar

Paulo Orquillo olopsman

View GitHub Profile
@olopsman
olopsman / README-Template.md
Created April 1, 2018 22:09 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@olopsman
olopsman / GenericRESTMock.cls
Created October 2, 2019 09:27
Apex GenericRESTMock
public with sharing class GenericRESTMock implements HttpCalloutMock{
protected Integer code;
protected String status;
protected String body;
protected Map<string , String> responseHeaders;
public GenericRESTMock(Integer code, String status, String body, Map<String,String> responseHeaders) {
this.code = code;
this.status = status;
this.body = body;
@olopsman
olopsman / MyServiceAPI.cls
Created October 2, 2019 09:31
Apex Sample REST Callout
public with sharing class MyServiceAPI {
@AuraEnabled
public static String getTransactions(String dateFrom) {
HttpRequest req = new HttpRequest();
req.setMethod('GET');
//retrieved from named credentials
request.setEndpoint('callout:MyServiceAPI/transactions?date=dateFrom');
req.setEndpoint(strEndPoint);
@olopsman
olopsman / gist:f263440caf19a8835c3ff09849bb6369
Created October 2, 2019 09:33
Apex MyServiceAPITest Unit Test using GenericRESTMock
@isTest
private class MyServiceAPITest {
@isTest static void getTransactionsTest() {
Test.startTest();
Map<String,String> headers = new Map<String, String>();
headers.put('Accept','application/json');
Test.setMock(HttpCalloutMock.class, new GenericRESTMock(200,'Success','{"Items":[{"Id":"string","Code":"string","EffectiveDate":"2019-07-15T22:03:31.145Z","Type":"APP"]}',headers));
String str = MyServiceAPI.getTransactions('7/15/2019');
Test.stopTest();
system.assertEquals(null, str);
@olopsman
olopsman / TransactionsJSONPDF.json
Last active October 2, 2019 09:40
JSON sample transacton payload
[
{
"Id": "0d284614-c4ec-424c-a5aa-04e28d06a4df",
"Date": "2016-10-14T08:34:10.8+00:00",
"RegistryAccountCode": "ABC",
"ClientId": 0,
"Category": "I",
"Description": "Distribution Advice 12102016.pdf",
"FileName": "ABC Distribution Advice 12102016.pdf"
},
@olopsman
olopsman / dataTableSampleRest.cmp
Created October 2, 2019 09:43
Lightning Component
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="dataTableSampleREST">
<!-- attributes -->
<aura:attribute name="recordId" type="String"></aura:attribute>
<aura:attribute name="mydata" type="Object"></aura:attribute>
<aura:attribute name="mycolumns" type="List"></aura:attribute>
<aura:attribute name="noResults" type="String"></aura:attribute>
<!-- handlers-->
<aura:handler name="init" value="{! this }" action="{! c.init }"></aura:handler>
<article aura:id="gridContainer" class="slds-card slds-card_boundary">
@olopsman
olopsman / dataTableSampleRestController.js
Created October 2, 2019 09:44
Lightning Component controller
({
init: function (cmp, event, helper) {
helper.fetchData(cmp);
}
})
@olopsman
olopsman / dataTableSampleRestHelper.js
Created October 2, 2019 09:46
Lightning Component Helper that parses the JSON payload
({
fetchData: function (cmp) {
var action = cmp.get('c.getDocumentList');
action.setCallback(this, $A.getCallback(function (response) {
var state = response.getState();
if (state === "SUCCESS") {
if(JSON.parse(response.getReturnValue()) != null) {
var actions = [
{ label: 'Download', name: 'download' },
];
@olopsman
olopsman / dataTableSampleREST.cls
Created October 2, 2019 09:48
Apex Sample REST Callout
public class dataTableSampleREST {
@AuraEnabled
public static String getDocumentList() {
String strEndPoint = 'https://www.lopau.com/rest/accounts';
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint(strEndPoint);
Http h = new Http();
system.debug('## => ' + req);
@olopsman
olopsman / JSONdeserializeUntyped.cls
Created October 2, 2019 09:58
Apex JSONdeserializeUntyped
String input = '{"name":"paulo","age":42, "car" : {"model" : "outlander", "year" : "2016"}}';
Map<String, Object> o = (Map<String, Object>) JSON.deserializeUntyped(input);
system.assertEquals(o.get('name'), 'paulo');
system.assertEquals(o.get('age'), 42);
Map<String, Object> car = (Map<String, Object>) o.get('car');
system.assertEquals(car.get('model'), 'outlander');