Thursday, 9 August 2012

Display Trigger names of selected objects

I am trying to explain to show the trigger names for selected object from picklist on visualforce page.

For this i used Dynamic apex and Apextrigger object.

public  class Dynamicobjectstriggerspageclass {
    public boolean ren { get; set; }
    public List<apextrigger> Triggerss { get; set; }
    public List<SelectOption> items { get; set; }
    public String selectedObj { get; set; }
    Public List<SelectOption> trignames{get;set;}
    public string selectedtrigname{get;set;}
    public Dynamicobjectstriggerspageclass (){
        Triggerss=new List<apextrigger>();
        trignames=new List<selectoption>();
        List<Schema.sObjecttype> lst= Schema.getGlobalDescribe().values();
        items= new List<SelectOption>();
        items.add(new SelectOption('','--None--'));
        for(Schema.sobjecttype s:lst){
            items.add(new SelectOption(string.valueOf(s),String.valueOf(s)));
    public void fun1(){
    public List<selectoption> getapextriggers(){
        if(selectedObj!=null && selectedObj!=''){
               Triggerss=new List<apextrigger>();
               trignames=new List<selectoption>();     
        trignames.add(new SelectOption('','--None--'));
        for(ApexTrigger aptrig:[select id,name from apextrigger where TableEnumOrId=:selectedObj]){
             trignames.add(new SelectOption(,;
        return trignames;      

Visualforce Page
<apex:page controller="Dynamicobjectstriggerspageclass">
<apex:form >
<apex:actionfunction name="fun" action="{!fun1}" rerender="trig"/>
  <apex:pageblock >
      <apex:outputText value="Object Name"/> &nbsp;
        <apex:SelectList value="{!selectedObj}" size="1" onchange="fun()">
          <apex:selectOptions value="{!items}"/>
         <apex:outputpanel >
                <apex:outputText value="Trigger Name:"/>&nbsp;
                <apex:selectList value="{!selectedtrigname}" id="trig" multiselect="false" size="1">
                                <apex:selectoptions value="{!apextriggers}"/>

No comments:

Post a Comment

Create Dynamic Picklists for Your Custom Components (design:component)

Hi, We can expose a component property as a picklist when the component is configured in the Lightning App Builder. The picklist’s value...