• Tim Johnson-Reynolds 8
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi
I am using a dynamic component on a visualforce page to allow for a configurable layout defined by custom metadata types. This is my get class in my controller 
 
public Component.Apex.PageBlockSection getDynamicPageSection(){
        
        Map<String, Schema.SObjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
        
        Component.Apex.PageBlockSection pageBlock = new Component.Apex.PageBlockSection();
        pageBlock.columns=1;
        
        list<Sales_Tool_Page_Sections__mdt> sectionsfields = new list<Sales_Tool_Page_Sections__mdt>([Select id, Label, order__c, (Select id, Field_Api_Name__c, order__c, required__c from Sales_Tool_Section_Fields__r order by Order__c asc ) From Sales_Tool_Page_Sections__mdt where Sales_Tool_Request_Type__c =:strType order by Order__c asc]);
        
        for(Sales_Tool_Page_Sections__mdt ps:sectionsfields){
            system.debug('Page Section Order: ' + ps.order__c);
            Component.Apex.PageBlockSection pbs = new Component.Apex.PageBlockSection();
			pbs.title = ps.label;   
            
            
            for (Sales_Tool_Section_Field__mdt f:ps.Sales_Tool_Section_Fields__r){
            	system.debug('Order: ' + f.order__c);
                if(caseFields.containskey(f.Field_Api_Name__c)){
                    Component.Apex.InputField newfield = new Component.Apex.InputField();

                    newfield.expressions.value = '{!stCase.' + f.Field_Api_Name__c + '}';
              
                    
                    system.debug(newfield.expressions.value);
                    newfield.id = f.Field_Api_Name__c;
                    newfield.required = f.required__c;
                    
                    Component.Apex.ActionRegion ar = new Component.Apex.ActionRegion();
                    Component.Apex.ActionSupport asup = new Component.Apex.ActionSupport();
                    asup.event='onchange';
                    asup.expressions.action='{!fieldCheck}';
                    ar.childcomponents.add(asup);
					newfield.childcomponents.add(ar);
                    
                    pbs.childComponents.add(newfield);
                }
            }
            
            
            pageBlock.childComponents.add(pbs);
        }
       
       
        Return pageBlock;
        
    }

And this is the component on the page:
 
<apex:dynamicComponent id="dynamicSection" componentValue="{!dynamicPageSection}" rendered="{!strTool!=null&&strType!=null&&casenum==null}"/>

The component is rendered following selection of other fields defined on the page. It builds the dynamic page sections correctly and they function normally apart from the fact that the values entered into the dynamic input fields don't appear to be saving the values to the sobject and field defined in the value expression. On inserting the record I just have blank values. 

I have tried all sorts of things to determine the cause of this, and this is my first attempt at dynamic components. Any help to fix this issue would be greatly appreciated. 

Thanks
I'll preface this with the fact I am new to visualforce.

Is it possible to display picklist values on a visualforce page by recordtype using the standard controller (and optionally adding an extension)?

Currently picklist values load based on my default record type.

I would like to load the correct ones on the visualforce page, and additionally would like the option to change the record type on the visualforce page and have the picklists update with the correct options

I would like to do this using standard functionality ideally rather than load options via apex, or I would like to know that what I am trying to achieve is not possible.

Thanks

Tim

 
Hi
I am using a dynamic component on a visualforce page to allow for a configurable layout defined by custom metadata types. This is my get class in my controller 
 
public Component.Apex.PageBlockSection getDynamicPageSection(){
        
        Map<String, Schema.SObjectField> caseFields = Schema.SObjectType.Case.fields.getMap();
        
        Component.Apex.PageBlockSection pageBlock = new Component.Apex.PageBlockSection();
        pageBlock.columns=1;
        
        list<Sales_Tool_Page_Sections__mdt> sectionsfields = new list<Sales_Tool_Page_Sections__mdt>([Select id, Label, order__c, (Select id, Field_Api_Name__c, order__c, required__c from Sales_Tool_Section_Fields__r order by Order__c asc ) From Sales_Tool_Page_Sections__mdt where Sales_Tool_Request_Type__c =:strType order by Order__c asc]);
        
        for(Sales_Tool_Page_Sections__mdt ps:sectionsfields){
            system.debug('Page Section Order: ' + ps.order__c);
            Component.Apex.PageBlockSection pbs = new Component.Apex.PageBlockSection();
			pbs.title = ps.label;   
            
            
            for (Sales_Tool_Section_Field__mdt f:ps.Sales_Tool_Section_Fields__r){
            	system.debug('Order: ' + f.order__c);
                if(caseFields.containskey(f.Field_Api_Name__c)){
                    Component.Apex.InputField newfield = new Component.Apex.InputField();

                    newfield.expressions.value = '{!stCase.' + f.Field_Api_Name__c + '}';
              
                    
                    system.debug(newfield.expressions.value);
                    newfield.id = f.Field_Api_Name__c;
                    newfield.required = f.required__c;
                    
                    Component.Apex.ActionRegion ar = new Component.Apex.ActionRegion();
                    Component.Apex.ActionSupport asup = new Component.Apex.ActionSupport();
                    asup.event='onchange';
                    asup.expressions.action='{!fieldCheck}';
                    ar.childcomponents.add(asup);
					newfield.childcomponents.add(ar);
                    
                    pbs.childComponents.add(newfield);
                }
            }
            
            
            pageBlock.childComponents.add(pbs);
        }
       
       
        Return pageBlock;
        
    }

And this is the component on the page:
 
<apex:dynamicComponent id="dynamicSection" componentValue="{!dynamicPageSection}" rendered="{!strTool!=null&&strType!=null&&casenum==null}"/>

The component is rendered following selection of other fields defined on the page. It builds the dynamic page sections correctly and they function normally apart from the fact that the values entered into the dynamic input fields don't appear to be saving the values to the sobject and field defined in the value expression. On inserting the record I just have blank values. 

I have tried all sorts of things to determine the cause of this, and this is my first attempt at dynamic components. Any help to fix this issue would be greatly appreciated. 

Thanks