You need to sign in to do that
Don't have an account?
Leticia Monteiro Freitas 4
Use a standard action in lightinig page.
Hello,
I need to create a lightining component with a button that calls a standard action to create a case. Is there possible?
I need to create a lightining component with a button that calls a standard action to create a case. Is there possible?
Yes, You can create using force:createRecord event JS Controller.
Please find below link for the reference, Hope it helps!!
https://developer.salesforce.com/docs/component-library/bundle/force:createRecord/documentation
Cheers,
Durgapaavan
You can use the force:createRecord Event with Quick Action for this:
http://www.sfdcbox.com/2018/07/sneaky-smart-quick-action-to-open.html
http://amulhai.blogspot.com/2018/12/lightning-component-button-create-child.html
http://www.infallibletechie.com/2017/11/forcecreaterecord-example-in-salesforce.html
Thanks,
Maharajan.C
Also, the event has additional option to pre populate the values in the standard modal.
Cheers,
Durgapaavan
Hope it resolves the error!.
Cheers
Durgapaavan
In that way that seets me for a specifc type, the screen for choose doesen show.
Cheers
Durgapaavan
I thought you need to populate record type value, Sorry for misunderstanding!!.
record type selection is not available by default using force:createRecord Event and you need to implement extra stuff to provide record type selection. Please find below devloper forum discussion thread for the same.
https://salesforce.stackexchange.com/questions/263875/recordtype-selection-list-not-available-in-a-gete-forcecreaterecord/263892
Hope it helps!!.
Cheers
Durgapaavan
https://success.salesforce.com/ideaView?id=0873A000000CR9sQAG
If you find answer helpful, Please Mark as best answer.
Cheers
Durgapaavan
Please use the below code reference:
1. You Need to create the Apex Class to Fetch the Record Types.
2. On Component load ( Init ) call the Apex method and display the RT.
3. Based on the Selected Record Type you have to pass the parameter in CreateRecord Event.
Apex Class :
public class RecordTypeSelector{
public static Map<Id, String> recordtypemap;
@AuraEnabled
public static Map<Id, String> fetchRecordTypeValues(String objectName){
List<Schema.RecordTypeInfo> recordtypes = Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfos();
recordtypemap = new Map<Id, String>();
for(RecordTypeInfo rt : recordtypes){
recordtypemap.put(rt.getRecordTypeId(), rt.getName());
}
return recordtypemap;
}
}
====================
Component :
<aura:component controller="RecordTypeSelector" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="lstOfRecordType" type="String[]" />
<aura:attribute name="mapOfRecordType" type="Map" />
<aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
<lightning:layout multipleRows="true" horizontalAlign="center">
<lightning:layoutItem flexibility="auto" padding="around-small"
size="12"
largeDeviceSize="12"
mediumDeviceSize="12"
smallDeviceSize="12">
<lightning:formattedText value="Select Case Record Type" />
</lightning:layoutItem>
<lightning:layoutItem flexibility="auto" padding="around-small"
size="12"
largeDeviceSize="12"
mediumDeviceSize="12"
smallDeviceSize="12">
<!-- select to hold all available record type names list -->
<lightning:select aura:id="recordTypePickList" name="selectRecordType" label="Select a Record Type">
<option value="" text="Select Record Type"/>
<aura:iteration items="{!v.lstOfRecordType}" var="item">
<option value="{!item}" text="{!item}"/>
</aura:iteration>
</lightning:select>
</lightning:layoutItem>
<lightning:layoutItem flexibility="auto" padding="around-small"
size="3"
largeDeviceSize="3"
mediumDeviceSize="3"
smallDeviceSize="6">
<lightning:button variant="brand" label="Next" onclick="{!c.createRecord}"/>
</lightning:layoutItem>
<lightning:layoutItem flexibility="auto" padding="around-small"
size="3"
largeDeviceSize="3"
mediumDeviceSize="3"
smallDeviceSize="6">
<lightning:button variant="neutral" label="Cancel" onclick="{!c.closeModal}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
====================
JS Controller:
({
fetchListOfRecordTypes: function(component, event, helper) {
var action = component.get("c.fetchRecordTypeValues");
action.setParams({
"objectName" : "Case"
});
action.setCallback(this, function(response) {
var mapOfRecordTypes = response.getReturnValue();
component.set("v.mapOfRecordType", mapOfRecordTypes);
var recordTypeList = [];
//Creating recordTypeList from retrieved Map
for(var key in mapOfRecordTypes){
recordTypeList.push(mapOfRecordTypes[key]);
}
if(recordTypeList.length == 0){ //Object does not have any record types
//Close Quick Action Modal here
helper.closeModal();
//Calling CreateRecord modal here without providing recordTypeId
helper.showCreateRecordModal(component, "", "Case");
} else{
component.set("v.lstOfRecordType", recordTypeList);
}
});
$A.enqueueAction(action);
},
createRecord: function(component, event, helper, sObjectRecord) {
var selectedRecordTypeName = component.find("recordTypePickList").get("v.value");
if(selectedRecordTypeName != ""){
var selectedRecordTypeMap = component.get("v.mapOfRecordType");
var selectedRecordTypeId;
//finding selected recordTypeId from recordTypeName
for(var key in selectedRecordTypeMap){
if(selectedRecordTypeName == selectedRecordTypeMap[key]){
selectedRecordTypeId = key;//match found, set value in selectedRecordTypeId variable
break;
}
}
//Close Quick Action Modal here
helper.closeModal();
//Calling CreateRecord modal here without providing recordTypeId
helper.showCreateRecordModal(component, selectedRecordTypeId, "Case");
} else{
alert('You did not select any record type');
}
},
/*
* closing quickAction modal window
* */
closeModal : function(component, event, helper){
helper.closeModal();
}
})
=====================
JS Helper:
({
showCreateRecordModal : function(component, recordTypeId, entityApiName) {
var createRecordEvent = $A.get("e.force:createRecord");
if(createRecordEvent){ //checking if the event is supported
if(recordTypeId){//if recordTypeId is supplied, then set recordTypeId parameter
createRecordEvent.setParams({
"entityApiName": entityApiName,
"recordTypeId": recordTypeId,
});
} else{//else create record under master recordType
createRecordEvent.setParams({
"entityApiName": entityApiName,
});
}
createRecordEvent.fire();
} else{
alert('This event is not supported');
}
},
closeModal : function(){
var closeEvent = $A.get("e.force:closeQuickAction");
if(closeEvent){
closeEvent.fire();
} else{
alert('force:closeQuickAction event is not supported in this Ligthning Context');
}
},
})
https://sfdcfacts.com/apex/record-type-selector-quick-action-in-lightning/
Thanks,
Maharajan.C
Hi @ Durga
I am using e.force:createRecord in my component to override standard button but when I click on new button my background component changes. Can you tell me how can I set same background.