Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<aura:component controller="SkRecordTypeSelectionController">
<aura:attribute name="objType" type="String" required="true" default="Opportunity"/>
<aura:attribute name="selectedRecordType" type="String"/>
<aura:attribute name="recordTypeList" type="Object[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
<div role="dialog" tabindex="-1" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<div class="slds-modal__header">
<lightning:buttonIcon class="slds-modal__close" iconName="utility:close" size="large"
variant="bare-inverse" alternativeText="Close" onclick="{!c.defaultCloseAction}" />
<h2 id="header43" class="slds-text-heading--medium">Please select record Type</h2>
</div>
<div class="slds-modal__content slds-p-around--medium">
<div class="slds-align--absolute-center">
<div class="slds-p-top--small slds-p-bottom--small" >
<fieldset class="slds-form-element">
<div class="slds-form-element__control">
<aura:iteration items="{!v.recordTypeList}" var="item">
<label class="slds-radio slds-p-top--small">
<tr>
<td>
<ui:inputRadio name="benefits" change="{!c.onChange}" text="{!item.recordTypeId}" value="true"/>
<span class="slds-radio--faux"></span>
</td>
<td>
<span class="slds-form-element__label">{!item.recordTypeLabel}</span>
</td>
</tr>
</label>
</aura:iteration>
</div>
</fieldset>
</div>
</div>
</div>
<div class="slds-modal__footer">
<lightning:button label="Cancel" variant="neutral" onclick="{!c.defaultCloseAction}"/>
<lightning:button label="Continue" variant="brand" onclick="{!c.onconfirm}"/>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open"></div>
</aura:component>
({
doInit : function(component,event,helper){
// alert('do init get called');
helper.callToServer(
component,
"c.findRecordTypes",
function(response) {
//alert(JSON.parse(response));
var jsonObject=JSON.parse(response);
component.set('v.recordTypeList',jsonObject);
component.set('v.selectedRecordType',jsonObject[0].recordTypeId);
},
{objName: component.get('v.objType')}
);
},
onChange : function(component, event, helper) {
var value = event.getSource().get("v.text");
component.set('v.selectedRecordType', value);
},
defaultCloseAction : function(component, event, helper) {
//$A.util.addClass(component, "hideModal");
$A.util.addClass(component, "slds-hide");
},
onconfirm : function(component, event, helper){
//alert('confirm get called');
var selectedRecType=component.get('v.selectedRecordType');
alert('selected recordtype:'+selectedRecType);
}
})
({
callToServer : function(component, method, callback, params) {
//alert('Calling helper callToServer function');
var action = component.get(method);
if(params){
action.setParams(params);
}
//alert(JSON.stringify(params));
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
//alert('Processed successfully at server');
callback.call(this,response.getReturnValue());
}else if(state === "ERROR"){
alert('Problem with connection. Please try again.');
}
});
$A.enqueueAction(action);
}
})
public with sharing class SkRecordTypeSelectionController {
@AuraEnabled
public static string findRecordTypes(string objName){
string returnString='';
string queryString='Select id, name from RecordType where sobjectType =: objName and IsActive=true';
List<sobject> recordList= Database.query(queryString);
List<RecordTypeWrapper> wrapperList=new List<RecordTypeWrapper>();
for(sobject sb : recordList) {
RecordTypeWrapper rw=new RecordTypeWrapper();
rw.recordTypeLabel=string.valueof(sb.get('name'));
rw.recordTypeId=string.valueof(sb.get('id'));
wrapperList.add(rw);
}
returnString= JSON.serialize(wrapperList);
system.debug('*****'+returnString);
return returnString;
}
public class RecordTypeWrapper{
public string recordTypeLabel{get;set;}
public string recordTypeId{get;set;}
}
}
<aura:application extends="force:slds">
<c:SkDemoRecordtTypeSelector objType="Opportunity"/>
</aura:application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment