function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sandeep varsandeep var 

Dynamic Component - Unable to use Command link with field from list as value.

hi,

I am creating pageblock tables dynamically based on number of record types, so i used dynamic component.

can somebody help me in using a command link in the page block table using dynamic component.. here is my code snippet..

how can i give command link a dynamic value   (when i tried using link this Comlink.value = '{!d.FirstName}' it is using as a string instead of the value of the  {!d.FirstName}'.


<apex:page showheader="false" standardController="Lead" extensions="RealtimeLeadDashboard">
<apex:pagemessages ></apex:pagemessages>
<apex:form >
  <apex:actionPoller action="{!refreshDocs}" rerender="docsTable" interval="5"/>
    <apex:outputPanel id="docsTable">
        <apex:dynamicComponent componentValue="{!Pageblock}"/>
    </apex:outputPanel>
          <apex:outputPanel rendered="{!refreshPage}">
   <script>
      window.top.location='/{!LeadID}';
   </script>
</apex:outputPanel>

</apex:form>
</apex:page>


public Component.Apex.PageBlock getPageblock()
    {
        Component.Apex.PageBlock PG = new Component.Apex.PageBlock();
        // get the queue id of the real time queue
        Group objQueue = [SELECT CreatedById,CreatedDate,DeveloperName,DoesIncludeBosses,DoesSendEmailToMembers,Email,Id,LastModifiedById,LastModifiedDate,Name,OwnerId,RelatedId,SystemModstamp,Type FROM Group WHERE Name = 'Real Time Queue' limit 1];
        String Queueid=objQueue.Id;
        // getting the record type from campaign object.       
        Map<String,String> RecordMap = new Map<String,String>();
        for(Campaign cam : [Select Id, Record_Type__c FROM Campaign]) {
        RecordMap.put(cam.Record_Type__c, cam.id);
        }
        List<String> keys = new List<String>(RecordMap.keySet());
        keys.sort();
        system.debug('*** TEST list***'+keys);
        for(integer i=0;i<keys.size();i++){
        String Objch = keys.get(i);
        list<lead> RealLeads=[Select id,FirstName,LastName,Company,CreatedDate,Time_In_Queue_Mins__c,County__c,Date_of_Birth__c,Channel_Code__c from Lead Where OwnerId =: Queueid AND Channel_Code__c=:Objch  ORDER BY CreatedDate ASC NULLS LAST limit 10];     
        if(RealLeads.size()!=0){
        Component.Apex.PageBlock pageBlock = new Component.Apex.PageBlock();
        pageBlock.title=Objch ;
        Component.Apex.PageBlockTable DT = new Component.Apex.PageBlockTable();
        DT.value =RealLeads;
        DT.var = 'd';
        Component.Apex.Column Columnvalue1 = new Component.Apex.Column();
        Component.Apex.Column Columnvalue2 = new Component.Apex.Column(headervalue='Name');
        Component.Apex.commandLink Comlink = new Component.Apex.commandLink ();
        Comlink.value = '{!d.FirstName}'; 
        Comlink.expressions.action = '{!goLead}';
        Columnvalue2.childComponents.add(Comlink);
        Component.Apex.Column Columnvalue3 = new Component.Apex.Column();
        Component.Apex.Column Columnvalue4 = new Component.Apex.Column();
        Component.Apex.Column Columnvalue5 = new Component.Apex.Column();
        Columnvalue3.expressions.value='{!d.Time_In_Queue_Mins__c}';
        Columnvalue1.expressions.value='{!d.County__c}';
        Columnvalue4.expressions.value='{!d.Date_of_Birth__c}';
        Columnvalue5.expressions.value='{!d.Channel_Code__c}';
        PG.childComponents.add(pageBlock);
        pageBlock.childComponents.add(DT);
        DT.childComponents.add(Columnvalue2);
        DT.childComponents.add(Columnvalue1);
        DT.childComponents.add(Columnvalue4);       
        DT.childComponents.add(Columnvalue5);
        DT.childComponents.add(Columnvalue3);
        }
       
    }  
        return PG;
    }

Thanks,
Sandeep.
Ashish_SFDCAshish_SFDC
Hi Sandeep, 


I think the general steps to allowing users to select a record type and then being taken to a custom Visualforce page are:
Present a native Record Type picklist to the user
Allow the user to click an apex:commandButton or apex:commandLink to go to the edit page
Construct a PageReference[1] to the custom Visualforce edit page
Add the selected Record Type ID as a parameter to the PageReference
Return the PageReference, including the Record Type ID parameter
Read the parameter on the receiving page and do what you need there

Here are two sample pages, SelectTransactionRecordType[2] and EditTransaction[3] with a simple controller[4] behind them demonstrating this concept.
[1]: PageReference (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm)
[2]: SelectTransactionRecordType (http://pastebin.com/x2H4AH0v)
[3]: EditTransaction (http://pastebin.com/Uk6HsecN)
[4]: a simple controller (http://pastebin.com/zZp64BDH)

https://developer.salesforce.com/forums?id=906F00000009F1MIAU


You can use the key prefix in conjunction with the RecordType parameter in a custom controller or extension. The basic idea is below. The developer name should be stable and not change between orgs. Also, once in production the ID doesn't change in sandboxes refreshed from production, so if you are already working with a record type that is in production you could use the ID.

You can adapt this code to be more specific or to not be an extension. The main thing is the format of the URL and the idea that the RecordType ID is retrieved in a relatively stable way.

http://salesforce.stackexchange.com/questions/7996/commandlink-or-commandbutton-as-new-button-to-create-a-new-record-of-a-specific


Regards,
Ashish