• MSR
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 2
    Replies
Here is the relationship of an custom object (all are Lookup relations)
A--> B --> C
A--> D
Trying To Achieve, if a new record is created in "D" then "C" Custom field need to capture "D" latest record Name in a custom field (latest_D_Name__c)

I have written below code, I tested with Bulk data as well its working fine
But i want this to optimize as much as possible and make it simple. any suggestion will be helpful

Question in my mind always popping up, Why am getting Null when am trying to pull A.ID (C.B__r.A__c) through "1st For Loop" directly.
If i find a way to pull the A.id from "1st For Loop" , then i can get rid of "2nd For Loop" */
 
trigger C_CustomObjTrigger on C_CustomObj  (Before Update) {  
     set<ID> B_idset = new set<ID>();
     set<ID> A_idset = new set<ID>();
     // Getting Parent ID of Object C (1st For Loop)
     for(C_CustomObj C : Trigger.new){
          if(C.B_CustomObj != null)
             B_idset.add(C.B_CustomObj);
     }  
     // Getting Grand Parent ID (2nd For Loop)
     for(B_CustomObj B: [SELECT NAME,id,A_CustomObj FROM B_CustomObj where id in:B_idset]){
          if(B.A_CustomObj != null)
             A_idset.add(B.A_CustomObj);
     }  
    // pulling Childs list for Grand Parent  
     List<D_CustomObj> D = [Select id,name,Date__c,Value__c From D_CustomObj where A_CustomObj in: A_idset
                                          Order By Date__c Desc];
    If(Trigger.IsBefore) {  
    for(C_CustomObj C_Update: trigger.new){                                           
        if(C_Update.Approved__c == False){
           //Update the Decision Object :Latest D to be caluculated                                  
            if(D.size()>0){
                C_Update.latest_D_Name__c = D[0].Name;
            }                   
        }
   }        
 }

 
  • November 24, 2014
  • Like
  • 0

Hi,

 

i have a vfpage on which am querying about 20 Million records based on a search criteria and seeing a request time out.

I have tried 'Read-only' option on the page, gave max no of Where clauses with indexed fields in the query.So how cani workaround to overcome this request time out error message and display the search results by querying 20 Million records.Any kind of help would be appreciated and will be helpful to others who r facing the same issue.

  • August 17, 2012
  • Like
  • 0

HI All,

 

I am hitting a View State error for the controller that i wrote for a Vf page in which an input text is entered to retrive the results.In the controller it queries the list from a custom object and populates on a page. I used std controller for pagination to run through the results to show 10000 records atleast out of 40000 records records.My Issue is when i keep the pagesize in the std controller to 100,if i click on "Next/Previous "  button tto run through results of Say 2000, i am hitting the view state error after 1300-1400 records.Can someone debug my controller code and help me where i am going wrong.I have tried to declare transients and tried to follow all the norms to minimize view state error but still i am seeing the error.Any suggestions....appriciated.Below is my controller code.

public class TestIpreoSearch {

   public transient List<Ipreo__c> ipresultList {get;set;}
   public transient List<Trading_Activity__c> selectedTAs {get;set;}
   public List<Trading_Inquiry__c> selectedTIs {get;set;}
   public transient List<cTradingActivity> TAList {get;set;}
   public transient List<cTradingInquiry> TIList {get;set;}
   public String inputValue { get; set; }
   //public String radiooption{ get; set; }
   public integer totalSize{get;set;}
   public integer totalSize1{get;set;}
   public boolean showcolumn {get;set;}
   public boolean Mycoverage {get;set;}
   public boolean donotshow {get;set;} // This boolean value is to hide the TI Section when Desk manager selects 'MyDesk' RadioOption;
   public boolean SingleUserCoverage {get;set;}
   public boolean Mydeskcoverage {get;set;}
   public boolean ManagerVisiblity{get;set;}
   public Set<String> AccTeamMemidSet = new Set<String>();
 // public List<SelectOption> options{get;set;}
   public String sortDirection = 'DESC';
   public String sortDirectionTi = 'DESC';
   public String sortExpr = 'Trade_Date__c';
   public String sortExprTi = 'Date__c ';
   public Boolean sortFlag = false;
   public Boolean sortFlagTi = false;
   
      public TestIpreoSearch (){
          string roleid = userinfo.getUserRoleId(); 
          system.debug('ROLE ID:::'+roleid);
           
           if((roleid == '00EU0000000nAblMAE') || (roleid =='00EU0000000nAboMAE')) {
                showcolumn = true; 
               }else
                showcolumn = false; 
                system.debug('ENTER LOOP:::'+showcolumn);
                
         /*  options = new List<SelectOption>(); 
           options.add(new SelectOption('MyCoverage','My')); 
           options.add(new SelectOption('MyDeskCoverage','My Desk')); */   
       // getTALists();         
      
     }
      
        public List<SelectOption> getRadioSelection() {
        List<SelectOption> RadioSelection= new List<SelectOption>(); 
        RadioSelection.add(new SelectOption('MyCoverage','My')); 
        RadioSelection.add(new SelectOption('MyDeskCoverage','My Desk')); 
         return RadioSelection;
      } 
      String Radiooption = null;
      public String getRadiooption() {
        return Radiooption ;
    }
      public void setRadiooption(String Radiooption)
    {
        this.Radiooption = Radiooption;
    }
       
    
     
     
   public ApexPages.StandardSetController con { 
     get{
       if(con == null || sortFlag == true){
       String sortFullExp = sortExpression  + ' ' + sortDirection;
       String message = System.currentPagereference().getParameters().get('msg');
       String sortmessage = System.currentPagereference().getParameters().get('msg2');
       system.debug('CON CALLED:::::');
       string Userid = userinfo.getUserId();
       String pfid = userinfo.getprofileid();
       //List<AccountTeamMember> AccTeamMemList = new List<AccountTeamMember>();
       
       Set<ID> uidset = new Set<ID>(); 
             
       if(showcolumn == false){
              SingleUserCoverage = true;
          }
        if( SingleUserCoverage == true){
          uidset.add(UserId);
          system.debug('SINGLEUSERSET'+uidset);
          donotshow = true;
       }
          
        
       if(radiooption == 'MyCoverage'){
          uidset.add(UserId);
          system.debug('USERSET'+uidset);
          donotshow = true;
       }else if(radiooption == 'MyDeskCoverage'){
          donotshow = false;
         // List<User> uList = [SELECT id,name,profileid FROM user WHERE profileid=:pfid];
          for(User u:[SELECT id,name,profileid FROM user WHERE profileid=:pfid]){
            uidset.add(u.id);
            system.debug('DESKSET'+uidset);
          }  
        }
      
       // AccTeamMemList = [SELECT accountId, userId FROM AccountTeamMember WHERE userId IN: uidset]; 
         for(AccountTeamMember a:[SELECT accountId, userId FROM AccountTeamMember WHERE userId IN: uidset]){
                 AccTeamMemidSet.add(a.accountId);
         } 
         
         String SearchQuery ='';
        List<String> slist = new List<String>();
           String s='';
       if(AccTeamMemidSet.size() > 0){    
           slist.addAll(AccTeamMemidSet);
                
          for(integer i=0;i<slist.size();i++){
            if(i!=0)
            s+='OR Account__c='+'\''+slist[i]+'\'';
            } 

        s+=')';
      }   
           string whereclause = 'WHERE';
           whereClause += ' (CUSIP__c ='+'\''+inputValue+'\'';  
           whereClause += ' OR Bloomberg_Issuer_Ticker__c ='+'\''+inputValue+'\'';
           whereClause+=')';
           if(s != '')
             whereClause += ' AND ( Account__c =\''+slist[0]+'\''+s+'';
             whereClause += ' ORDER BY '+sortFullExp+' LIMIT 1000';
               
           searchQuery = 'SELECT id,name, Trade_ID__c, Trade_Date__c, Bloomberg_Issuer_Ticker__c, Sales_Person__c, '+
                         'Account__r.Name, CUSIP__c, Coupon_Rate__c, Maturity_Date__c, Buy_Sell__c, '+
                         'Par_Notional__c, Trade_Price__c, Spread__c, Sales_Credit__c '+
                         'FROM Trading_Activity__c '+whereClause;    
     
                      
          system.debug('&&&&&&&&QUERY:::::'+searchQuery);
          
          
                    
          con = new ApexPages.StandardSetController(Database.getQueryLocator(searchQuery));
               if(message == 'success' || sortmessage == 'aftersort')
                con.setPageSize(100);
                else
                 con.setPageSize(10);
                totalSize= con.getResultSize(); 
                sortFlag = false;
}
Return con;
}
Set;
}

/*-----------------------------SEARCH METHOD FOR USER INPUT-------------------------------------------*/
   
     
     public void SearchData() {
      
      con = null;
     // TAList = null;
    //  con1 = null;
     // TIList = null;
        
    /*  ipresultList =  [SELECT Account_Name__c,CUSIP__c,Ticker__c,Portfolio_Name__c,
                                 Par_Held__c,Par_Change__c,Position_Date__c,Source__c,
                                 Coupon_Rate__c,Maturity_Date__c 
                           FROM Ipreo__c
                          WHERE (CUSIP__c=:inputvalue OR Ticker__c=:inputvalue) ];*/
             
         
   }      
        
 /*----------------------------------END OF SEARCH METHOD--------------------------------------------*/ 
    
        
    //This method uses a simple SOQL query to return a List of TradingActivities
    public List<cTradingActivity> getTALists() {
            //  if(TAList == null) {
              TAList = new List<cTradingActivity>();
            for(Trading_Activity__c ta:(List<Trading_Activity__c>)con.getRecords()) {
                // As each TradingActivity is processed we create a new cTradingActivity object and add it to the TAList
                TAList.add(new cTradingActivity(ta));
              }
          // }
        return TAList;
    }
    
 public pagereference gotolist(){
        con = null;TAList = null;
        PageReference pageRef = Page.gotoTAlistIpreo1;
        pageRef.getParameters().put('msg','success');
       // pageRef.setRedirect(true);
        return PageRef;
      }
      
 public pagereference gototilist(){
        con1 = null;TIList = null;
        PageReference pageRef = Page.gotoTIlistIpreo;
        pageRef.getParameters().put('msg1','success');
       // pageRef.setRedirect(true);
        return PageRef;
      }     
      
  public pagereference ipgotolist(){
         pagereference p2 = new pagereference('/apex/gotoipList');
         return p2;
      }   
        
/* ----------------------WRAPPER FOR TRADING ACTIVITIES--------------------------------------------------*/
     
      
    public PageReference processSelected() {

                //We create a new list of TAs that we be populated only with TAs if they are selected
        selectedTAs = new List<Trading_Activity__c>();

        //We will cycle through our list of cTradingActivities and will check to see if the selected property is set to true, if it is we add the TradingActivity to the selectedTAs list
        for(cTradingActivity cta : TAList) {
        
            if(cta.selected == true) {
                selectedTAs.add(cta.tra);
                System.debug('These are the selected TAs...'+selectedTAs);
            }
        }
        //TAList.clear();  //
        // Now we have our list of selected TradingActivities and can perform any type of logic we want, sending emails, updating a field on the TA, etc
        System.debug('These are the selected TAs...'+selectedTAs.size());
       /* for(Trading_Activity__c tra : selectedTAs) {
            system.debug(tra);
            system.debug('@@@'+tra);
        }*/
      return Page.gotoTAlistIpreoExcel;
    }


    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class cTradingActivity {
        public Trading_Activity__c tra {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cTradingActivity object we pass a TA that is set to the ta property. We also set the selected value to false
        public cTradingActivity(Trading_Activity__c ta) {
            tra = ta;
           selected = false;
        }
    }
    
    //This method uses a simple SOQL query to return a List of TradingActivities
   /* public List<cTradingActivity> getTALists() {
       //if(TAList == null) {
            TAList = new List<cTradingActivity>();
            for(Trading_Activity__c ta:(List<Trading_Activity__c>)con.getRecords()) {
                // As each TradingActivity is processed we create a new cTradingActivity object and add it to the TAList
                TAList.add(new cTradingActivity(ta));
           }
        //}
        return TAList;
    }*/
    
    
/*----------------------------------END OF WRAPPER CLASS-------------------------------------------------*/


 
 
/*---------------------------------SORTING METHOD FOR TA------------------------------------------------*/

         public String sortExpression {
        get {
            return sortExpr;
        }
        set {
            if(value == sortExpr)
                sortDirection = (sortDirection == 'ASC') ? 'DESC' : 'ASC';
            else
                sortDirection = 'ASC';
            sortExpr = value;
        }
    }
     public String getsortDirection() {
        if(sortExpression == null || sortExpression == '')
            return 'ASC';
        else
            return sortDirection;
    }
    
    public void setsortDirection(String value) {
        sortDirection = value;
    }
    
    public String getsortExpr() {
        return sortExpr;
    }
    
    public void setsortExpr(String value) {
        sortExpr=value;
    }
    
     public PageReference sortData() {
        sortFlag = true;
        getTALists();     
      //  con.setPageNumber(1);
     return null;  
    }
    
   
   
 /*--------------------------------END-SORTING--------------------------------------------------------*/  
 
/*------------------------------PAGINATION FOR TA----------------------------------------------------*/   
      
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }
      public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }
    
     public Integer pageNumber {
        get {
            return con.getPageNumber();
        }
        set;
    }
    public void first() {
       
        con.first();
        
    }
    
    public void last() {
        con.last();
    }
    
    public void previous() {
        con.previous();
    }
    
   public void next() {
        con.next();
    }
/*--------------------END-PAGINATION FOR TA-------------------------------------*/   

 

  • August 09, 2012
  • Like
  • 0
Here is the relationship of an custom object (all are Lookup relations)
A--> B --> C
A--> D
Trying To Achieve, if a new record is created in "D" then "C" Custom field need to capture "D" latest record Name in a custom field (latest_D_Name__c)

I have written below code, I tested with Bulk data as well its working fine
But i want this to optimize as much as possible and make it simple. any suggestion will be helpful

Question in my mind always popping up, Why am getting Null when am trying to pull A.ID (C.B__r.A__c) through "1st For Loop" directly.
If i find a way to pull the A.id from "1st For Loop" , then i can get rid of "2nd For Loop" */
 
trigger C_CustomObjTrigger on C_CustomObj  (Before Update) {  
     set<ID> B_idset = new set<ID>();
     set<ID> A_idset = new set<ID>();
     // Getting Parent ID of Object C (1st For Loop)
     for(C_CustomObj C : Trigger.new){
          if(C.B_CustomObj != null)
             B_idset.add(C.B_CustomObj);
     }  
     // Getting Grand Parent ID (2nd For Loop)
     for(B_CustomObj B: [SELECT NAME,id,A_CustomObj FROM B_CustomObj where id in:B_idset]){
          if(B.A_CustomObj != null)
             A_idset.add(B.A_CustomObj);
     }  
    // pulling Childs list for Grand Parent  
     List<D_CustomObj> D = [Select id,name,Date__c,Value__c From D_CustomObj where A_CustomObj in: A_idset
                                          Order By Date__c Desc];
    If(Trigger.IsBefore) {  
    for(C_CustomObj C_Update: trigger.new){                                           
        if(C_Update.Approved__c == False){
           //Update the Decision Object :Latest D to be caluculated                                  
            if(D.size()>0){
                C_Update.latest_D_Name__c = D[0].Name;
            }                   
        }
   }        
 }

 
  • November 24, 2014
  • Like
  • 0

HI All,

 

I am hitting a View State error for the controller that i wrote for a Vf page in which an input text is entered to retrive the results.In the controller it queries the list from a custom object and populates on a page. I used std controller for pagination to run through the results to show 10000 records atleast out of 40000 records records.My Issue is when i keep the pagesize in the std controller to 100,if i click on "Next/Previous "  button tto run through results of Say 2000, i am hitting the view state error after 1300-1400 records.Can someone debug my controller code and help me where i am going wrong.I have tried to declare transients and tried to follow all the norms to minimize view state error but still i am seeing the error.Any suggestions....appriciated.Below is my controller code.

public class TestIpreoSearch {

   public transient List<Ipreo__c> ipresultList {get;set;}
   public transient List<Trading_Activity__c> selectedTAs {get;set;}
   public List<Trading_Inquiry__c> selectedTIs {get;set;}
   public transient List<cTradingActivity> TAList {get;set;}
   public transient List<cTradingInquiry> TIList {get;set;}
   public String inputValue { get; set; }
   //public String radiooption{ get; set; }
   public integer totalSize{get;set;}
   public integer totalSize1{get;set;}
   public boolean showcolumn {get;set;}
   public boolean Mycoverage {get;set;}
   public boolean donotshow {get;set;} // This boolean value is to hide the TI Section when Desk manager selects 'MyDesk' RadioOption;
   public boolean SingleUserCoverage {get;set;}
   public boolean Mydeskcoverage {get;set;}
   public boolean ManagerVisiblity{get;set;}
   public Set<String> AccTeamMemidSet = new Set<String>();
 // public List<SelectOption> options{get;set;}
   public String sortDirection = 'DESC';
   public String sortDirectionTi = 'DESC';
   public String sortExpr = 'Trade_Date__c';
   public String sortExprTi = 'Date__c ';
   public Boolean sortFlag = false;
   public Boolean sortFlagTi = false;
   
      public TestIpreoSearch (){
          string roleid = userinfo.getUserRoleId(); 
          system.debug('ROLE ID:::'+roleid);
           
           if((roleid == '00EU0000000nAblMAE') || (roleid =='00EU0000000nAboMAE')) {
                showcolumn = true; 
               }else
                showcolumn = false; 
                system.debug('ENTER LOOP:::'+showcolumn);
                
         /*  options = new List<SelectOption>(); 
           options.add(new SelectOption('MyCoverage','My')); 
           options.add(new SelectOption('MyDeskCoverage','My Desk')); */   
       // getTALists();         
      
     }
      
        public List<SelectOption> getRadioSelection() {
        List<SelectOption> RadioSelection= new List<SelectOption>(); 
        RadioSelection.add(new SelectOption('MyCoverage','My')); 
        RadioSelection.add(new SelectOption('MyDeskCoverage','My Desk')); 
         return RadioSelection;
      } 
      String Radiooption = null;
      public String getRadiooption() {
        return Radiooption ;
    }
      public void setRadiooption(String Radiooption)
    {
        this.Radiooption = Radiooption;
    }
       
    
     
     
   public ApexPages.StandardSetController con { 
     get{
       if(con == null || sortFlag == true){
       String sortFullExp = sortExpression  + ' ' + sortDirection;
       String message = System.currentPagereference().getParameters().get('msg');
       String sortmessage = System.currentPagereference().getParameters().get('msg2');
       system.debug('CON CALLED:::::');
       string Userid = userinfo.getUserId();
       String pfid = userinfo.getprofileid();
       //List<AccountTeamMember> AccTeamMemList = new List<AccountTeamMember>();
       
       Set<ID> uidset = new Set<ID>(); 
             
       if(showcolumn == false){
              SingleUserCoverage = true;
          }
        if( SingleUserCoverage == true){
          uidset.add(UserId);
          system.debug('SINGLEUSERSET'+uidset);
          donotshow = true;
       }
          
        
       if(radiooption == 'MyCoverage'){
          uidset.add(UserId);
          system.debug('USERSET'+uidset);
          donotshow = true;
       }else if(radiooption == 'MyDeskCoverage'){
          donotshow = false;
         // List<User> uList = [SELECT id,name,profileid FROM user WHERE profileid=:pfid];
          for(User u:[SELECT id,name,profileid FROM user WHERE profileid=:pfid]){
            uidset.add(u.id);
            system.debug('DESKSET'+uidset);
          }  
        }
      
       // AccTeamMemList = [SELECT accountId, userId FROM AccountTeamMember WHERE userId IN: uidset]; 
         for(AccountTeamMember a:[SELECT accountId, userId FROM AccountTeamMember WHERE userId IN: uidset]){
                 AccTeamMemidSet.add(a.accountId);
         } 
         
         String SearchQuery ='';
        List<String> slist = new List<String>();
           String s='';
       if(AccTeamMemidSet.size() > 0){    
           slist.addAll(AccTeamMemidSet);
                
          for(integer i=0;i<slist.size();i++){
            if(i!=0)
            s+='OR Account__c='+'\''+slist[i]+'\'';
            } 

        s+=')';
      }   
           string whereclause = 'WHERE';
           whereClause += ' (CUSIP__c ='+'\''+inputValue+'\'';  
           whereClause += ' OR Bloomberg_Issuer_Ticker__c ='+'\''+inputValue+'\'';
           whereClause+=')';
           if(s != '')
             whereClause += ' AND ( Account__c =\''+slist[0]+'\''+s+'';
             whereClause += ' ORDER BY '+sortFullExp+' LIMIT 1000';
               
           searchQuery = 'SELECT id,name, Trade_ID__c, Trade_Date__c, Bloomberg_Issuer_Ticker__c, Sales_Person__c, '+
                         'Account__r.Name, CUSIP__c, Coupon_Rate__c, Maturity_Date__c, Buy_Sell__c, '+
                         'Par_Notional__c, Trade_Price__c, Spread__c, Sales_Credit__c '+
                         'FROM Trading_Activity__c '+whereClause;    
     
                      
          system.debug('&&&&&&&&QUERY:::::'+searchQuery);
          
          
                    
          con = new ApexPages.StandardSetController(Database.getQueryLocator(searchQuery));
               if(message == 'success' || sortmessage == 'aftersort')
                con.setPageSize(100);
                else
                 con.setPageSize(10);
                totalSize= con.getResultSize(); 
                sortFlag = false;
}
Return con;
}
Set;
}

/*-----------------------------SEARCH METHOD FOR USER INPUT-------------------------------------------*/
   
     
     public void SearchData() {
      
      con = null;
     // TAList = null;
    //  con1 = null;
     // TIList = null;
        
    /*  ipresultList =  [SELECT Account_Name__c,CUSIP__c,Ticker__c,Portfolio_Name__c,
                                 Par_Held__c,Par_Change__c,Position_Date__c,Source__c,
                                 Coupon_Rate__c,Maturity_Date__c 
                           FROM Ipreo__c
                          WHERE (CUSIP__c=:inputvalue OR Ticker__c=:inputvalue) ];*/
             
         
   }      
        
 /*----------------------------------END OF SEARCH METHOD--------------------------------------------*/ 
    
        
    //This method uses a simple SOQL query to return a List of TradingActivities
    public List<cTradingActivity> getTALists() {
            //  if(TAList == null) {
              TAList = new List<cTradingActivity>();
            for(Trading_Activity__c ta:(List<Trading_Activity__c>)con.getRecords()) {
                // As each TradingActivity is processed we create a new cTradingActivity object and add it to the TAList
                TAList.add(new cTradingActivity(ta));
              }
          // }
        return TAList;
    }
    
 public pagereference gotolist(){
        con = null;TAList = null;
        PageReference pageRef = Page.gotoTAlistIpreo1;
        pageRef.getParameters().put('msg','success');
       // pageRef.setRedirect(true);
        return PageRef;
      }
      
 public pagereference gototilist(){
        con1 = null;TIList = null;
        PageReference pageRef = Page.gotoTIlistIpreo;
        pageRef.getParameters().put('msg1','success');
       // pageRef.setRedirect(true);
        return PageRef;
      }     
      
  public pagereference ipgotolist(){
         pagereference p2 = new pagereference('/apex/gotoipList');
         return p2;
      }   
        
/* ----------------------WRAPPER FOR TRADING ACTIVITIES--------------------------------------------------*/
     
      
    public PageReference processSelected() {

                //We create a new list of TAs that we be populated only with TAs if they are selected
        selectedTAs = new List<Trading_Activity__c>();

        //We will cycle through our list of cTradingActivities and will check to see if the selected property is set to true, if it is we add the TradingActivity to the selectedTAs list
        for(cTradingActivity cta : TAList) {
        
            if(cta.selected == true) {
                selectedTAs.add(cta.tra);
                System.debug('These are the selected TAs...'+selectedTAs);
            }
        }
        //TAList.clear();  //
        // Now we have our list of selected TradingActivities and can perform any type of logic we want, sending emails, updating a field on the TA, etc
        System.debug('These are the selected TAs...'+selectedTAs.size());
       /* for(Trading_Activity__c tra : selectedTAs) {
            system.debug(tra);
            system.debug('@@@'+tra);
        }*/
      return Page.gotoTAlistIpreoExcel;
    }


    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class cTradingActivity {
        public Trading_Activity__c tra {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cTradingActivity object we pass a TA that is set to the ta property. We also set the selected value to false
        public cTradingActivity(Trading_Activity__c ta) {
            tra = ta;
           selected = false;
        }
    }
    
    //This method uses a simple SOQL query to return a List of TradingActivities
   /* public List<cTradingActivity> getTALists() {
       //if(TAList == null) {
            TAList = new List<cTradingActivity>();
            for(Trading_Activity__c ta:(List<Trading_Activity__c>)con.getRecords()) {
                // As each TradingActivity is processed we create a new cTradingActivity object and add it to the TAList
                TAList.add(new cTradingActivity(ta));
           }
        //}
        return TAList;
    }*/
    
    
/*----------------------------------END OF WRAPPER CLASS-------------------------------------------------*/


 
 
/*---------------------------------SORTING METHOD FOR TA------------------------------------------------*/

         public String sortExpression {
        get {
            return sortExpr;
        }
        set {
            if(value == sortExpr)
                sortDirection = (sortDirection == 'ASC') ? 'DESC' : 'ASC';
            else
                sortDirection = 'ASC';
            sortExpr = value;
        }
    }
     public String getsortDirection() {
        if(sortExpression == null || sortExpression == '')
            return 'ASC';
        else
            return sortDirection;
    }
    
    public void setsortDirection(String value) {
        sortDirection = value;
    }
    
    public String getsortExpr() {
        return sortExpr;
    }
    
    public void setsortExpr(String value) {
        sortExpr=value;
    }
    
     public PageReference sortData() {
        sortFlag = true;
        getTALists();     
      //  con.setPageNumber(1);
     return null;  
    }
    
   
   
 /*--------------------------------END-SORTING--------------------------------------------------------*/  
 
/*------------------------------PAGINATION FOR TA----------------------------------------------------*/   
      
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }
      public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }
    
     public Integer pageNumber {
        get {
            return con.getPageNumber();
        }
        set;
    }
    public void first() {
       
        con.first();
        
    }
    
    public void last() {
        con.last();
    }
    
    public void previous() {
        con.previous();
    }
    
   public void next() {
        con.next();
    }
/*--------------------END-PAGINATION FOR TA-------------------------------------*/   

 

  • August 09, 2012
  • Like
  • 0

I thought I'd share since figuring this out was kind of crappy.  Since you can't (or I couldn't find how) concatenate a string in an SOQL query to combine wildcards like % and _ to make a query, you need to do so with the variable you want to pass in.

 

So if you want to do an SOQL query using LIKE, wild cards, and an Apex variable, this will work.

 

//create a string
String s = 'mystring';

//add wildcards around it to be more flexible in the search
s = '%' + s + '%';

//create an SOBject list with the results from our query
SObject[] obj = [select id from SObjectName where Name LIKE :s];

 

and this will return any row from the SObjectName where the "Name" field has "mystring" in it.