Skip to content

Instantly share code, notes, and snippets.

View Frelseren's full-sized avatar

Nikita Verkhoshintcev Frelseren

View GitHub Profile
@Frelseren
Frelseren / AngularPOC.cls
Created February 10, 2018 17:51
AngularPOC Apex class with Remote Action
public class AngularPOC {
@RemoteAction
public static List getContacts() {
return [SELECT Id, Name FROM Contact];
}
@RemoteAction
public static Contact getContact(String contactId) {
return [SELECT Id, Name, Title, Phone, Email FROM Contact WHERE Id =: contactId];
}
@Frelseren
Frelseren / AngularPOC.page
Created February 10, 2018 18:06
AngularPOC Visualforce page with Remote Action
<apex:page standardStylesheets="false" sidebar="false" showHeader="false"
applyBodyTag="false" applyHtmlTag="false" docType="html-5.0"
controller="AngularPOC">
<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'}" />
@Frelseren
Frelseren / AngularPOC.html
Created February 10, 2018 18:07
AngularPOC Visualforce page with RemoteAction
<apex:page standardStylesheets="false" sidebar="false" showHeader="false"
applyBodyTag="false" applyHtmlTag="false" docType="html-5.0"
controller="AngularPOC">
<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'}" />
@Frelseren
Frelseren / contacts.component.ts
Created February 10, 2018 18:09
Angular app Remote Action example
import { Component, OnInit } from '@angular/core';
declare const Visualforce;
interface Contact {
Id: string;
Name: string;
}
@Component({
@Frelseren
Frelseren / AngularPOC.cls
Created February 10, 2018 18:10
AngularPOC Apex class Web Service
global class AngularPOC {
@RemoteAction
webservice static String getContacts() {
return JSON.serialize([SELECT Id, Name FROM Contact]);
}
@RemoteAction
webservice static String getContact(String contactId) {
return JSON.serialize([SELECT Id, Name, Title, Phone, Email FROM Contact WHERE Id =: contactId][0]);
}
@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'}" />
@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 / 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 / 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];
}