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
KNKKNK 

Restriction of button visibility

 

Hi Team,

 

I want to restrict the below add product button based on the value of year. can any one help me on this. below is the apex code for same.

 

 

 

public string addingProduct {get; set;}
    
    public PageReference addProduct() {
        addingProduct='.';
        return null;
    }
    
    public PageReference cancelAddProduct() {
        addingProduct = null;
        return null;
    }       
    
    public transient string selectedProductIDs {get; set;} // no need to keep between postbacks
    
    public PageReference productsSelected() {
        addingProduct = null;
        
        string[] spIDs = (selectedProductIDs==null) ? new string[]{} : selectedProductIDs.split(',');
        Set<ID> pIDs = new Set<ID>();
        
        for (string s : spIDs)
            pIDs.add(s);
        
        Map<ID, Product_Shipper__c> pp = readProducts(pIDs);
        List<DSP_Product__c> records = new List<DSP_Product__c>();
        List<DataRecord> drdr = new List<DataRecord>();
        
        for (ID pid : pp.keySet())
        {
            Product_Shipper__c p = pp.get(pid);
            DataRecord dr = new DataRecord(p, this);
            dr.fix();
            
            dr.Forecast.Product_Price__c = p.Price__c;
            dr.LE.Product_Price__c = p.Price__c;
            dr.Actual.Product_Price__c = p.Price__c;
            
            records.add(dr.Forecast);
            records.add(dr.LE);
            records.add(dr.Actual);
            
            drdr.add(dr);
            
        }
        
        try {
            insert records;
           // for (DataRecord dr : drdr)
           //     dataRecords.add(dr);
           reloadRecords();    
        }
        catch (Exception e) {
         ApexPages.addMessages(e);
        }
        
        dsp.invalidate();
                
        return null;        
    }

    public ID[] existingProducts {
        get {
            if (dataRecords==null) return new ID[]{};
            
            ID[] rr = new ID[]{};
            
            for (DataRecord r : dataRecords.items) {
                if (r.Forecast!=null)
                    rr.add(r.Forecast.Product_Shipper__c);
            }
            return rr;
        }
    }
   

Best Answer chosen by Admin (Salesforce Developers) 
MFSDevMFSDev

Hi,

Do you want to restrict visibility of button for a certain value? 

You can use rendered property of button . For a String value set you can show/hide of button