Skip to content

Instantly share code, notes, and snippets.

@Frelseren
Created February 10, 2018 18:19
Show Gist options
  • Save Frelseren/525ba46b74ff3af27b958b349889f7cf to your computer and use it in GitHub Desktop.
Save Frelseren/525ba46b74ff3af27b958b349889f7cf to your computer and use it in GitHub Desktop.
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;
}
@Component({
selector: 'app-contacts',
templateUrl: './contacts.component.html'
})
export class ContactsComponent implements OnInit {
contacts: Contact[];
constructor(
private cd: ChangeDetectorRef
) {}
ngOnInit() {
sforce.connection.sessionId = LCC.getRESTAPISessionKey();
try {
this.contacts = JSON.parse(sforce.apex.execute('AngularPOC',
'getContacts', {}));
/**
* Angular cannot detect changes made by lightning container by itself,
* so we have to force the update manually.
*/
this.cd.detectChanges();
} catch (e) {
console.error(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment