function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
si risi ri 

standard recordtype url in custom button


I have a rquirement that, by clickin on a custom button on Contract object  standard recordtypes like OP1,OP2,OP3 page selection should be opened. If we select OP1 recordtype from that picklist  related OP1 page record should be opened and vise versa. How can i acheive this,please help me, I'm new to coding.
Meghna Vijay 7Meghna Vijay 7
Hi Si ri,
 
/*** LibraryRecordTypePage.cmp *****/
<aura:component implements ="flexipage:availableForAllPageTypes" access="global" controller="LibraryRecordTypePageController">
    <aura:attribute name="libraryRecordTypeId" type="String" default="" />
    <aura:attribute name="recordTypeOptions" type="map" default="" />
    <aura:attribute name="recordId" type="String" default="" />
    <aura:attribute name="isRecordTypeSelected" type="Boolean" default="false" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:layout class="slds-m-left_small slds-size--1-of-2">
        <lightning:layoutItem flexibility="grow" size="8">
            <lightning:select label="" value="{!v.libraryRecordTypeId}" aura:id="recordTypeSelection" onchange="{!c.selectedRecordType}">
                <aura:iteration items="{!v.recordTypeOptions}" indexVar="key" var="recordType">
                    <option value="{!recordType.key}">{!recordType.value}</option>
                </aura:iteration>
            </lightning:select>
        </lightning:layoutItem>
    </lightning:layout>
    <aura:if isTrue="{!v.isRecordTypeSelected}">
        <lightning:layout>
            <lightning:layoutItem>
                
                <lightning:recordForm recordId="{!v.recordId}"
                                      objectApiName="Library_Items__c"
                                      layoutType="Full"
                                      mode="view"
                                      columns="2"/>
            </lightning:layoutItem>
        </lightning:layout>
    </aura:if>   
</aura:component>

/**** LibraryRecordTypePageController.js ****/
({
	doInit : function(component, event, helper) {
		var getRecordTypeNameAction = component.get("c.getRecordTypeName");
        getRecordTypeNameAction.setCallback(this,function(response){
            var state = response.getState();
            if(state === 'SUCCESS') {
                var recordTypeOpts = [];
                var recordTypes = response.getReturnValue();                
                for (var key in recordTypes) {
                    recordTypeOpts.push({value:recordTypes[key], key:key});
                }                
                component.set("v.recordTypeOptions", recordTypeOpts);
            }
        });        
        $A.enqueueAction(getRecordTypeNameAction);	
	},
    selectedRecordType : function(component) {
        component.set("v.isRecordTypeSelected", true);
        var libraryRecType = component.get("v.libraryRecordTypeId");
        var getLibraryItemAction = component.get("c.getLibraryItem");
        getLibraryItemAction.setParams({"libraryRecTypeId": libraryRecType});
        getLibraryItemAction.setCallback(this,function(response){
            var state = response.getState();
            if(state === 'SUCCESS') {
                var libraryItemList = response.getReturnValue();
                var recordId = '';
                for(var i=0; i< libraryItemList.length; i++) {
                    recordId = libraryItemList[i].Id;
                } 
                component.set("v.recordId", recordId);
                /*for (var key in recordTypes) {
                    recordTypeOpts.push({value:recordTypes[key], key:key});
                }                
                component.set("v.recordTypeOptions", recordTypeOpts);*/
            }
        });
        $A.enqueueAction(getLibraryItemAction);
    }
})

/*** LibraryRecordTypePageController ***/
public class LibraryRecordTypePageController {
	
    @AuraEnabled
    public static Map<String,String> getRecordTypeName() {
        Map<String,String> mapOfRecordTypeIdWithRecordTypeName = new Map<String,String>(); 
        Schema.DescribeSObjectResult librarySObjectRes = Library_Items__c.SObjectType.getDescribe();
        for(String recordTypeId : librarySObjectRes.getRecordTypeInfosById().keyset()) {
            if(librarySObjectRes.getRecordTypeInfosById().get(recordTypeId).getName() != 'Master') {
                String recordTypeName = librarySObjectRes.getRecordTypeInfosById().get(recordTypeId).getName();
                mapOfRecordTypeIdWithRecordTypeName.put(recordTypeId,recordTypeName);
            }
        }
        return mapOfRecordTypeIdWithRecordTypeName;
    }
    
    @AuraEnabled
    public static List<Library_Items__c> getLibraryItem(String libraryRecTypeId) {
        return [SELECT Id FROM Library_Items__c WHERE RecordTypeId =: libraryRecTypeId];
    }
}

User-added image

Hope it helps, if it does mark it as solved to help others too.

Thanks
si risi ri
Hi Meghna,
                 Actually the requirement should be created through Apex/visualforce developement. Thanks for your reply.