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
anuj huriaanuj huria 

I want to hide “Delete” commandLink at visualforce page

hi guys..
i have 3 collumns 
1-date on which record is created
2-delete(command link)
3-edit(Command Link)

i want to hide delete and edit command link for those whose created date is not today..

thanks in advance
regards 
Anuj
Best Answer chosen by anuj huria
anuj huriaanuj huria
Hi sandeep 
problem is solved now thanks for your concern

here is the solution

apex:commandLink value="delete" action="{!ddelete}" rendered="{!if(left(x,10)== Text(Today()),true,false)}">

All Answers

sandeep sankhlasandeep sankhla
Hi Anuj,

You can use the rendered attribute in code to show and hide this command link conditionally.

Check the below example adn let me know if it helps you.

<apex:commandLink action="{!save}" value="Save" id="theCommandLink" rendered = "{!if(Obj.createddate == Today()), true, false}"/>

Like this you can conditionally hide and show these links. Pelase check and share your code if you are facing any issue in implementing the same.

Thanks
Sandeep
anuj huriaanuj huria
Hi Sandeep,
Actually that date  collumn in also a comand link and it consist all those records created on that day...

here is the code

page;-

<apex:page controller="sample2">
   <apex:form >
      <apex:pageBlock >
          <apex:pageblockTable var="x" value="{!l}">
              <apex:column headerValue="date wise records">
              <apex:outputPanel >
                  <apex:commandLink value="{!x}" action="{!set1}">
                       <Apex:param name="fid" value="{!x}" assignTo="{!fid}"/>
                  </apex:commandLink>
              </apex:outputPanel>
              </apex:column>
              <apex:column >
                  <apex:commandLink value="edit" action="{!dedit}" rendered="{!ce}">
                      <apex:param name="aid" value="{!x}" assignTo="{!aid}"/>
                  </apex:commandLink>                 
              </apex:column>
              <apex:column >
                  <apex:commandLink value="delete" action="{!ddelete}" rendered="{!cd}">
                      <apex:param name="yid" value="{!x}" assignTo="{!yid}"/>
                  </apex:commandLink>
              </apex:column>
          </apex:pageblockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page


controller

public with sharing class sample2 
{
    public List<String> l{get;set;}
    public String fid{get;set;}
    public String aid{get;set;}
    public String yid{get;set;}
   
    public List<task__c> d{get;set;}
    List<task__c> i{get;set;}
    
    public Boolean b{get;set;}
    public Boolean v{get;set;}
    public Boolean cn{get;set;}
    public Boolean sv{get;set;}
    public Boolean e{get;set;}
    public Boolean cd{get;set;}
    public Boolean ce{get;set;}
    public sample2()
        {
        
            b=true;
            v=false;
            e=true;
            cn=false;
            sv=false;
            l=new List<String>();
            i=new List<task__c>();
         
           
            AggregateResult[] ar = [SELECT cdate__c from task__c group by cdate__c];
            //System.debug(ar);        
           
            for(AggregateResult a:ar)
            {
                String h=String.valueOf(a.get('cdate__c')); 
                //String m=h.substring(0,h.length()-1);               
                l.add(h);
                //System.debug(m);              
            }
            for(String o:l)
            {
                //String h=String.valueOf(o.get('cdate__c'));
                //DateTime dt=DateTime.valueOfGmt(h);
                //System.debug(System.now());
                //System.debug(System.now()-0.125);
                String u=o.subString(0,o.length()-10);
                //System.debug(u);
                
                if(String.valueOf(Date.today())==u)
                {
                   ce=true;
                   cd=true;
                  System.debug('true'); 
                   
                }
                else
                {
                    ce=false;
                    cd=false;
                    System.debug('false');
                }
                
                
            }
            
            
            
            
            

        }
    public List<String> l()
    {
        return l;
    }  
    
    public PageReference set1()
    {
        i=new List<task__c>();
        i=[select id,name,X15__c,X20__c,X30__c from task__c where cdate__c=:fid];
        
        e=true;
        PageReference reRend2 = new PageReference('/apex/task4_2');
           return reRend2;
    }
    public PageReference dedit()
    {
       
        i=new List<task__c>();
        i=[select id,name,X15__c,X20__c,X30__c from task__c where cdate__c=:aid];
        
        e=false;
        cn=true;
        sv=true;
        v=true;
        b=false;
        PageReference reRend2 = new PageReference('/apex/task4_2');
           return reRend2;
    } 
    
    public PageReference ddelete()
    {
        i=new List<task__c>();
        i=[select id,name,X15__c,X20__c,X30__c from task__c where cdate__c=:yid]; 
        for(task__c w:i)
            {
                delete w;
            }
            e=true;
          PageReference reRend2 = new PageReference('/apex/task4_1');
          reRend2.setRedirect(true);
           return reRend2;
             
    }
    
    
    public List<task__c> getshow()
    {
    return i;
    } 
    
    public void ed()
    {
        b=false;
        v=true;
        e=false;
        cn=true;
        sv=true;
    }
    public void can()
    {
        b=true;
        v=false;
        e=true;
        cn=false;
        sv=false;
    }
    public void sa()
    {
        for(task__c d:i)
            {
                upsert d;
            }
        b=true;
        v=false;
        sv=false;
        cn=false;
        e=true;
    }
    
}
sandeep sankhlasandeep sankhla
Hi
 simply you can have tow things here so if date is not today then show command link else simply show the valye as output text..

so as condition will be there so only one will be enabling at a time..

Like

<apex:commandLink value="delete" action="{!ddelete}" rendered="{!cd}">
                      <apex:param name="yid" value="{!x}" assignTo="{!yid}"/>
                  </apex:commandLink>
<apex:outputtext rendered="{!!cd}"></apex:outputtext>

so as conditio is applied and only one will be shown at a time..

Please check and let me know if it helps.

Thanks
anuj huriaanuj huria
hi sandeep.
problem is not solved yet.. 

<apex:commandLink value="edit" action="{!dedit}" rendered="{!ce}">
                      <apex:param name="aid" value="{!x}" assignTo="{!aid}"/>
                  </apex:commandLink> 
                  <apex:outputText rendered="{!ce}">
                  </apex:outputText> 

all the rows having edit and delete command link
anuj huriaanuj huria
Hi sandeep 
problem is solved now thanks for your concern

here is the solution

apex:commandLink value="delete" action="{!ddelete}" rendered="{!if(left(x,10)== Text(Today()),true,false)}">
This was selected as the best answer
sandeep sankhlasandeep sankhla
Hi Anuj,

ABove code I just shared for referece....see in above code in rendered attribute you used same which is wrong..

so first one should be rendered when it ce is true and second one which is output text should be renderd when it is false. then only at a time only one will appear and in secodn one you need to add the value to display for now that is blank. nothing you haev added to show.

Pleaser implement as I mentioned and let me know if you are able to solve it.

<apex:commandLink value="edit" action="{!dedit}" rendered="{!ce}">
                      <apex:param name="aid" value="{!x}" assignTo="{!aid}"/>
                  </apex:commandLink> 
                  <apex:outputText rendered="{!!ce}">
                     <apex:param name="aid" value="{!x}" assignTo="{!aid}"/>
                  </apex:outputText>

Thanks
Sandeep
sandeep sankhlasandeep sankhla
HI Anuj,

I see that you just wanted to hide same but syntax was not correct so you used that..I thought value itself you just dont want to show as link adn you only want to display the text, in this case only we need to use above solution which I shared.

If you hide that link itself then yes which I shared as first solution will solve , there were syntax error so it was not working but good that you solved it...

Please mark the answer as best answer so other can also take help if they face the same issue.
Thanks
Sandeep