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
Long TruongLong Truong 

Visualforce page keeps loadingand freeze

I have a custom object (contact request form ), and when you click the "Search Contact" button, it takes you to a VF page. When I use it as an internal Salesforce user, everything works fine. When I use it as a portal user , it used to work fine, but now the page keep loading and loading. When you click the "x" button on the browser, and click the "Search contact" button again, it works. What is wrong here? Thanks!
BDatlaBDatla
Hi Long truong,

I think you are having some infiniteloop issue in the controller.
Please check the controller constructor and action method.

Regards,
BDatla
Long TruongLong Truong

@BDatla:  Thanks for your suggestion. This is the controller:

public with sharing class TESTCRequestForm_SearchController {
  
  public TESTCRequestForm_SearchController(ApexPages.StandardController controller)
  { 
    cid=System.currentPageReference().getParameters().get('id');
    }
    
  Public String cid;                                                            
  public List<cContact> contactList {get; set;}                                 
  public boolean errormsg=false;
  public String errorDetail='';                                                
  String userinput1;                                                             
  String userinput2;
  String userinput3;                                                               

  Public boolean displayboxes;
  Public List<Contact> results = new List<Contact>();                                     

  Public List<Contact> selectedContactsstep2 = new List<Contact>();             
  Public List<Contact> cList = new List<Contact>();

  public String getuserinput1(){
    return userinput1;
    }
    
  public void setuserinput1(String userinp){
    this.userinput1=userinp;
    }
    
  public String getuserinput2(){
    return userinput2;
    }
    
  public void setuserinput2(String userinp){
    this.userinput2=userinp;
    }
    
  public String getuserinput3(){
    return userinput3;
    }
    
  public void setuserinput3(String userinp){
    this.userinput3=userinp;
    }
  public String geterrorDetail()
  { 
    return errorDetail;
  }  
    


  public List<Contact> contactsearch(){     
    errormsg=false;     
    contactList = new List<cContact>(); 
    if(userinput1=='' && userinput2=='' && userinput3=='')
    {
      errormsg=true;
      errorDetail='Please enter atleast one field to search for matching contact';
      contactList=null;
      return null;
    }    
    for(Contact c : [select Account.Name,Name,FirstName,LastName,Email,title,Id from Contact where FirstName like :userinput1+'%' and LastName like :userinput2+'%' and Account.Name like :userinput3+'%'])     
    {        
       contactList.add(new cContact(c));     
     } 
    return null;
    }

  public List<cContact> getresults()
  { 
    return contactList;
  }

  public class cContact{ 
    public Contact con {get; set;} 
    public Boolean selected {get; set;} 
    public cContact(Contact c) {     
    con = c;     
    selected = false; 
    }
  }

    
  public boolean geterrormsg()
  { 
    return errormsg;
  }

  
  public Pagereference createCRequestNew()
  {        
    Pagereference p =new Pagereference('/apex/CRequestNew'); 
           
    return p;
  }        
  
  public Pagereference createCRequest()
  {
    List<Contact> selectedContact = new List<Contact>(); 
    Pagereference p =new Pagereference('/a02/o');  
    if (contactList!= null)  {     
             
             for (cContact similarContact : contactList) {
                 if (similarContact.selected==true) {
                     selectedContact.add(similarContact.con);
                 }
         }
     if (selectedContact.size()==0) {     
      errormsg=true;
      errorDetail='Please select a contact to Modify';     
      return null; 
    } 
    else {     
      errormsg=false;
      String idField='';
      for (Contact selectedCont : selectedContact) {
      idField=selectedCont.Id;      
      }     
      p =new Pagereference('/apex/TEST_CRequestModify'+'?cid='+idField);     
      return p; 
    }        
    
  }
  return p;
  }
  public Pagereference createCRequestDelete()
  {
        List<Contact> selectedContact = new List<Contact>(); 
    Pagereference p =new Pagereference('/a02/o');  
    if (contactList!= null)  {     
             
             for (cContact similarContact : contactList) {
                 if (similarContact.selected==true) {
                     selectedContact.add(similarContact.con);
                 }
         }
     if (selectedContact.size()==0) {     
      errormsg=true;
      errorDetail='Please select a contact to Delete';     
      return null; 
    } 
    else {     
      errormsg=false;
      String idField='';
      for (Contact selectedCont : selectedContact) {
      idField=selectedCont.Id;      
      }     
      p =new Pagereference('/apex/TEST_Delete_contact_CRF'+'?cid='+idField);     
      return p; 
    }        
    
  }
  return p;


  }
  
  public Contact_Request_Form__c NewCRequest(Contact cContact)
    {
      
      Contact_Request_Form__c  c  = new Contact_Request_Form__c();
        c.Subgrantee_Name__c    =cContact.AccountId;           
        c.Last_Name__c       =cContact.LastName ;
      c.First_Name__c     =cContact.FirstName ;
       c.MI__c          =cContact.MI__c ;
      
       c.Fax_Phone__c      =cContact.Fax ;
       c.Mobile_Phone__c     =cContact.MobilePhone; 
       c.Home_Phone__c      =cContact.HomePhone ;
       c.Business_Phone__c    =cContact.OtherPhone ;
      
       c.Email_Address__c    =cContact.Email ;
       c.Job_Title__c      =cContact.Title; 
       c.Department_B__c      =cContact.Department;
       c.Department_S__c      =cContact.Shipping_Department__c;
       
       c.Organization_S__c    =cContact.Shipping_Organization__c;
       c.Organization_B__c    =cContact.Mailing_Organization__c;
           
      
       c.Address_Line_1B__c    =cContact.Contact_Mailing_Street_1__c;  
      c.Address_Line_2B__c    =cContact.Contact_Mailing_Street_2__c ; 
       c.City_B__c        =cContact.Contact_Mailing_City__c ; 
       c.Zip_Code_B__c      =cContact.Contact_Mailing_Zip_Code__c ; 
       c.Business_State__c    =cContact.Contact_Mailing_State__c  ;
      
       c.SSAI_Fiscal__c     =cContact.SSAI_Fiscals__c  ;
       c.SSAI_Spon__c      =cContact.SSAI_Sponsors__c  ;
       c.SSAI_Directors__c    =cContact.SSAI_Directors__c  ;
       c.D2D_Contacts__c      =cContact.D2D_Contacts__c  ;
      
       c.Address_Line_1S__c    =cContact.Contact_Shipping_Street_1__c;  
       c.Address_Line_2S__c    =cContact.Contact_Shipping_Street_2__c ; 
       c.City_S__c        =cContact.Contact_Shipping_City__c  ;
       c.Zip_Code_S__c      =cContact.Contact_Shipping_Zip_Code__c;  
       c.Shipping_State__c    =cContact.Contact_Shipping_State__c  ;
      
       //c.Fax_Phone__c      =cContact.Contact_Fax__c  ;
       c.Fax_Phone__c      =cContact.Fax  ;
       c.Contact__c      =cContact.Id;
       
       
       return c;
      
      
    }
    public Pagereference createCModify()
  {
  errormsg=false;
  String idField='';
  idField=cid;      
  Pagereference p  =new Pagereference('/apex/CRequestModify'+'?cid='+idField);     
  return p;
  }
  
  public Pagereference createCDelete()
  {
    Pagereference p =new Pagereference('/a02/o');       
    errormsg=false;
    Contact cContact=[Select Id,LastName,FirstName,MI__c,Fax,MobilePhone,HomePhone,OtherPhone,Email,Title,Contact_Mailing_Street_2__c
                        ,Contact_Mailing_City__c ,Contact_Mailing_Zip_Code__c ,SSAI_Sponsors__c,SSAI_Directors__c,Department,Contact_Mailing_Street_1__c ,
                        SSAI_Fiscals__c,D2D_Contacts__c,Contact_Shipping_Street_1__c ,Contact_Shipping_Street_2__c ,Contact_Shipping_City__c ,
                        Contact_Shipping_Zip_Code__c ,Contact_Fax__c ,Contact_Mailing_State__c ,Contact_Shipping_State__c,Shipping_Organization__c,
                        Mailing_Organization__c,Shipping_Department__c,AccountId from Contact where id =:cid limit 1];
        Contact_Request_Form__c newRec =NewCRequest(cContact);
        newRec.Status__c='Submitted';
        newRec.Is_Delete_Request__c=true;
    insert newRec;           
    return p;
  }
  
}
BDatlaBDatla
Hi,
Can you please share VF page .

Regards,
BDatla
 
Long TruongLong Truong

This is the VF page to search contact:

<apex:page standardcontroller="Contact_Request_Form__c" extensions="TESTCRequestForm_SearchController" >
<script>
function checkAll(cb)
{   
var inputElem = document.getElementsByTagName("input");  
for(var j=0;j<inputElem.length;j++)    
 {             
 if(inputElem[j].id.indexOf("selectLine1")!=-1)                  
    inputElem[j].checked = false;
 }
cb.checked=true;
}
</script>
    <apex:form >
    <apex:sectionHeader title="Create or Modify Existing Contact"/>
    <apex:pageblock mode="edit">
    <apex:pagemessage strength="2" title="Description" severity="Info" detail="[New]- Creates a New Contact Request Form for modifying a existing a Contact or create New Contact" />
    <div style="border-width:1px;border-style:solid;border-color:light gray;">    
        <apex:panelGrid columns="2">        
            <apex:outputLabel style="font-weight:bold;" value="First Name" >
            </apex:outputLabel>        
            <apex:inputText value="{!userinput1}"/> 
            <apex:outputLabel style="font-weight:bold;" value="Last Name" >
            </apex:outputLabel>        
            <apex:inputText value="{!userinput2}"/> 
            <apex:outputLabel style="font-weight:bold;" value="Organization" >
            </apex:outputLabel>        
            <apex:inputText value="{!userinput3}"/>        
        </apex:panelGrid>   
        <div style="position:relative;left:75px;">             
            <apex:commandButton value="Search Contact" action="{!contactsearch}" />
            <apex:commandButton value="Create New Contact" action="{!createCRequestNew}" />         
        </div> 
    
        <br/>
    </div>
    <br/>
     
     <apex:pagemessage strength="2" title="Error!!" severity="error" detail="{!errorDetail}" rendered="{!errormsg}"/>
     
     <apex:pageblocksection columns="1" title="Search results" rendered="{!NOT(ISNULL(results))}" >  
        <apex:outputpanel id="Contactlist">        
             <apex:pageBlockTable value="{!results}" var="contacts">             
                <apex:column >                
                    <apex:facet name="header">                   
                    </apex:facet>                    
                    <apex:inputCheckbox value="{!contacts.selected}" id="selectLine1" onclick="checkAll(this)"/>            
                 </apex:column>            
                 <apex:column headervalue="Contact Name">                
                    <apex:outputtext value="{!contacts.con.Name}"/>            
                 </apex:column>            
                 <apex:column headervalue="Subgrantee Name">                
                    <apex:outputtext value="{!contacts.con.Account.Name}"/>           
                  </apex:column>           
                  <apex:column headervalue="Title">                
                    <apex:outputtext value="{!contacts.con.Title}"/>            
                  </apex:column>        
              </apex:pageBlockTable> 
   
        </apex:outputpanel>
      </apex:pageblocksection>
       
      <div style="position:relative;left:75px;">      
          <apex:commandButton value="Modify" action="{!createCRequest}"/>      
          <apex:commandbutton value="Delete" action="{!createCRequestDelete}"/>  
      </div>
      </apex:pageblock>
      </apex:form>
      </apex:page>
Long TruongLong Truong
This is what the page look like:
When you type in "First name" and then click on "Search Contact", it keeps on loading and loading
User-added image
BDatlaBDatla
Hi,

Can you please run the below query as portal user and other user and let me know the count separately?

select Account.Name,Name,FirstName,LastName,Email,title,Id from Contact whereFirstName like :userinput1+'%' and LastName like :userinput2+'%' and Account.Name like :userinput3+'%']

May be it is taking lot of time to process the collection ??

Regads,
BDatla
 
Long TruongLong Truong
How do you do that (run the query alone as different user)? I'm not a developer, this was created a long time ago by consultants.

Thanks,
BDatlaBDatla
Hi ,
replace portaluser id in the below query and execute in the developer console execute anonymous let me know the result.
User u = [select Id from user where Id =' please type the ID here']
System.runAs(u) {
                List<contact> contactList = [select Account.Name,Name,FirstName,LastName,Email,title,Id from Contact whereFirstName like                                                                                 :userinput1+'%' and LastName like :userinput2+'%' and Account.Name like :userinput3+'%'];
                System.debug('contactList size : ' + contactList.size() );

}
check in the debug log the value for contactList size :.

Regards,
BDatla
Long TruongLong Truong
I put in the portal user id, and have an error:
Line: 2, Column: 0
unexpected token: 'System.runAs'
User u = [select Id from user where Id ='005F0000004y25sIAA']
System.runAs(u) {
                List<contact> contactList = [select Account.Name,Name,FirstName,LastName,Email,title,Id from Contact whereFirstName like:userinput1+'%' and LastName like :userinput2+'%' and Account.Name like :userinput3+'%'];
                System.debug('contactList size : ' + contactList.size() );

}

 
Long TruongLong Truong
Ok, I found out the problem: runAs can only be run in a test class, and test class cannot be run from the execute anonymous window. Do you have any idea?

Thanks,
Long TruongLong Truong

I added a debug log on the portal user, does this make any sense?

31.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:36:41.055 (55311882)|EXECUTION_STARTED
15:36:41.055 (55364413)|CODE_UNIT_STARTED|[EXTERNAL]|066F0000002GMTn|VF: /apex/TESTSearchContact
15:36:41.067 (67636777)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController <init>
15:36:41.067 (67654776)|SYSTEM_MODE_ENTER|true
15:36:41.068 (68839766)|METHOD_ENTRY|[1]|01pF0000003gua8|TESTCRequestForm_SearchController.TESTCRequestForm_SearchController()
15:36:41.068 (68884798)|SYSTEM_MODE_ENTER|false
15:36:41.068 (68891955)|SYSTEM_MODE_EXIT|false
15:36:41.068 (68902095)|METHOD_EXIT|[1]|TESTCRequestForm_SearchController
15:36:41.069 (69117398)|SYSTEM_MODE_ENTER|false
15:36:41.069 (69178724)|SYSTEM_CONSTRUCTOR_ENTRY|[17]|<init>()
15:36:41.069 (69225561)|SYSTEM_CONSTRUCTOR_EXIT|[17]|<init>()
15:36:41.069 (69236106)|SYSTEM_CONSTRUCTOR_ENTRY|[19]|<init>()
15:36:41.069 (69246100)|SYSTEM_CONSTRUCTOR_EXIT|[19]|<init>()
15:36:41.069 (69252463)|SYSTEM_CONSTRUCTOR_ENTRY|[20]|<init>()
15:36:41.069 (69259898)|SYSTEM_CONSTRUCTOR_EXIT|[20]|<init>()
15:36:41.069 (69285291)|SYSTEM_METHOD_ENTRY|[5]|System.currentPageReference()
15:36:41.069 (69319095)|SYSTEM_METHOD_EXIT|[5]|System.currentPageReference()
15:36:41.069 (69338549)|SYSTEM_METHOD_ENTRY|[5]|System.PageReference.getParameters()
15:36:41.069 (69371707)|SYSTEM_METHOD_EXIT|[5]|System.PageReference.getParameters()
15:36:41.069 (69394885)|SYSTEM_METHOD_ENTRY|[5]|Map<String,String>.get(Object)
15:36:41.069 (69408883)|SYSTEM_METHOD_EXIT|[5]|Map<String,String>.get(Object)
15:36:41.069 (69417291)|SYSTEM_MODE_EXIT|false
15:36:41.069 (69429926)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController <init>
15:36:41.069 (69777633)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController get(errormsg)
15:36:41.069 (69786483)|SYSTEM_MODE_ENTER|true
15:36:41.069 (69803988)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController invoke(geterrormsg)
15:36:41.069 (69833102)|SYSTEM_MODE_ENTER|false
15:36:41.069 (69840903)|SYSTEM_MODE_EXIT|false
15:36:41.069 (69848104)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController invoke(geterrormsg)
15:36:41.069 (69857705)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController get(errormsg)
15:36:41.069 (69935917)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController get(results)
15:36:41.069 (69943805)|SYSTEM_MODE_ENTER|true
15:36:41.069 (69953753)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController invoke(getresults)
15:36:41.069 (69981497)|SYSTEM_MODE_ENTER|false
15:36:41.069 (69994654)|SYSTEM_METHOD_ENTRY|[71]|TESTCRequestForm_SearchController.__sfdc_contactList()
15:36:41.070 (70012227)|SYSTEM_METHOD_EXIT|[71]|TESTCRequestForm_SearchController.__sfdc_contactList()
15:36:41.070 (70018389)|SYSTEM_MODE_EXIT|false
15:36:41.070 (70024605)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController invoke(getresults)
15:36:41.070 (70033365)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController get(results)
15:36:41.087 (87796517)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController get(userinput1)
15:36:41.087 (87812648)|SYSTEM_MODE_ENTER|true
15:36:41.087 (87824887)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController invoke(getuserinput1)
15:36:41.087 (87854686)|SYSTEM_MODE_ENTER|false
15:36:41.087 (87866242)|SYSTEM_MODE_EXIT|false
15:36:41.087 (87872818)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController invoke(getuserinput1)
15:36:41.087 (87881916)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController get(userinput1)
15:36:41.088 (88058492)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController get(userinput2)
15:36:41.088 (88078294)|SYSTEM_MODE_ENTER|true
15:36:41.088 (88100297)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController invoke(getuserinput2)
15:36:41.088 (88137375)|SYSTEM_MODE_ENTER|false
15:36:41.088 (88151041)|SYSTEM_MODE_EXIT|false
15:36:41.088 (88162405)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController invoke(getuserinput2)
15:36:41.088 (88184971)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController get(userinput2)
15:36:41.088 (88284507)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController get(userinput3)
15:36:41.088 (88292254)|SYSTEM_MODE_ENTER|true
15:36:41.088 (88302028)|CODE_UNIT_STARTED|[EXTERNAL]|01pF0000003gua8|TESTCRequestForm_SearchController invoke(getuserinput3)
15:36:41.088 (88328266)|SYSTEM_MODE_ENTER|false
15:36:41.088 (88335900)|SYSTEM_MODE_EXIT|false
15:36:41.088 (88341831)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController invoke(getuserinput3)
15:36:41.088 (88350376)|CODE_UNIT_FINISHED|TESTCRequestForm_SearchController get(userinput3)
15:36:41.090 (90834342)|VF_SERIALIZE_VIEWSTATE_BEGIN|066F0000002GMTn
15:36:41.093 (93311810)|VF_SERIALIZE_VIEWSTATE_END
15:36:41.952 (95835825)|CUMULATIVE_LIMIT_USAGE
15:36:41.952|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

15:36:41.952|CUMULATIVE_LIMIT_USAGE_END

15:36:41.095 (95867405)|CODE_UNIT_FINISHED|VF: /apex/TESTSearchContact
15:36:41.097 (97475282)|EXECUTION_FINISHED
BDatlaBDatla

Hi ,

Ok,I thought as you are not a developer you may find bit difficult to find the debug log thats why i said to run the query
Can you please get the debug log after clicking the "Search Contact" button ,as you facing issue after clicking this button.

After that please add the below test class and let me now the result if possible post the debug log for this one too.

@isTest  private class testloop{
static testMethod void testloopcount() {
User u = [select Id from user where Id ='005F0000004y25sIAA']
System.runAs(u) {
      List<contact> contactList = [select Account.Name,Name,FirstName,LastName,Email,title,Id from Contact whereFirstName                                                                             like:userinput1+'%' and LastName like :userinput2+'%' and Account.Name like :userinput3+'%'];
     System.debug('contactList size : ' + contactList.size() );
 }

}

}

Regards,
BDatla