Created
February 13, 2020 14:14
-
-
Save brianmfear/1edeccb86bdd1cb1c31e16a3f405d69c to your computer and use it in GitHub Desktop.
Demo of using @AuraEnabled without getter/setter in both Aura and LWC (SFSE: 292183)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:application controller="q292183"> | |
<aura:handler name="init" value="{!this}" action="{!c.init}" /> | |
<aura:attribute name="data" type="Map" /> | |
{!v.data.a} {!v.data.b} {!v.data.c} | |
<hr /> | |
<c:q292183lwc /> | |
</aura:application> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class q292183 { | |
public class Response { | |
@AuraEnabled public String a, b, c; | |
} | |
@AuraEnabled(cacheable=true) public static Response getData() { | |
Response res = new Response(); | |
res.a = 'Hello'; | |
res.b = 'World'; | |
res.c = 'Everyone'; | |
return res; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
init : function(component, event, helper) { | |
var action = component.get("c.getData"); | |
action.setCallback( | |
this, | |
response => component.set("v.data", response.getReturnValue()) | |
); | |
$A.enqueueAction(action); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<template if:true={data}> | |
{data.a} {data.b} {data.c} | |
</template> | |
<template if:true={error}> | |
{error} | |
</template> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement, wire, track } from 'lwc'; | |
import getData from '@salesforce/apex/Q292183.getData'; | |
export default class Q292183lwc extends LightningElement { | |
@track data; | |
@track error; | |
@wire(getData, {}) | |
result({data, error}) { | |
this.data = data; | |
this.error = error; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<apiVersion>47.0</apiVersion> | |
<isExposed>false</isExposed> | |
</LightningComponentBundle> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@brianmfear, mine is failing as an Apex type as an input parameter to an Apex method, not the return. But now that I'm saying that, I wonder how common is that really? Adding 2-3 params isn't a big deal. But you only get one object to pass back. So probably much more prevalent to pass back an Apex type than to use as input.