You need to sign in to do that
Don't have an account?
akkk
I am getting Error when are click on the Next button for the Popup used the Contact Object
Hi All,
Please support i am getting the Recrod type of the Contact Object its find after that when am i clicking on the Next Button for Creating a Record facing the Error The Erro
the Component => <aura:component controller="recordtypeContact" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
<aura:attribute name="lstOfRecordType" type="String[]" />
<aura:attribute name="isOpen" type="boolean" default="false" />
<div class="slds-m-around--x-large">
<lightning:button label="Create a contact" onclick="{!c.openModal}" />
</div>
<!-- Model Box Start -->
<aura:if isTrue="{!v.isOpen}">
<div role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<div class="slds-modal__header">
<button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.closeModal}">
X<span class="slds-assistive-text">Cancel</span>
</button>
<h2 id="header43" class="slds-text-heading--medium">New Contact</h2>
</div>
<div class="slds-modal__content slds-p-around--medium">
<div class="slds-grid slds-wrap">
<div class="slds-size--1-of-2 slds-large-size--1-of-2">
<div class="slds-align--absolute-center">Select a Record Type</div>
</div>
<div class="slds-size--1-of-2 slds-large-size--1-of-2">
<ui:inputSelect aura:id="selectid">
<aura:iteration items="{!v.lstOfRecordType}" var="contact">
<ui:inputSelectOption text="{!contact}" label="{!contact}" />
</aura:iteration>
</ui:inputSelect>
</div>
</div>
</div>
<div class="slds-modal__footer">
<lightning:button class="slds-button slds-button--neutral" onclick="{!c.closeModal}">Cancel</lightning:button>
<lightning:button class="slds-button slds-button--brand" onclick="{!c.createRecord}">Next</lightning:button>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open"></div>
</aura:if>
</aura:component>
controller part=>
({
fetchListOfRecordTypes: function(component, event, helper) {
var action = component.get("c.fetchRecordTypeValues");
action.setCallback(this, function(response) {
component.set("v.lstOfRecordType", response.getReturnValue());
});
$A.enqueueAction(action);
},
createRecord: function(component, event, helper) {
component.set("v.isOpen", true);
var action = component.get("c.getRecTypeId");
var recordTypeLabel = component.find("selectid").get("v.value");
action.setParams({
"recordTypeLabel": recordTypeLabel
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var createRecordEvent = $A.get("e.force:createRecord");
var RecTypeID = response.getReturnValue();
createRecordEvent.setParams({
"entityApiName": 'Contact',
"recordTypeId": RecTypeID
});
createRecordEvent.fire();
} else if (state == "INCOMPLETE") {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Oops!",
"message": "No Internet Connection"
});
toastEvent.fire();
} else if (state == "ERROR") {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Error!",
"message": "Please contact your administrator"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
},
closeModal: function(component, event, helper) {
// set "isOpen" attribute to false for hide/close model box
component.set("v.isOpen", false);
},
openModal: function(component, event, helper) {
// set "isOpen" attribute to true to show model box
component.set("v.isOpen", true);
},
})
apex code =>
public class recordtypeContact {
public static Map<Id, String> recordtypemap {get;set;}
@AuraEnabled
public static List<String> fetchRecordTypeValues(){
List<Schema.RecordTypeInfo> recordtypes = Contact.SObjectType.getDescribe().getRecordTypeInfos();
recordtypemap = new Map<Id, String>();
for(RecordTypeInfo rt : recordtypes){
if(rt.getName() != 'Master')
recordtypemap.put(rt.getRecordTypeId(), rt.getName());
}
return recordtypemap.values();
}
@AuraEnabled
public static Id getRecTypeId(String recordTypeLabel){
Id recid = Schema.SObjectType.Contact.getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();
return recid;
}
}
Thanks
Akhan25
Please support i am getting the Recrod type of the Contact Object its find after that when am i clicking on the Next Button for Creating a Record facing the Error The Erro
the Component => <aura:component controller="recordtypeContact" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
<aura:attribute name="lstOfRecordType" type="String[]" />
<aura:attribute name="isOpen" type="boolean" default="false" />
<div class="slds-m-around--x-large">
<lightning:button label="Create a contact" onclick="{!c.openModal}" />
</div>
<!-- Model Box Start -->
<aura:if isTrue="{!v.isOpen}">
<div role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<div class="slds-modal__header">
<button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.closeModal}">
X<span class="slds-assistive-text">Cancel</span>
</button>
<h2 id="header43" class="slds-text-heading--medium">New Contact</h2>
</div>
<div class="slds-modal__content slds-p-around--medium">
<div class="slds-grid slds-wrap">
<div class="slds-size--1-of-2 slds-large-size--1-of-2">
<div class="slds-align--absolute-center">Select a Record Type</div>
</div>
<div class="slds-size--1-of-2 slds-large-size--1-of-2">
<ui:inputSelect aura:id="selectid">
<aura:iteration items="{!v.lstOfRecordType}" var="contact">
<ui:inputSelectOption text="{!contact}" label="{!contact}" />
</aura:iteration>
</ui:inputSelect>
</div>
</div>
</div>
<div class="slds-modal__footer">
<lightning:button class="slds-button slds-button--neutral" onclick="{!c.closeModal}">Cancel</lightning:button>
<lightning:button class="slds-button slds-button--brand" onclick="{!c.createRecord}">Next</lightning:button>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open"></div>
</aura:if>
</aura:component>
controller part=>
({
fetchListOfRecordTypes: function(component, event, helper) {
var action = component.get("c.fetchRecordTypeValues");
action.setCallback(this, function(response) {
component.set("v.lstOfRecordType", response.getReturnValue());
});
$A.enqueueAction(action);
},
createRecord: function(component, event, helper) {
component.set("v.isOpen", true);
var action = component.get("c.getRecTypeId");
var recordTypeLabel = component.find("selectid").get("v.value");
action.setParams({
"recordTypeLabel": recordTypeLabel
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var createRecordEvent = $A.get("e.force:createRecord");
var RecTypeID = response.getReturnValue();
createRecordEvent.setParams({
"entityApiName": 'Contact',
"recordTypeId": RecTypeID
});
createRecordEvent.fire();
} else if (state == "INCOMPLETE") {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Oops!",
"message": "No Internet Connection"
});
toastEvent.fire();
} else if (state == "ERROR") {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Error!",
"message": "Please contact your administrator"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
},
closeModal: function(component, event, helper) {
// set "isOpen" attribute to false for hide/close model box
component.set("v.isOpen", false);
},
openModal: function(component, event, helper) {
// set "isOpen" attribute to true to show model box
component.set("v.isOpen", true);
},
})
apex code =>
public class recordtypeContact {
public static Map<Id, String> recordtypemap {get;set;}
@AuraEnabled
public static List<String> fetchRecordTypeValues(){
List<Schema.RecordTypeInfo> recordtypes = Contact.SObjectType.getDescribe().getRecordTypeInfos();
recordtypemap = new Map<Id, String>();
for(RecordTypeInfo rt : recordtypes){
if(rt.getName() != 'Master')
recordtypemap.put(rt.getRecordTypeId(), rt.getName());
}
return recordtypemap.values();
}
@AuraEnabled
public static Id getRecTypeId(String recordTypeLabel){
Id recid = Schema.SObjectType.Contact.getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();
return recid;
}
}
Thanks
Akhan25
For firing an event, you need to register the same in your component as below:
<aura:registerEvent name="createRecord" type="c:createRecord"/>
Plz refer (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component_example.htm) for more details.
Acutally i used all thing but i am not able to slove the problem if you can test this code and reply me .
Plz refer below code for Task creation.
Just to mention that, toast doesn't work in lightning Apps, so try using this after creating a button/quick Action on Task object.