Tag Archives: Visualforce Page

How to open a new Tab using PageReference in apex class?

We can use apex:commandLink to redirect a visualforce page in a new Tab URL using PageReference in apex class.

Sample Code:

VF Page:

<apex:page controller="SampleleRedirect">
	<apex:form >
		<apex:pageblock >
			<apex:commandlink action="{!redirect}" target="_blank">
				<apex:commandButton value="Open in New Tab"/>
			</apex:commandLink>
		</apex:pageblock>
	</apex:form>
</apex:page> 

Apex Controller:

public class SampleleRedirect {   

	public SampleleRedirect() {
	
	}

	public pageReference redirect() {
		PageReference pageRef = new PageReference('http://www.biswajeetsamal.com');
		pageRef.setRedirect(true);
		return pageRef;
	}            
}

Dynamically Add Delete Rows In PageBlockTable Visualforce Page

Apex Class:

public class DemoController {
    
    Public List<Account> accList {get;set;}
    public Integer rowIndex {get;set;}
    
    public DemoController(){
        accList = new list<Account>();
        accList.add(new Account());
    }
    
    public void addRow(){
        accList.add(new Account());
    }
    
    public pagereference saveAccount(){
        Insert accList;
        return null;
    }
    
    public PageReference deleteRow(){
        rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
        accList.remove(rowIndex);
        return null;
    }
}

Visualforce Page:

<apex:page controller="DemoController">
    <apex:form id="fm">
        <apex:pageBlock id="pb">
            <apex:variable var="rowNumber" value="{!0}"/> 
            <apex:pageBlockTable value="{!accList}" var="ac">
                <apex:column headerValue="Account Name">
                    <apex:inputField value="{!ac.Name}"/>
                </apex:column>
                <apex:column headerValue="Account Number">
                    <apex:inputField value="{!ac.AccountNumber}"/>
                </apex:column>
                <apex:column headerValue="Account Type">
                    <apex:inputField value="{!ac.Type}"/>
                </apex:column>
                <apex:column headerValue="Industry">
                    <apex:inputField value="{!ac.Industry}"/>
                </apex:column>
                <apex:column headerValue="Action" >
                    <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb">
                        <apex:param name="rowIndex" value="{!rowNumber}"/>
                    </apex:commandButton>
                    <apex:variable var="rowNumber" value="{!rowNumber}"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Add Row" action="{!addRow}"/>
                <apex:commandButton value="Save Accounts" action="{!saveAccount}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output:

Display The Required Bar For apex:selectList in Visualforce Page

Sample Code:

<apex:pageBlockSectionItem>
    <apex:outputLabel value="Group" for="groupSelectList"/>
    <apex:outputPanel styleClass="requiredInput" layout="block">
        <apex:outputPanel styleClass="requiredBlock" layout="block"/>
        <apex:selectList value="{!selectedGroup}" id="groupSelectList" size="1" required="true">
            <apex:selectOptions value="{!groupOptions}"/>
        </apex:selectList>
    </apex:outputPanel>
</apex:pageBlockSectionItem>

Related list Button Edit/Delete/View is not working in VF Page on Service Cloud Console

If showHeader="false" in VF Page, the related list Button Edit/Delete/View won’t work on Service Cloud Console.
When showHeader is set to false, some important JS files needed for the service cloud console to function properly will not be loaded, and hence you may see some issues. It is recommended to leave showHeader as true while using in the service cloud console.