Skip to content

Instantly share code, notes, and snippets.

View Frelseren's full-sized avatar

Nikita Verkhoshintcev Frelseren

View GitHub Profile
@Frelseren
Frelseren / contacts.component.ts
Created February 10, 2018 18:19
Angular app LCC Web Service
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import * as LCC from 'lightning-container';
declare const sforce;
interface Contact {
Id: string;
Name: string;
}
@Frelseren
Frelseren / index.html
Created February 10, 2018 18:18
Angular index.html source file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Meetup</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="assets/main.css">
</head>
@Frelseren
Frelseren / AngularPOC.html
Created February 10, 2018 18:16
AngularPOC Lightning Component
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
<lightning:container src="{!$Resource.AngularPOC + '/index.html'}" />
</aura:component>
@Frelseren
Frelseren / contacts.component.ts
Created February 10, 2018 18:16
Angular app REST
import { Component, OnInit } from '@angular/core';
import { ApexService } from '../apex.service';
interface Contact {
Id: string;
Name: string;
}
@Component({
selector: 'app-contacts',
@Frelseren
Frelseren / apex.service.ts
Created February 10, 2018 18:15
Angular service for Apex requests
// apex.service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
declare const sessionId;
interface Contact {
Id: string;
Name: string;
@Frelseren
Frelseren / AngularPOC.html
Created February 10, 2018 18:14
AngularPOC Visualforce page REST
<apex:page standardStylesheets="false" sidebar="false" showHeader="false"
applyBodyTag="false" applyHtmlTag="false" docType="html-5.0">
<html>
<head>
<meta charset="utf-8" />
<title>Meetup</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="{!$Resource.AngularPOC + '/favicon.ico'}" />
<link rel="stylesheet" type="text/css" href="{!$Resource.AngularPOC + '/assets/main.css'}" />
@Frelseren
Frelseren / AngularPOC.cls
Created February 10, 2018 18:13
AngularPOC Apex class REST
@RestResource(urlMapping = '/angularpoc')
global class AngularPOC {
@HttpGet
global static List<Contact> getContacts() {
RestRequest req = RestContext.request;
String contactId = req.params.get('contactId');
if (contactId != null) {
return [SELECT Id, Name, Title, Phone, Email FROM Contact WHERE Id =: contactId];
}
@Frelseren
Frelseren / webservice-async-example.ts
Created February 10, 2018 18:12
Explample of async web service
// Example of asynchronous web service
// Function that returns a promise with a list of contacts
// and throws if there is any error in Apex. As alternative,
// you can return empty array right there.
async getContacts(): Promise<Contact[]> {
try {
const contacts = await JSON.parse(sforce.apex.execute('AngularPOC', 'getContacts', { }));
return contacts;
} catch (e) {
throw new Error(e);
@Frelseren
Frelseren / contacts.component.ts
Created February 10, 2018 18:11
Angular app Web Service
import { Component, OnInit } from '@angular/core';
declare const sforce;
interface Contact {
Id: string;
Name: string;
}
@Component({
@Frelseren
Frelseren / AngularPOC.html
Created February 10, 2018 18:10
AngularPOC Visualforce page Web Service
<apex:page standardStylesheets="false" sidebar="false" showHeader="false"
applyBodyTag="false" applyHtmlTag="false" docType="html-5.0">
<html>
<head>
<meta charset="utf-8" />
<title>Meetup</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="{!$Resource.AngularPOC + '/favicon.ico'}" />
<link rel="stylesheet" type="text/css" href="{!$Resource.AngularPOC + '/assets/main.css'}" />