Skip to content

Instantly share code, notes, and snippets.

@brianmfear
Created February 13, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianmfear/1edeccb86bdd1cb1c31e16a3f405d69c to your computer and use it in GitHub Desktop.
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)
<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>
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;
}
}
({
init : function(component, event, helper) {
var action = component.get("c.getData");
action.setCallback(
this,
response => component.set("v.data", response.getReturnValue())
);
$A.enqueueAction(action);
}
})
<template>
<template if:true={data}>
{data.a} {data.b} {data.c}
</template>
<template if:true={error}>
{error}
</template>
</template>
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;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>47.0</apiVersion>
<isExposed>false</isExposed>
</LightningComponentBundle>
@pchittum
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment