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
Vanitha ManiVanitha Mani 

how to open the page in subtab in lightning console with some conditions

Hi,

I have a apex command button when it is clicked it check for condition in controller if false it throws exception in same page and if true it opens the another page but it overrides the same page..i need to open that page in subtab ..
Can anyone help me modify my code based on conditions.
Controller:
public PageReference clonePackageToChangeRequests() {
        
        Savepoint sp = Database.setSavepoint();
        try {
            Set<ID> crIds = new Set<ID>();
            for (SelectableChangeRequest record : changeRequests) {
                 
            if(record.selected && record.obj.Customer_Packages__r.size() > 0 ) { //TKT-1239114
              
                
              throw new CloneChangeRequestException(EXCEPTION_NAME);
                
               
            }else if (record.selected) {
               
                   crIds.add(record.obj.Id);
                
                    
                }
            }

            if (crIds.size() > 0) {
               
                return handleSuccess(SVC_CR_Package_Service.clonePackage(crIds, crPackage.Id));
               
            }
        } catch (Exception e) {
            Database.rollback(sp);
            ApexPages.addMessage(SVC_ErrorHandler.logAndConvertToApexMessage(e));
        }

        return null;
    }
  private PageReference redirect(ID recordId) {
       
        PageReference retURL = new PageReference('/' + recordId);
       
        retURL.setRedirect(true);
         
        return retURL;
       
 
           }
VF page:
<apex:commandButton value="Back" action="{!cancel}" immediate="true"/>
                <apex:commandLink action="{!clonePackageToChangeRequests}" >
       <apex:commandButton value="Clone Package To Selected CRs" />
</apex:commandLink>