One Paragraph of project description goes here
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.
| 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; | 
| 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); | 
| @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); | 
| [ | |
| { | |
| "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" | |
| }, | 
| <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"> | 
| ({ | |
| init: function (cmp, event, helper) { | |
| helper.fetchData(cmp); | |
| } | |
| }) | 
| ({ | |
| 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' }, | |
| ]; | 
| 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); | 
| 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'); |