0

I'd like to use a <lightning:recordEditForm> to edit a CampaignMember. When I add campaign member fields to the component they show up as editable no problem. However, when I add related fiends (say, CampaignMember.Lead.FirstName) it displays fine, but the text box is disabled so I can't edit it. Any way around this?

  • 1
    You can't edit field which is present on other objects. – MIX DML Apr 17 '18 at 14:16
1

Here's a suggestion:

  1. Create a mock Lead to use to bind field values.

  2. Set the id when you get a reference to the campaignMember, and query for field values used on the page.

  3. Bind your fields to this dummy lead. When they change the fields, the dummy lead takes the changes.

  4. Override the basic save method, to on a successful save of the campaign member, to update the lead used, including its new field values.


I've never really worked with lightning, so I'm not sure what to provide for a code example, but this pattern has worked for me in classic.

| improve this answer | |
1

The fields are from Lead or Contact and CamapignMember is an association with either a Lead or Contact to a Campaign, and thus those fields are always displayed as read only. What you are looking for is to edit Lead (or Contact) information using recordEditForm while using the component on CampaignMember.

While I wouldn't recommend editing Lead or Contact fields from CampaignMember custom screen as they should be done on the respective object level, and also that it's not the efficient way to address the requirement. But if at all you have a use case, the following approach may be utilized.

On your recordEditForm, use lighting:input (still in beta as of today) for all those fields from Lead or Contact that you want to edit. Let's say you want to edit the Leads's first name along with other fields that you want to capture. So you declare it on the component as:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:recordEditForm aura:id="editForm" objectApiName="CampaignMember" recordId="xxxxxxxxx">
    <lightning:messages />
    <lightning:input aura:id="leadFirstName" type="text" label="First Name" />
    <lightning:inputField aura:id="lastName" fieldName="LastName" />
    <lightning:inputField aura:id="cmpAct" fieldName="Campaing_Custom__c" />
    <lightning:button class="slds-m-top_small" variant="brand" name="update" label="Update" onclick="{!c.onSubmit}"/>
</lightning:recordEditForm>

In doInit JS function, get the Lead details from Apex as below:

doInit: function (cmp, event, helper) {
    var campaignId = cmp.find('editForm').get('v.recordId');
    // pass on this to an aura method to retrieve lead details for that campaign member record
    // get the response from the aura method and set the value on the attribute for leads
    cmp.find('leadFirstName').set('v.value', 'response from aura');
}

Then finally, while saving the record, save the details captured on individual fields for campaignmember and the custom Lead field.

onSubmit : function(cmp, event, helper){
    // call an aura method which will take care of saving the campaign details, as well as the lead details
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.