So figured this out, and it's a bit clunky if you ask me.
- Create a VF page that uses the sObject as the StandardController
- Create an Action on the sObject that opens the page you just created
- In the controller, create a method that returns a PageReference to the VF page you actually want to go to, and pass add any parameters there.
- On the VF page, set the method you created as the Action property in the element, like Action={!goToPage}
The downside, you get this big empty modal that pops up for a second before actually redirecting you. The modal has action buttons at the bottom as well... which you can't get rid of.
This question falls into Parent to child integration pattern so there are multiple solutions
1. aura:attribute:
Aura:Attribute is most commonly used communication pattern where parent component can initialize and pass value at later time.
<c:HelloWorkdChildCmp selectedaccount="{!acc.Id}" anotherattribute="VALUE" />
2. Aura:Method:
This enables you to directly call a method in a child component’s client-side controller instead of firing and handling a component event. Using simplifies the code needed for a parent component to call a method on a child component that it contains. It is done using aura:id.
Child Component
<aura:component>
<aura:method name="sampleMethod" action="{!c.doAction}"
description="Sample method with parameters">
<aura:attribute name="param1" type="String" default="parameter 1"/>
<aura:attribute name="param2" type="Object" />
</aura:method>
</aura:component>
Child component.js
({
doAction : function(cmp, event) {
var params = event.getParam('arguments');
if (params) {
var param1 = params.param1;
// add your code here
}
}
})
Parentcomponent.cmp
<aura:component>
<c:ChildComponent aura:id="compB"/>
<lightning:button label="Call child method" onclick="{! c.onAction}" />
</aura:component>
Parentcomponent.js
({
onAction : function(component, event, helper) {
var objCompB = component.find('compB');
objCompB.sampleMethod("Param1", "Param2");
}
})
3. Application event
Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.
applicationevent.evt
<!--c:aeEvent-->
<aura:event type="APPLICATION">
<aura:attribute name="message" type="String"/>
</aura:event>
Parent component
/* aeNotifierController.js */
{
fireApplicationEvent : function(cmp, event) {
// Get the application event by using the
// e.<namespace>.<event> syntax
var appEvent = $A.get("e.c:aeEvent");
appEvent.setParams({
"message" : "An application event fired me. " +
"It all happened so fast. Now, I'm everywhere!" });
appEvent.fire();
}
}
childcomponenthandler.js
/* aeHandlerController.js */
{
handleApplicationEvent : function(cmp, event) {
var message = event.getParam("message");
// set the handler attributes based on event data
cmp.set("v.messageFromEvent", message);
var numEventsHandled = parseInt(cmp.get("v.numEvents")) + 1;
cmp.set("v.numEvents", numEventsHandled);
}
}
Best Answer
A quick Action on Parent to create child records would work a charm. Also, we can prepopulate child record's fields from parent using
Predefined Field Values
which is somewhat similar to classic(pre-populating fields url hack)A tip from Salesforce docs says:
Src: https://help.salesforce.com/articleView?id=predefined_field_values.htm&type=5