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
salesforce@14salesforce@14 

The Add row functionality is not working in my code. can someone help me to resolve my issue.

Hi,

 I pasted my code below and darked area is an issue one.

public class AllUserList
{  
    public list<SelectOption> selectedobject { get; set; }
    public String objectName { get; set; }    
    public list<SelectOption> fieldsName {get;set;}
    Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    Map<string,EmailTemplate> alltemplate;
    Map<string,string> FieldType = new Map<string,string>();
    Map<string,string> fieldTypes=new Map<string,string>();
    public list<SelectOption> open{get;set;}
    public list<selectoption> templates{get;set;}
    public list<wrapperclass> value{get;set;}
    public list<Sobject> rowlist{get;set;}
 // Public list<Wrapper> wrap{get;set;}
    Public List<sobject> val4{get;set;}
    Public List<Contact> conList = new List<Contact>();
    public string templatename{get;set;}
    public Integer totalRecords;
    public Integer sno=0;
    public string templateid{get;set;}
    Public string FieldName{get;set;}
    public string query{get;set;}   
    public string Fname1{get;set;}
    public string Operator1{get;set;}
    public string Value1{get;set;}                      
    public void search()
    {      
        string whereQuery='select id,Name,Email from ObjectName';
        string whereclause ='where';
                    if(Fname1!='' && Fname1!=null && Operator1!='' && Operator1!=null && Value1!='' && Value1!=null)
                    {
                       whereQuery=whereQuery+retwhereQuery(Fname1,Operator1,Value1)+' and ';
                       
                    }                  
            if(objectName=='Contact')
        {
        whereQuery = ' select id,Email,Name'  +  ' from '  +  objectName  +  ' where '  + retwhereQuery(Fname1,Operator1,Value1);
        }
        else
        if(objectName=='Lead')
        {
        whereQuery = ' select id,Email,Name'   +  ' from '  +  objectName  +  ' where ' + retwhereQuery(Fname1,Operator1,Value1);
        }
        else
        if(objectName=='User')
        {
        whereQuery = ' select id,Email,Name'   +  ' from '  +  objectName  +  ' where '  + retwhereQuery(Fname1,Operator1,Value1);
        }
          if(whereQuery.contains('and'))
        whereQuery = whereQuery.subString(0,whereQuery.lastIndexOf('and'));
        system.debug('################################################'+Query);   
        val4 = Database.query(whereQuery);
        value=new list<wrapperclass>();
     //   wrap = new list<Wrapper>();
        for(Sobject s:val4)
        {
            wrapperclass wr = new wrapperclass('s.Email','s.Name',false,s.id,sno);   
            wr.email=string.valueof(s.get('Email'));
            wr.name= string.valueof(s.get('Name'));
            value.add(wr);
            system.debug('^^^^^^^^^^^^^'+value);
        }    
        system.debug('$$$$$$$$$$$$$'+value);
    }   
    public class wrapperclass
    {         
        public string id{get;set;}
        public string name{get;set;}
        public string email{get;set;}
        public Boolean checked{get;set;}
        public string snumber{get;set;}
        public wrapperclass(string email,string name,Boolean checked,string id,Integer sno)
        {      
            this.id=id;  
            this.Name=name;
            this.Email=email;
            this.checked=checked;    
            snumber=String.valueOf(sno);
        }
    }
  /*  public class wrapper
    {
      public Integer sno{get;set;}
      public wrapper(Integer sno)
      {
        this.sno=sno;
      }
    }    */    
    public AllUserList()
    {    
       
        value = new List<wrapperclass>(); 
       // addrow();
      //  wrap = new List<Wrapper>();
        templates = new list<selectoption>(); 
        templates.add(new selectoption('','--None--')); 
        val4 = new List<sobject> ();
        rowlist = new List<Sobject>();
        totalRecords=0;  
        String folderId = [Select Id,Name From Folder where Name = 'Email'].Id;
        system.debug('????????????'+folderId );
        alltemplate = new map<string,EmailTemplate>();
        for(EmailTemplate fd: [Select Body, HtmlValue, Id, Name, Subject from EmailTemplate where FolderId=:folderId])
        {
            templates.add(new selectoption(fd.Name,fd.Name));
            alltemplate.put(fd.Name,fd);
        } 
        system.debug('++++++++++++'+alltemplate);      
    }
    public list<selectoption> getobject()
    {   
        List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();    
        List<SelectOption> options = new List<SelectOption>();  
        options.add(new SelectOption('','--None--'));  
        for(Schema.SObjectType f : gd)
        {   
            if(!f.getDescribe().isCustomSetting() && f.getDescribe().isAccessible() && f.getDescribe().isCreateable() && f.getDescribe().isSearchable() && f.getDescribe().isQueryable())
            {
                if(string.valueof(f.getDescribe().getName()) == 'Lead' || string.valueof(f.getDescribe().getName()) == 'Contact' || string.valueof(f.getDescribe().getName()) == 'User')
                options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getLabel()));
            }      
            options.sort();       
        }
        return options;
    }
    public List<SelectOption> getfd()
    { 
        List<SelectOption> fieldsName =new List<SelectOption>();
        if(objectName != null)
        {
            system.debug('!!!!!!!'+objectName );
            Map <String, Schema.SObjectField> fieldMap= Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
            for(Schema.SObjectField sfield : fieldMap.values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                fieldTypes.put(string.valueof(dfield.getName()),string.valueof(dfield.getType()));
                fieldsName.add(new SelectOption(dfield.getName(),dfield.getLabel()));
            }
        }
        return fieldsName;
    }
    public List<SelectOption> getSelect()
    {
                    List<SelectOption> option = new List<SelectOption>();
                option=getSearchOperator(Fname1);
                return option;

        return open;
    }
  /*   public void add()
    {
      sno=sno+1;
      addrow();
    }  */
   public void addrow()
    {
        rowlist = new List<Sobject>();
        totalRecords=0;          
         sno = value.size();   
        system.debug('@@@@@@@@@@@@@'+sno);
        for(Sobject s:val4)
        {
            wrapperclass wr = new wrapperclass('s.Email','s.Name',false,s.id,sno);   
            value.add(wr);   
        } 
        system.debug('$$$$$$$$$$$$$$$'+value);
        
    }   

  public void removerow()
    {
        if(value.size() > 1)
        {
            value.remove(value.size()-1);
        }
    } 
                             
}

Thanks.
Keshab AcharyaKeshab Acharya
What is the issue you are facing, please provide some more info.
salesforce@14salesforce@14
Hi keshab archaya,

Actually i need to implement Add Row and Remove Row functionality in filter condition in VF page.

I implemented that functionality in my code(darked area) but its not working and i dont know where i made mistake.

Thanks.