Skip to content

Instantly share code, notes, and snippets.

@sfcure
Last active January 30, 2021 19:47
Show Gist options
  • Save sfcure/0605a5bf66a9a196f354c5102c92423c to your computer and use it in GitHub Desktop.
Save sfcure/0605a5bf66a9a196f354c5102c92423c to your computer and use it in GitHub Desktop.
<aura:event type="COMPONENT" description="On record selection">
<aura:attribute name="childObjectName" type="String"/>
<aura:attribute name="fieldName" type="String"/>
<aura:attribute name="selectedRecordId" type="String"/>
</aura:event>
<aura:component>
<aura:attribute name="childObjectName" type="String" required="true"/>
<aura:attribute name="fieldName" type="String" required="true"/>
<aura:attribute name="selectedRecordId" type="String"/>
<aura:registerEvent name="onSelectEvt" type="c:CustomLookupSelectionEvt"/>
<lightning:recordEditForm
onload="{!c.setSelectedRecordId}"
objectApiName="{!v.childObjectName}">
<lightning:inputField aura:id="lookupField" variant="label-stacked" fieldName="{!v.fieldName}" onchange="{!c.fireOnSelectEvt}"/>
</lightning:recordEditForm>
</aura:component>
({
setSelectedRecordId: function(component, event, helper) {
var selectedRecordId = component.get("v.selectedRecordId");
component.find("lookupField").set("v.value", selectedRecordId);
},
fireOnSelectEvt : function(component, event, helper) {
var cmpEvent = component.getEvent("onSelectEvt");
cmpEvent.setParams({
"childObjectName": component.get("v.childObjectName"),
"fieldName": component.get("v.fieldName"),
"selectedRecordId": component.find("lookupField").get("v.value")
});
cmpEvent.fire();
}
})
<!--aura Handler-->
<aura:handler name="onSelectEvt" event="c:CustomLookupSelectionEvt" action="{!c.getLookUpValues}"/>
<c:CustomLookupStd
selectedRecordId="{!v.projectId}"
childObjectName="Contact"
fieldName="Project_in_Contact__c"/>
{
getLookUpValues : function(component, event, helper){
let fieldName = event.getParam("fieldName");
let projectId = event.getParam("selectedRecordId");
component.set("v.projectId", projectId);
},
}
@Nidhi-sfdc
Copy link

works well but how to fetch more than one field from same obj like picklist

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