+ Start a Discussion
siva@shiva.comsiva@shiva.com 

can we pass object dynamically from vf to apex.............?

can we pass object dynamically from vf to apex...?

like

.....

[select id,name from account]

 

insted of account object we are going pass objects //

 

 

is it possible...?

Noam.dganiNoam.dgani

What do you mean by pass from vf to apex?

 

what are you trying to do?

ManjunathManjunath

Hi,

 

You mean to say, if I select a object name in my vf page based on that in apex controller you are going to write a dynamic query. 

 

You can do this, but all the object should have same fields since the query statement is same.

 

Regards,

Manjunath

 

 

siva@shiva.comsiva@shiva.com

<apex:page controller="ApprovalEnabledObjectsController">  
<apex:form >  
<apex:pageBlock >
<apex:pageBlockButtons location="top">
    
       <apex:selectlist multiselect="false" size="1" value="{!sendobj}">  
        <apex:selectoptions value="{!supportedObject}">  
    </apex:selectoptions>
    </apex:selectlist>
    <apex:commandButton action="{!Go}" value="Go"/>  
    </apex:pageBlockButtons>
    <apex:pageBlockTable value="{!record}" var="r">
    
    
    </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>  
</apex:page>

 

 

public class ApprovalEnabledObjectsController  
{
 
   public String sendobj { get; set; }
 
    public list<Schema.SObjectType> getRecord() {
     list<Schema.SObjectType> obj=new list<Schema.SObjectType>();
       List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();      
       for(Schema.SObjectType f : gd)
       {
         string s=f.getDescribe().getLabel() ;
         
         if(sendobj==s)
         {
           
           system.debug('************'+sendobj);
         }
        
       }
        
     
        return null;
    }


    public PageReference Go() {
        return null;
    }

 
    //List displayed on UI  
    public List<selectoption> supportedObject {get; set;}  
      
    //Constructor  
    public ApprovalEnabledObjectsController()  
    {  
        //Initialize  
        supportedObject = new List<selectoption>() ;  
          
        //Get only reference to objects  
        for(Schema.SObjectType item : ProcessInstance.TargetObjectId.getDescribe().getReferenceTo())  
        {  
            //Excluding custom setting objects  
            if(!item.getDescribe().CustomSetting)  
            {  
                //Adding to list
                
                supportedObject.add(new SelectOption(item.getDescribe().getLocalName().toLowerCase() , item.getDescribe().getLabel() ));
                
                 
                
               for(selectoption sp:supportedobject)
               {
                 
               }
            }  
        }  
          
    }
      public class wrapper{
       public String sendobj { get; set; }
 
        public wrapper(String sendobj)
        {
            this.sendobj=sendobj;
            
        }
    }  
}

 

----------------------i want to pass objects names dynamically