+ Start a Discussion
sivassivas 

Dynamic Output Links

 

I have a custom Script object which has lookup with Account. Script object has 'Script_Category', 'Script_Type' and 'Script_Text' fields. I have created a button on the Account object which on clicking opens up a visualforce page which displays DISTINCT 'Script_Categories' as output links. Once you click any of the output link it displays its corresponding 'Script_Types' and then on clicking one of the 'Script_Types' it should display the respective 'Script_Text'. I managed to display 'Script_Category' but couldn't figure out how to deal with output links. I am including my code below. Any help. 

 

I created a custom objects Script which has lookup to Account. Script object has 'Script_Category' and 'Script_Text' fields. I have created a button on the Account object which on clicking opens up a visualforce page which displays DISTINCT 'Script_Categories' as output links related to that Account. Once you click any of the output link it displays its corresponding 'Script Names' associated with that 'Script_Category' (of course related to that particular account) as links or buttons and then on clicking one of the 'Script Names' it should display the respective 'Script_Text'. I managed to display 'Script_Category' but couldn't figure out how to deal with output links. I am including my code below. 

 

 

<apex:page standardController="Account" extensions="distinctcategory">
  <apex:pageBlock title="Script Category">
     <apex:dataList value="{!Categories}" var="cat" type="circle"> 
        <apex:outputLink > {!cat} </apex:outputLink> 
     </apex:dataList>
  </apex:pageBlock>  
</apex:page>

 

 

public class distinctcategory {
	
	Account acc;
	Account accRec;
	list<Script__c> scr = new list<Script__c>(); 
	String[] sc = new list<String>();
	
	/*################ Constructor #####################*/
	
	public distinctcategory(ApexPages.StandardController stdcontroller){
		getCategories();
	}
	
	/*############## Returns Script Categories ##############*/
	
	public String[] getCategories(){
		
		scr = [select Name, Script_Category__c, Script_Text__c from Script__c 
	    	   where Script__c.Account__c=:ApexPages.currentPage().getParameters().get('id')];
	    list<String> distinct = new list<String>(); 
	    
	    for(integer i=0; i<scr.size(); i++){
	    	distinct.add(scr[i].Script_Category__c);
	    }
	 	 
		list<String> sc = new list<String>();
		sc=distinctcategories(distinct);
		return sc;
    }
    
    /*############# Returns Distinct Script Categories #################*/
    
    public list<String> distinctcategories(list<String> distinct){
    	list<String> distinctcate = new list<String>();
    	
    	integer sizetest = distinct.size();
    	system.debug('Size is >>>>>>>'+sizetest);
    	
    	for(String cate : distinct){
    		Boolean found = false;
    		
    		for(integer i=0; i<distinctcate.size(); i++){
    			if(cate.equals(distinctcate[i])){
    				found = true;
    				break;
    			}
    		}
			if(!found){
    			distinctcate.add(cate);
    		}
        }
    	return distinctcate;
    }

 

Thanks in advance.

 

 

 

 

Teja