In this example we will fetch Picklist field “Industry” values from “Account” object and set in ui:inputSelect on Lightning Component.
Apex Class:
public class GetPicklistValuesController {
@AuraEnabled
public static List <String> getPicklistValues(sObject obj, String fld) {
List <String> pList = new list <String>();
//Get the object type of the SObject.
Schema.sObjectType objType = obj.getSObjectType();
//Describe the SObject using its object type.
Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
//Get a map of fields for the SObject
Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
//Get the list of picklist values for this field.
List<Schema.PicklistEntry > values = fieldMap.get(fld).getDescribe().getPickListValues();
//Add these values to the selectoption list.
for (Schema.PicklistEntry a: values) {
pList.add(a.getValue());
}
pList.sort();
return pList;
}
}
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;
}
}
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject