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
learnSFlearnSF 

how to add "Personal Tagging" or "Public Tagging" functionality in visual force?

Hi,
 
I would like to add "Personal Tagging" or " Public Tagging" in visual force page layout.
 
Can it be possible? do we have any syntex or pageblock section or header section with Tagging enable?
 
 
Thanks in advance.
 
mtbclimbermtbclimber
There are no standard Visualforce components that natively support tagging. However, in the Winter '09 release tagging is exposed in the API and thus Apex and thus you can provide tagging features in your Visualforce pages as you see fit.

More about the winter '09 release here. There's also a webinar coming up that you might want to check out.
Eva DeLoriolEva DeLoriol

I have written code for our Lead VF Pages to display and edit/add Tags using a Component and Apex.  It's probably not the most graceful solution, and there are some ToDos, but it works. 

 

This is the Apex Component code:

<apex:component controller="getTagRecord">
<!--Tagging Header-->
<br/><br/>
<div class="bPageTitle">
<div class="ptBody">
<div id="section_header" class="metadata">
<div id="tag_header" class="tagHeader" style="display: block;">
<apex:actionRegion rendered="{!NOT(newMode)}" >

<input type="hidden" name="personalhidden_tag_list" id="personalhidden_tag_list" value="{!stringPersonalName}"/>
<input type="hidden" name="personalhidden_tag_id_list" id="personalhidden_tag_id_list" value="{!stringPersonalId}"/>

<input type="hidden" id="publichidden_tag_list" name="publichidden_tag_list" value="{!stringPublicName}"/>
<input type="hidden" id="publichidden_tag_id_list" name="publichidden_tag_id_list" value="{!stringPublicId}"/>

</apex:actionRegion>

<img width="16" height="16" title="" alt="" src="/img/icon/tagEdit16.gif"/>

<span id="tag_edit" class="editTags">
<a title="Add Tags" id="tag_edit_text" class="clickable" href="javascript&colon;void(0)">Add Tags</a>
</span>
<span class="tagHeaderLists">
<span id="personaltag_display_container" style="display: none;">
<img width="16" height="16" title="Personal Tag" class="tagHeaderImg" alt="Personal Tag" src="/img/icon/personal_tag16.gif"/>

<span class="myTags">Personal: </span>

<span id="personaltag_display_list" class="tagList"></span>

</span>

<span id="publictag_display_container" style="display: none;">
<img width="16" height="16" title="" class="tagHeaderImg" alt="" src="/s.gif"/>

<span class="myTags">Public: </span>
<span id="publictag_display_list" class="tagList"></span>


</span>
</span>
</div>

<div style="display: none;" id="tag_drop_down" class="tagDropDown"><div style="visibility: hidden;" id="tag_drop_down_contents">
<div style="display: none;" id="tag_edit_error" class="errorMsg"></div>

<table class="tagDropDownContent"><tbody><tr><td colspan="5" class="tagHelp">
<div><a href="javascript&colon;openPopupFocusEscapePounds(%27/help/doc/user_ed.jsp?loc=help&amp;target=tag_records.htm%27, %27Help%27, 700, 600, %27width=700,height=600,resizable=yes,toolbar=yes,status=no,scrollbars=yes,menubar=yes,directories=no,location=no,dependant=no%27, false, false);"><span>Tags Help</span><img title="Help" class="helpIcon" alt="Help" src="/s.gif"/></a>

</div></td></tr>

<tr><td><img width="16" height="16" title="Personal Tag" alt="Personal Tag" src="/img/icon/personal_tag16.gif"/></td>

<td class="my_tags"><label for="personaltag_edit_area">Personal Tags:</label>
<span id="personaltag_edit_list" class="tagList"></span><br/>
<textarea wrap="soft" type="text" rows="1" name="personaltag_edit_area" maxlength="49599" id="personaltag_edit_area"></textarea>
<br/>

<div style="display: none;" id="personaltag_edit_error" class="errorMsg"></div></td>

<td><img width="16" height="16" title="" alt="" src="/s.gif"/></td>
<td class="my_tags">
<label for="publictag_edit_area">Public Tags:</label>
<span id="publictag_edit_list" class="tagList"></span><br/>

<textarea wrap="soft" type="text" rows="1" name="publictag_edit_area" maxlength="49599" id="publictag_edit_area"></textarea><br/>

<div style="display: none;" id="publictag_edit_error" class="errorMsg"></div></td>
<td>&nbsp;</td></tr>

<tr><td>&nbsp;</td><td colspan="4"><div class="example">Separate tags with commas (for example: Hot Lead, Golfer).</div></td></tr>

<tr><td colspan="5" class="tagButtons">
<input type="button" title="Save" id="tag_save" class="btn" value=" Save "/>
<input type="button" title="Cancel" id="tag_cancel" class="btn" value="Cancel"/></td></tr>
</tbody></table></div></div>
<div class="clearingBox"></div></div>
</div></div>
<!--End Tagging Header-->
</apex:component>
                     

 This is the Apex Controller for the Component:

 

public with sharing class getTagRecord {

//used with component taggingHeader
   
     
    Public Boolean newMode = false;
    Lead thisLead;
    
    PageReference pageRef = ApexPages.currentPage();
   //todo:  use SObject to reference which type of Object instead of hard coded Lead
   //benefit - ability to use tagging header on other objects, like accounts
   
    public boolean getNewMode(){
    PageReference pageref = ApexPages.currentPage();
    String retString = pageref.getURL();
    Boolean result = retString.contains('save_new');
    if(result == true){
    newMode = true;
    } else {
     Lead thisLead = [Select Name, Id From Lead WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];
     } 
      return newMode;
    }

      public list<tagL> getTags() {

     // Initialize list to be returned
     list<tagL> list_tags = new list<tagL>();
         if(thisLead!=null){
    //get Tags for this Lead
    for (LeadTag lt : [SELECT Id, Name, ItemId, Type FROM LeadTag WHERE ItemId = : thisLead.Id]){
    if(lt.Type == 'Personal'){
       // Create a new wrapper object
        tagL tl = new tagL();
       
       // Set the valueOf(string);
        tl.theName = string.valueOf(lt.Name);
        tl.theType = string.valueOf(lt.Type);
        tl.theId = string.valueOf(lt.Id);
        list_tags.add(tl);     
        }
    }
   }
  return list_tags;

    }
           public class tagL{
     
     // Class properties
        public String theName{get; set;}
        public String theId{get; set;}
        public String theType{get; set;}       
    }
    
     public list<tagP> getPublicTags() {
     //public tags
       // Initialize list to be returned
    List<tagP> list_Ptags = new list<tagP>();
        if(thisLead!=null){
    //get Tags for this Lead
    for (LeadTag lP : [SELECT Id, Name, ItemId, Type FROM LeadTag WHERE ItemId = : thisLead.Id]){
    if(lP.Type == 'Public'){
       // Create a new wrapper object
        tagP tP = new tagP();
       
       // Set the Date datetime.valueOf(stringDate);
       //initialized tp no values;
        tP.thePName = string.valueOf(lP.Name);
        tP.thePType = string.valueOf(lP.Type);
        tP.thePId = string.valueOf(lP.Id);
        
      list_Ptags.add(tP);   
      }
  }    
 }
  return list_Ptags;

    }
    

     public class tagP{
     
     // Class properties
        public String thePName{get; set;}
        public String thePId{get; set;}
        public String thePType{get; set;}       
    }
    
    //need to populate the fields on the page w/concatenated values not repeated
   public String getStringPublicName() {
   Integer pNameL =0;
   List<String>StringPublicName = new List<String>();
       List<tagP> myPubName = getPublicTags();
       for(tagP tpn : myPubName){
       stringPublicName.add(String.valueOf(tpn.thePName));
       pNameL = tpn.thePName.length() + pNameL;
       System.debug('**************************************  ' + stringPublicName);
       } 
       if(stringPublicName.size() > 0){   
       return string.valueOf(stringPublicName).substring(1,pNameL-1);
       } else { 
       return null;
       }
  
        }
  //return public tag id
    public String getStringPublicId() {
    Integer pIdL = 0;
   List<String>StringPublicId = new List<String>();
       List<tagP> myPubName = getPublicTags();
       for(tagP tpid: myPubName){
       stringPublicId.add(tpid.thePId);
       pIdL = tpid.thePId.length() + pIdL;
       }
       if(stringPublicId.size() > 0){      
       return string.valueOf(stringPublicId).substring(1,pIdL-1);
       } else { 
       return null;
       }
      } 
        //return personal tag name
   public String getStringPersonalName() {
   Integer nLength = 0;
   List<String>StringPersonalName = new List<String>();
       List<tagL> myPerName = getTags();
       for(tagL tid: myPerName){
       stringPersonalName .add(tid.theName);
       nLength = tid.theName.length() + nLength;
       } 
       if(stringPersonalName.size() > 0){     
       return string.valueOf(stringPersonalName).substring(1,nLength-1);
       } else {
       return null;
       }
      }
        //return personal tag id
   public String getStringPersonalId() {
   Integer idL = 0;
   List<String>StringPersonalId = new List<String>();
       List<tagL> myPerName = getTags();
       for(tagL tid: myPerName){
       stringPersonalId.add(tid.theId);
       idL = tid.theId.length() + idL;
       }     
       if(stringPersonalId.size() > 0){ 
       return string.valueOf(stringPersonalId).substring(1,idL-1);
       } else {
       return null;
       }
      }     
}

 Now to insert this into my VF Page:

<c:taggingHeader id="th"></c:taggingHeader>

 Hope you find this helpful!

Eva