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
ForceLoverForceLover 

Regarding Test class

 I have a inputtext  in my VF page  as

 

        <apex:pageBlockSection >
         <apex:pageblockSectionItem >
          <apex:outputLabel for="searchText" style="font-size:14px">RefID/FileNumber</apex:outputLabel>
          <apex:panelGroup >
          <apex:inputText id="searchText" value="{!searchText}"/>
          <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>
          </apex:panelGroup>
         </apex:pageblockSectionItem>
        </apex:pageBlockSection>

 

I'm using that text field in my controller to compare one of my text field in the LeadBackup__c object as

 

public PageReference search() {
   // String qry = 'select id,Ref_ID_File_Number__c, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,DoNotCall__c from LeadBackup__c' + where Ref_ID_File_Number__c = searchText  order by name';
    searchResults1 = [select id,RefID_FileNumber__c,Name, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, TAB_Time_stamp__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,Do_Not_Call__c from LeadBackup__c where RefID_FileNumber__c =:searchText  order by name];
    //searchResults = Database.query(qry);
   
     
     //searchResults = [select id, name, FirstName, LastName, Status, Ref_ID_File_Number__c, Email, Phone, Street, City, State, Country, PostalCode, TAB_Message__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,DoNotCall from Lead where Ref_ID_File_Number__c =:searchText  order by name];

   
    if(searchResults1.size()==0){

          LeadBackup__c lb = new  LeadBackup__c(RefID_FileNumber__c = searchText,
                                                Name=[select name,id from lead where Ref_ID_File_Number__c=:searchtext ].Name,
                                                City__c=[select name,id,city from lead where Ref_ID_File_Number__c=:searchtext ].City,
                                                Street__c=[select name,id,street from lead where Ref_ID_File_Number__c=:searchtext ].street,
                                                State__c=[select name,id,state from lead where Ref_ID_File_Number__c=:searchtext ].state,
                                                Lead__c = [select name,id from lead where Ref_ID_File_Number__c=:searchtext ].id,
                                                Email__c = [select name,id,Email from lead where Ref_ID_File_Number__c=:searchtext ].Email,
                                                Phone__c = [select name,id,Email,Phone from lead where Ref_ID_File_Number__c=:searchtext].Phone,
                                                Evening_Phone__c = [select name,id,Evening_Phone__c  from lead where                 Ref_ID_File_Number__c=:searchtext ].Evening_Phone__c,
                                                Preferred_Call_Time__c = [select name,id,Evening_Phone__c,Preferred_Call_Time__c   from lead where Ref_ID_File_Number__c=:searchtext ].Preferred_Call_Time__c,
                                                Notes__c = [select name,id,Evening_Phone__c,Notes__c   from lead where Ref_ID_File_Number__c=:searchtext ].Notes__c,
                                                Do_Not_Call__c = [select name,id,Evening_Phone__c,DoNotCall   from lead where Ref_ID_File_Number__c=:searchtext ].DoNotCall);
          //searchResults.add(lb);
          system.debug('lb'+lb);
          insert lb ;
          
          searchResults = [select id,RefID_FileNumber__c,Name, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, TAB_Time_stamp__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,Do_Not_Call__c from LeadBackup__c where RefID_FileNumber__c =:searchText  order by name];

          
    }else{
    
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'<b>Please confirm name and address below. Address will be where the letter was received/addressed. If these do not match, you will need to re-verify Ref ID, as it may have been entered incorrectly</b>'));
       
       searchResults = [select id,RefID_FileNumber__c,Name, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, TAB_Time_stamp__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,Do_Not_Call__c from LeadBackup__c where RefID_FileNumber__c =:searchText  order by name];

       return null;
    }
    return null;
  }
 
 
  public PageReference save() {
   
   if(!(String.isEmpty(searchText))){  -----------------From Here my code is not covering how to pass this search text in test class
          
       try {
            
            list<LeadBackup__c> lstupdate = new list<LeadBackup__c>();
            
                 
             For(LeadBackup__c le:searchResults){
             
             //le.Id = lead.Id;
             le.RefID_FileNumber__c = searchResults[0].RefID_FileNumber__c ;
             le.Lead__c = [select name,id from lead where Ref_ID_File_Number__c=:searchtext ].id;
             le.Name = searchResults[0].Name;
             le.Email__c = searchResults[0].Email__c;
             le.Phone__c = searchResults[0].Phone__c;
             le.Evening_Phone__c = searchResults[0].Evening_Phone__c ;
             le.Preferred_Call_Time__c = searchResults[0].Preferred_Call_Time__c;
             le.Notes__c = searchResults[0].Notes__c;
             le.Do_Not_Call__c = searchResults[0].Do_Not_Call__c;
             le.TAB_Message__c = True;
             le.TAB_Time_stamp__c = System.now();
             lstupdate.add(le);
             }
             
             update lstupdate;
      
      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Record <b>'+searchResults[0].Name+'</b> has been Updated'));
            
    } Catch (DMLException e) {
      ApexPages.addMessages(e);
      return null;
    }
   
    searchText='';
    searchResults.clear();
    return null;
       
  }
  else
  {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Please enter REFID/FileNumber'));
  }
 
  return null;
 
}

 

How to pass this search text to the test class ......

Any help would appreciated greatly...

 

 

sfdcfoxsfdcfox
Set ext.searchText to some value (where ext is the variable for your controller or extension inside the test method).
Avidev9Avidev9

Should be easy.

From your test class you must be initializing the controller class.

 

Do something like this to set the value

 

Controller con = new Controller();
con.searchText = 'My String';

 

ForceLoverForceLover
Thanks for Both of you....
basic question from my side....
ForceLoverForceLover
A small question how can i move my site from sandbox to production with changesets....
i couldn't find the sites on add components list in change sets
Devendra@SFDCDevendra@SFDC

Hi,

 

You can not directly deploy site from sandbox to production org.

 

You need to form a changeset for apex classes, objects, pages, static resources and other components that used to build a site on sandbox. These all components needs to deploy to production.

 

In production org, you need to create a new site, provide the settings manually similar to sandbox site (Guest User profile settings) and you are good to launch production site.