Navigate to a lightning component or standard record page creation based on Record Type in Salesforce Lightning
NewContact Lightning Component:
- <aura:component implements=“lightning:actionOverride, lightning:hasPageReference” >
- <aura:handler name=“init” value=“{!this}” action=“{!c.doInit}”/>
- </aura:component>
NewContact Lighting Component Controller:
- ({
- doInit: function(component, event, helper) {
- //Fetching Record Type Id
- var recordTypeId = component.get( “v.pageReference” ).state.recordTypeId;
- //If Sales Record Type is selected, open NewContactForm Lightning component
- //else open new Contact record standard page with record type applied
- if ( recordTypeId == ‘0123i000000ICssAAG’ ) {
- var evt = $A.get(“e.force:navigateToComponent”);
- evt.setParams({
- componentDef : “c:NewContactForm”,
- componentAttributes: {
- contactRecordTypeId : recordTypeId
- }
- });
- evt.fire();
- } else {
- var createRecordEvent = $A.get(“e.force:createRecord”);
- createRecordEvent.setParams({
- “entityApiName” : “Contact”,
- “recordTypeId” : recordTypeId
- });
- createRecordEvent.fire();
- }
- }
- })
NewContactForm Lightning Component:
- <aura:component implements=“flexipage:availableForRecordHome,force:hasRecordId” access=“global” >
- <aura:attribute name=“contactRecordTypeId” type=“String”/>
- <div class = “slds-box slds-theme_default”>
- Test
- </div>
- </aura:component>
Output:
This is not working when trying to create another record without refreshing the page.
Reproduce Steps:
1. Click on new to create a record
2. Save the record
3. Again go back to Contact tab and click on New button
4. You notice the page is blank and there is no popup
Azarudeen,
This is just an example.
You have to use $A.get('e.force:refreshView').fire(); in your case.
Where did you put it? it stays in an infinite loop..
also if i hit cancel in event $A.get("e.force:createRecord") i cannot return to the page where i was.
Don’t put it in init method