├── .gitignore
├── .project
├── .salesforcedx.yaml
├── README.md
├── config
└── project-scratch-def.json
├── force-app
└── main
│ └── default
│ ├── ExampleApex.cls
│ ├── ExampleApex.cls-meta.xml
│ └── aura
│ ├── ApexProxy
│ ├── ApexProxy.cmp
│ ├── ApexProxy.cmp-meta.xml
│ ├── ApexProxy.css
│ ├── ApexProxyController.js
│ ├── ApexProxyHelper.js
│ └── ApexProxyRenderer.js
│ ├── ApexProxyApplicationEvent
│ ├── ApexProxyApplicationEvent.evt
│ └── ApexProxyApplicationEvent.evt-meta.xml
│ ├── ApexProxyComponentEvent
│ ├── ApexProxyComponentEvent.evt
│ └── ApexProxyComponentEvent.evt-meta.xml
│ ├── ExampleApexProxyConsumer
│ ├── ExampleApexProxyConsumer.cmp
│ ├── ExampleApexProxyConsumer.cmp-meta.xml
│ ├── ExampleApexProxyConsumer.css
│ ├── ExampleApexProxyConsumerController.js
│ ├── ExampleApexProxyConsumerHelper.js
│ └── ExampleApexProxyConsumerRenderer.js
│ └── ExampleApp
│ ├── ExampleApp.app
│ ├── ExampleApp.app-meta.xml
│ ├── ExampleApp.css
│ ├── ExampleAppController.js
│ ├── ExampleAppHelper.js
│ └── ExampleAppRenderer.js
├── sfdx-project.json
└── src
├── aura
├── ApexProxy
│ ├── ApexProxy.cmp
│ ├── ApexProxy.cmp-meta.xml
│ ├── ApexProxy.css
│ ├── ApexProxyController.js
│ ├── ApexProxyHelper.js
│ └── ApexProxyRenderer.js
├── ApexProxyApplicationEvent
│ ├── ApexProxyApplicationEvent.evt
│ └── ApexProxyApplicationEvent.evt-meta.xml
├── ApexProxyComponentEvent
│ ├── ApexProxyComponentEvent.evt
│ └── ApexProxyComponentEvent.evt-meta.xml
├── ExampleApexProxyConsumer
│ ├── ExampleApexProxyConsumer.cmp
│ ├── ExampleApexProxyConsumer.cmp-meta.xml
│ ├── ExampleApexProxyConsumer.css
│ ├── ExampleApexProxyConsumerController.js
│ ├── ExampleApexProxyConsumerHelper.js
│ └── ExampleApexProxyConsumerRenderer.js
└── ExampleApp
│ ├── ExampleApp.app
│ ├── ExampleApp.app-meta.xml
│ ├── ExampleApp.css
│ ├── ExampleAppController.js
│ ├── ExampleAppHelper.js
│ └── ExampleAppRenderer.js
├── classes
├── ExampleApex.cls
└── ExampleApex.cls-meta.xml
└── package.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | .sfdx/
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | apex-proxy
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.salesforcedx.yaml:
--------------------------------------------------------------------------------
1 | scratch-org-def: config/project-scratch-def.json
2 | assign-permset: false
3 | run-apex-tests: false
4 | delete-scratch-org: false
5 | show-scratch-org-url: true
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Lightning Apex Proxy
2 |
3 | The Lightning Apex Proxy component makes calls to @AuraEnabled Apex methods easier by encapsulating the $A.enqueueAction cycle. It allows you to pass success and error callbacks as anonymous function and fire component-level and application-level events.
4 |
5 | This repo is a Salesforce DX project. To get started, you'll need to spin up a scratch org, pull this repo and push the components into your scratch org.
6 |
7 | **Deploy to SFDX Scratch Org:**
8 | [](https://deploy-to-sfdx.com)
9 |
10 | **Deploy to Salesforce Org:**
11 | [](https://githubsfdeploy.herokuapp.com/?owner=tompatros&repo=lightning-apex-proxy&ref=master)
12 |
13 | ## Usage
14 |
15 | 1. Make a Lightning Component that needs to call an Apex method.
16 | 1. Add Apex Proxy to the component. Remember to include the "aura:id" attribute.
17 |
18 | ```
19 |
20 | ```
21 |
22 | 1. In your component's controller (or helper), find the Apex Proxy component by name and call it's "call" aura method.
23 |
24 | ```javascript
25 | // locate the apex proxy component within this component
26 | var apexProxy = component.find('apexProxy');
27 |
28 | // the "action" is the apex @auraenabled method on this component's controller
29 | // in this case "ExampleApex.method1"
30 | var action = component.get('c.method1');
31 |
32 | // params to the method are pass as an object with property names matching
33 | var params = {
34 | param1 : 'PARAM1'
35 | };
36 |
37 | // call the aura:method exposed on the ApexProxy component
38 | apexProxy.call(
39 | action,
40 | params,
41 | function(payload) {
42 | // onSuccess function
43 | // anonymous function retains references to component, event and helper
44 | // ApexProxy component passes "payload", which is whatever the Apex method returns
45 | // from here, you could make further calls to helper.whateverMethodToDoStuff();
46 | component.set('v.method1Value', payload);
47 | },
48 | function(payload) {
49 | // onError function
50 | // anonymous function retains references to component, event and helper
51 | // ApexProxy component passes "payload", which is whatever the Apex method returns
52 | // from here, you could make further calls to helper.whateverMethodToDoStuff();
53 | console.log(payload)
54 | }
55 | );
56 | ```
57 | A consolidated example, passing callbacks (but no events):
58 |
59 | ```javascript
60 | var apexProxy = component.find('apexProxy');
61 | var action = component.get('c.method1');
62 | var params = { param1 : 'PARAM1' };
63 | apexProxy.call(action, params,
64 | function(payload) {
65 | // success callback...
66 | },
67 | function(payload) {
68 | // error callback...
69 | }
70 | );
71 | ```
72 |
73 | 1. Rejoice in knowing you never have to write $A.enqueueAction code again.
74 |
75 | ## Apex Proxy Events
76 |
77 | Apex Proxy comes pre-packaged with a generic Application event (ApexProxyApplicationEvent) and Component event (ApexProxyComponentEvent). Each event has three attributes:
78 |
79 | * title (String) - if the 'onSuccess' or 'onError' value provided is a string, the "title" attribute will be set with that value.
80 | * data (Object) - the data returned from the Apex method.
81 | * error (Object) - if the Apex method returns as an error, the getError() data will be populated here.
82 |
83 | The last parameter of Apex Proxy's "call" method is "eventLevel". You can test it to:
84 |
85 | * NONE (default) - no events are fired
86 | * APPLICATION - the application-level event is fired
87 | * COMPONENT - the component-level event is fired
88 | * ALL - both the application and component-level events are fired
89 |
90 | ### Application-Level Event Example
91 |
92 | ```javascript
93 | var apexProxy = component.find('apexProxy');
94 | var action = component.get('c.method1');
95 | var params = { param1 : 'PARAM1' };
96 | apexProxy.call(action, params, 'doSuccessStuff', 'doErrorStuff', 'APPLICATION');
97 | ```
98 | Any component handling ApexProxyApplicationEvent will receive the event with:
99 |
100 | * title = 'doSuccessStuff' (or 'doErrorStuff')
101 | * data = the response of the method
102 | * error = getError() (if there is an error)
103 |
104 | ### Component-Level Event Example
105 |
106 | **NOTE: you must update your reference to the Apex Proxy component to include an 'onComplete' attribute so the parent component can handle the event properly.**
107 |
108 | ```
109 |
110 | ```
111 |
112 | Then, you can request the component-level event.
113 |
114 | ```javascript
115 | var apexProxy = component.find('apexProxy');
116 | var action = component.get('c.method1');
117 | var params = { param1 : 'PARAM1' };
118 | apexProxy.call(action, params, 'doSuccessStuff', 'doErrorStuff', 'COMPONENT');
119 | ```
120 |
121 | Any component handling ApexProxyComponentEvent will receive the event with:
122 |
123 | * title = 'doSuccessStuff' (or 'doErrorStuff')
124 | * data = the response of the method
125 | * error = getError() (if there is an error)
--------------------------------------------------------------------------------
/config/project-scratch-def.json:
--------------------------------------------------------------------------------
1 | {
2 | "orgName": "Red Argyle - Apex Proxy",
3 | "edition": "Developer",
4 | "orgPreferences" : {
5 | "enabled": ["S1DesktopEnabled"]
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/force-app/main/default/ExampleApex.cls:
--------------------------------------------------------------------------------
1 | public with sharing class ExampleApex {
2 |
3 | @AuraEnabled
4 | public static String method1(String param1) {
5 | String return1 = param1 + ' RETURN1';
6 | return return1;
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/force-app/main/default/ExampleApex.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxy/ApexProxy.cmp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxy/ApexProxy.cmp-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Component Bundle
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxy/ApexProxy.css:
--------------------------------------------------------------------------------
1 | .THIS {
2 | }
3 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxy/ApexProxyController.js:
--------------------------------------------------------------------------------
1 | ({
2 | call : function(component, event, helper) {
3 | return helper.call(component, event, helper);
4 | }
5 | })
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxy/ApexProxyHelper.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | call : function(component, event, helper) {
4 |
5 | var args = event.getParam('arguments');
6 | var action = args.action;
7 | var actionParams = args.actionParams;
8 | var onSuccess = args.onSuccess;
9 | var onError = args.onError;
10 | var eventLevel = args.eventLevel;
11 |
12 | var componentEvent = component.getEvent("componentEvent");
13 | var applicationEvent = $A.get("e.c:applicationEvent");
14 |
15 | action.setParams(actionParams);
16 |
17 | action.setCallback(this, function(response) {
18 |
19 | var responseState = response.getState();
20 | var responseError = response.getError();
21 | var responseValue = response.getReturnValue();
22 |
23 | var eventParams = { title : onSuccess, data : responseValue };
24 |
25 | switch(responseState) {
26 |
27 | default: break;
28 | case 'NEW': break;
29 | case 'RUNNING': break;
30 |
31 | case 'SUCCESS':
32 |
33 | if(typeof onSuccess === "function") {
34 |
35 | // onSuccess is an anonymous function - call with the returned value
36 | onSuccess(responseValue);
37 |
38 | } else if(typeof onSuccess === "string") {
39 |
40 | // onSuccess is a string, which is interpreted as the "title" parameter in the ApexProxyApplicationEvent or ApexProxyComponentEvent
41 | if(eventLevel === 'APPLICATION') {
42 | applicationEvent.setParams(eventParams);
43 | applicationEvent.fire();
44 | } else if(eventLevel === 'COMPONENT') {
45 | componentEvent.setParams(eventParams);
46 | componentEvent.fire();
47 | }
48 |
49 | }
50 | break;
51 |
52 | case 'ERROR':
53 | case 'INCOMPLETE':
54 |
55 | if(typeof onError === "function") {
56 |
57 | // onError is an anonymous function - call with the returned value
58 | onError(responseValue);
59 |
60 | } else if(typeof onError === "string") {
61 |
62 | eventParams.error = responseError;
63 |
64 | // onError is a string, which is interpreted as the "title" parameter in the ApexProxyApplicationEvent or ApexProxyComponentEvent
65 | if(eventLevel === 'APPLICATION') {
66 | applicationEvent.setParams(eventParams);
67 | applicationEvent.fire();
68 | } else if(eventLevel === 'COMPONENT') {
69 | componentEvent.setParams(eventParams);
70 | componentEvent.fire();
71 | }
72 |
73 | }
74 | break;
75 |
76 | }
77 |
78 | });
79 |
80 | $A.enqueueAction(action);
81 |
82 | }
83 | })
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxy/ApexProxyRenderer.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | // Your renderer method overrides go here
4 |
5 | })
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxyApplicationEvent/ApexProxyApplicationEvent.evt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxyApplicationEvent/ApexProxyApplicationEvent.evt-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Event Bundle
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxyComponentEvent/ApexProxyComponentEvent.evt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ApexProxyComponentEvent/ApexProxyComponentEvent.evt-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Event Bundle
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumer.cmp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | method1Value : {!v.method1Value}
6 |
7 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumer.cmp-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Component Bundle
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumer.css:
--------------------------------------------------------------------------------
1 | .THIS {
2 | }
3 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumerController.js:
--------------------------------------------------------------------------------
1 | ({
2 | init : function(component, event, helper) {
3 | helper.init(component, event, helper);
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumerHelper.js:
--------------------------------------------------------------------------------
1 | ({
2 | init : function(component, event, helper) {
3 |
4 | // locate the apex proxy component within this component
5 | var apexProxy = component.find('apexProxy');
6 |
7 | // the "action" is the apex @auraenabled method on this component's controller
8 | // in this case "ExampleApex.method1"
9 | var action = component.get('c.method1');
10 |
11 | // params to the method are pass as an object with property names matching
12 | var params = {
13 | param1 : 'PARAM1'
14 | };
15 |
16 | // call the aura:method exposed on the ApexProxy component
17 | apexProxy.call(
18 | action,
19 | params,
20 | function(payload) {
21 | // onSuccess function
22 | // anonymous function retains references to component, event and helper
23 | // ApexProxy component passes "payload", which is whatever the Apex method returns
24 | console.log(component);
25 | console.log(event);
26 | console.log(helper);
27 | console.log(payload);
28 | component.set('v.method1Value', payload);
29 | // from here, you could make further calls to helper.whateverMethodToDoStuff();
30 | },
31 | function(payload) {
32 | // onError function
33 | // anonymous function retains references to component, event and helper
34 | // ApexProxy component passes "payload", which is whatever the Apex method returns
35 | console.log(component);
36 | console.log(event);
37 | console.log(helper);
38 | console.log(payload);
39 | // from here, you could make further calls to helper.whateverMethodToDoStuff();
40 | }
41 | );
42 |
43 | }
44 | })
45 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumerRenderer.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | // Your renderer method overrides go here
4 |
5 | })
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApp/ExampleApp.app:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApp/ExampleApp.app-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Application Bundle
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApp/ExampleApp.css:
--------------------------------------------------------------------------------
1 | .THIS {
2 | }
3 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApp/ExampleAppController.js:
--------------------------------------------------------------------------------
1 | ({
2 | myAction : function(component, event, helper) {
3 |
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApp/ExampleAppHelper.js:
--------------------------------------------------------------------------------
1 | ({
2 | helperMethod : function() {
3 |
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/force-app/main/default/aura/ExampleApp/ExampleAppRenderer.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | // Your renderer method overrides go here
4 |
5 | })
6 |
--------------------------------------------------------------------------------
/sfdx-project.json:
--------------------------------------------------------------------------------
1 | {
2 | "packageDirectories": [
3 | {
4 | "path": "force-app",
5 | "default": true
6 | }
7 | ],
8 | "namespace": "",
9 | "sfdcLoginUrl": "https://login.salesforce.com",
10 | "sourceApiVersion": "40.0"
11 | }
12 |
--------------------------------------------------------------------------------
/src/aura/ApexProxy/ApexProxy.cmp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/aura/ApexProxy/ApexProxy.cmp-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Component Bundle
5 |
6 |
--------------------------------------------------------------------------------
/src/aura/ApexProxy/ApexProxy.css:
--------------------------------------------------------------------------------
1 | .THIS {
2 | }
3 |
--------------------------------------------------------------------------------
/src/aura/ApexProxy/ApexProxyController.js:
--------------------------------------------------------------------------------
1 | ({
2 | call : function(component, event, helper) {
3 | return helper.call(component, event, helper);
4 | }
5 | })
--------------------------------------------------------------------------------
/src/aura/ApexProxy/ApexProxyHelper.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | call : function(component, event, helper) {
4 |
5 | var args = event.getParam('arguments');
6 | var action = args.action;
7 | var actionParams = args.actionParams;
8 | var onSuccess = args.onSuccess;
9 | var onError = args.onError;
10 | var eventLevel = args.eventLevel;
11 |
12 | var componentEvent = component.getEvent("componentEvent");
13 | var applicationEvent = $A.get("e.c:applicationEvent");
14 |
15 | action.setParams(actionParams);
16 |
17 | action.setCallback(this, function(response) {
18 |
19 | var responseState = response.getState();
20 | var responseError = response.getError();
21 | var responseValue = response.getReturnValue();
22 |
23 | var eventParams = { title : onSuccess, data : responseValue };
24 |
25 | switch(responseState) {
26 |
27 | default: break;
28 | case 'NEW': break;
29 | case 'RUNNING': break;
30 |
31 | case 'SUCCESS':
32 |
33 | if(typeof onSuccess === "function") {
34 |
35 | // onSuccess is an anonymous function - call with the returned value
36 | onSuccess(responseValue);
37 |
38 | } else if(typeof onSuccess === "string") {
39 |
40 | // onSuccess is a string, which is interpreted as the "title" parameter in the ApexProxyApplicationEvent or ApexProxyComponentEvent
41 | if(eventLevel === 'APPLICATION') {
42 | applicationEvent.setParams(eventParams);
43 | applicationEvent.fire();
44 | } else if(eventLevel === 'COMPONENT') {
45 | componentEvent.setParams(eventParams);
46 | componentEvent.fire();
47 | }
48 |
49 | }
50 | break;
51 |
52 | case 'ERROR':
53 | case 'INCOMPLETE':
54 |
55 | if(typeof onError === "function") {
56 |
57 | // onError is an anonymous function - call with the returned value
58 | onError(responseValue);
59 |
60 | } else if(typeof onError === "string") {
61 |
62 | eventParams.error = responseError;
63 |
64 | // onError is a string, which is interpreted as the "title" parameter in the ApexProxyApplicationEvent or ApexProxyComponentEvent
65 | if(eventLevel === 'APPLICATION') {
66 | applicationEvent.setParams(eventParams);
67 | applicationEvent.fire();
68 | } else if(eventLevel === 'COMPONENT') {
69 | componentEvent.setParams(eventParams);
70 | componentEvent.fire();
71 | }
72 |
73 | }
74 | break;
75 |
76 | }
77 |
78 | });
79 |
80 | $A.enqueueAction(action);
81 |
82 | }
83 | })
--------------------------------------------------------------------------------
/src/aura/ApexProxy/ApexProxyRenderer.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | // Your renderer method overrides go here
4 |
5 | })
6 |
--------------------------------------------------------------------------------
/src/aura/ApexProxyApplicationEvent/ApexProxyApplicationEvent.evt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/aura/ApexProxyApplicationEvent/ApexProxyApplicationEvent.evt-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Event Bundle
5 |
6 |
--------------------------------------------------------------------------------
/src/aura/ApexProxyComponentEvent/ApexProxyComponentEvent.evt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/aura/ApexProxyComponentEvent/ApexProxyComponentEvent.evt-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Event Bundle
5 |
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumer.cmp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | method1Value : {!v.method1Value}
6 |
7 |
--------------------------------------------------------------------------------
/src/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumer.cmp-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Component Bundle
5 |
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumer.css:
--------------------------------------------------------------------------------
1 | .THIS {
2 | }
3 |
--------------------------------------------------------------------------------
/src/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumerController.js:
--------------------------------------------------------------------------------
1 | ({
2 | init : function(component, event, helper) {
3 | helper.init(component, event, helper);
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumerHelper.js:
--------------------------------------------------------------------------------
1 | ({
2 | init : function(component, event, helper) {
3 |
4 | // locate the apex proxy component within this component
5 | var apexProxy = component.find('apexProxy');
6 |
7 | // the "action" is the apex @auraenabled method on this component's controller
8 | // in this case "ExampleApex.method1"
9 | var action = component.get('c.method1');
10 |
11 | // params to the method are pass as an object with property names matching
12 | var params = {
13 | param1 : 'PARAM1'
14 | };
15 |
16 | // call the aura:method exposed on the ApexProxy component
17 | apexProxy.call(
18 | action,
19 | params,
20 | function(payload) {
21 | // onSuccess function
22 | // anonymous function retains references to component, event and helper
23 | // ApexProxy component passes "payload", which is whatever the Apex method returns
24 | console.log(component);
25 | console.log(event);
26 | console.log(helper);
27 | console.log(payload);
28 | component.set('v.method1Value', payload);
29 | // from here, you could make further calls to helper.whateverMethodToDoStuff();
30 | },
31 | function(payload) {
32 | // onError function
33 | // anonymous function retains references to component, event and helper
34 | // ApexProxy component passes "payload", which is whatever the Apex method returns
35 | console.log(component);
36 | console.log(event);
37 | console.log(helper);
38 | console.log(payload);
39 | // from here, you could make further calls to helper.whateverMethodToDoStuff();
40 | }
41 | );
42 |
43 | }
44 | })
45 |
--------------------------------------------------------------------------------
/src/aura/ExampleApexProxyConsumer/ExampleApexProxyConsumerRenderer.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | // Your renderer method overrides go here
4 |
5 | })
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApp/ExampleApp.app:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/aura/ExampleApp/ExampleApp.app-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | A Lightning Application Bundle
5 |
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApp/ExampleApp.css:
--------------------------------------------------------------------------------
1 | .THIS {
2 | }
3 |
--------------------------------------------------------------------------------
/src/aura/ExampleApp/ExampleAppController.js:
--------------------------------------------------------------------------------
1 | ({
2 | myAction : function(component, event, helper) {
3 |
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApp/ExampleAppHelper.js:
--------------------------------------------------------------------------------
1 | ({
2 | helperMethod : function() {
3 |
4 | }
5 | })
6 |
--------------------------------------------------------------------------------
/src/aura/ExampleApp/ExampleAppRenderer.js:
--------------------------------------------------------------------------------
1 | ({
2 |
3 | // Your renderer method overrides go here
4 |
5 | })
6 |
--------------------------------------------------------------------------------
/src/classes/ExampleApex.cls:
--------------------------------------------------------------------------------
1 | public with sharing class ExampleApex {
2 |
3 | @AuraEnabled
4 | public static String method1(String param1) {
5 | String return1 = param1 + ' RETURN1';
6 | return return1;
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/classes/ExampleApex.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/src/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ApexClass
5 | ExampleApex
6 |
7 |
8 | AuraDefinitionBundle
9 | ApexProxy
10 | ApexProxyApplicationEvent
11 | ApexProxyComponentEvent
12 | ExampleApexProxyConsumer
13 | ExampleApp
14 |
15 | 40.0
16 |
--------------------------------------------------------------------------------