+ Start a Discussion
Nick KeehanNick Keehan 

Query Records where CreateDate = Today and Set Boolean

Hi Guys.

Looking to query records that have been created in the last 7 days and set a boolean as true. The boolean will only render certain records on the VF page repeat function. I will change the Created_Date__c field to 7 days below, this was just the begining.

Getting a "Error: Compile Error: Expression cannot be assigned at line -1 column -1" 
 
public class booleanmap {

public boolean isDisplay {get;set;}

public list<Sales_visit__c> accts {get;set;}

Public Boolean ConditionalDisplay()
{


accts=[SELECT Id, Name, Created_Date__c FROM Sales_Visit__c WHERE Created_Date__c = 'Date.today()'];

        
     if(Sales_Visit__c.Created_Date__c = 'Date.today()')
       {
        isDisplay=True;
       }
       else
        {
          isDisplay=false;
        }

return isDisplay;
}

}

Any help would be apreciated.

Nick
V V Satyanarayana MaddipatiV V Satyanarayana Maddipati
Hi Nick Keehan, 

Create a wrapper class to display only the boolean flag true set values in the page.
 
public class booleanmap {
    
    public List<salesWrapper> salesWrapList {get;set;}
    
    Public void ConditionalDisplay() {
        
        List<Sales_visit__c> accts=[SELECT Id, Name, Created_Date__c FROM Sales_Visit__c WHERE Created_Date__c = LAST_N_DAYS:7];
        salesWrapList = new List<salesWrapper>();
        
        Date d = Date.today();
        for(Sales_visit__c sv: accts) {
            salesWrapper salesWrapIns = new salesWrapper();
            if(sv.Created_Date__c = d) {
                salesWrapIns.isDisplay=True;
            }
            else {
                salesWrapIns.isDisplay=false;
            }
            salesWrapIns.accts = sv;
            salesWrapList.add(salesWrapIns);
        }
    }
    
    public class salesWrapper {
        
        public boolean isDisplay {get;set;}
        public Sales_visit__c accts {get;set;}
        
        public salesWrapper(boolean isDisplay, Sales_visit__c accts) {
            this.isDisplay = isDisplay;
            this.accts  = accts;
        }
    } 
}


Now use {!salesWrapList} variable in the page and show only the boolean flag set true values.


Thanks
Satya. 
 
Nick KeehanNick Keehan
Thanks Satya

Getting the below error, any idea how to overcome this?

Error: Compile Error: Constructor not defined: [booleanmap.salesWrapper].<Constructor>() at line 12 column 41

Nick
V V Satyanarayana MaddipatiV V Satyanarayana Maddipati
for(Sales_visit__c sv: accts) {
    salesWrapper salesWrapIns = new salesWrapper(false, sv); // Modified line.
    if(sv.Created_Date__c = d) {
        salesWrapIns.isDisplay=True;
    }
    else {
        salesWrapIns.isDisplay=false;
    }
    salesWrapIns.accts = sv;
    salesWrapList.add(salesWrapIns);
}
Hope this will help you.

Mark best Answer if its works for you. 

Thanks 
Satya.