3

I built a quick action on Campaign that opens a lightning component. I am trying to pass parameters like, say the Id and the name of the Campaign.

Earlier I built this using Detail Page Button and executing javascript like so:

sforce.apex.execute("MyController","controller", 
{campaignId:"{!Campaign.Id}", 
campaignName:"{!Campaign.Name}"});

Is it possible to somehow retrieve those values from the component that gets triggered from the quick action?

Please note, I have no Visual Force page and am not planning on building one.

If this doesn't work can I use a button that opens a lightning App and pass the parameters as a query string then retrieve them somehow from the component?

EDIT I found that I can add implements="force:hasRecordId" to the component and that will give me the object's Id. Is it possible to pass the name similarly without having to query for the record?

1 Answer 1

6

As you've discovered, you can get force:hasRecordId. Unfortunately, any other fields you want, you have to query for. The easiest way to query for them is with force:recordData; this automatically pulls the data from the cache, when available, and includes the record's name:

<aura:component implements="force:hasRecordId,force:lightningQuickAction">
  <aura:attribute name="record" type="Campaign" />
  <force:recordData 
    recordId="{!v.recordId}"
    targetFields="{!v.record}"
    fields="['Name']" 
    recordUpdated="{!c.recordLoaded}" />

From here, you will have access to the fields you've requested:

({
    recordLoaded: function(component, event, helper) {
        var campaign = component.get("v.record");
        // Do whatever you need here
    }
})
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .