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
Mitchell SpanoMitchell Spano 

Auto scroll to VF page

Hello,

I need some help - we are using person acocunts and we have an embedded visualforce page on the account's page layout.
For some reason, when an account's record is open, the UI automatically scrolls to that visualforce page, and I don't know why.

Here is the VF page code - 

<apex:page standardController="Account" extensions="GoalOperations1" id="page">
 
  
 
   <script>
     function ChangeRow1(first , second){
        var size='{!sizeofGoal}';
               
         if(parseInt(size, 10) < parseInt(first, 10) || first==null || first ==0 || parseInt(first, 10)<0 ){
          alert('row number '+first+' does not Exist');
        document.getElementById('page:form:pageblock:table1:'+second+':number').value =parseInt(second, 10)+1;         
          
         }else{
          ChangeRow(first,second);
          }
     
     }
   </script>
 
      <apex:form id="form">
    <apex:variable var="rowNum1" value="{!0}"  />
     <apex:variable var="order" value="{!0}"  />
    <apex:pageMessages id="id1"></apex:pageMessages>
         <apex:outputPanel id="table" >
        <apex:pageBlock title="Financial Concerns" id="pageblock" >
           
          <apex:variable var="rowNum" value="{!0}"  />
            <apex:pageBlockTable value="{!Goals}" var="g" id="table1" width="10%"  >
                    <apex:column headerValue="Order" id="order" width="5%"><apex:inputField onchange="ChangeRow1(document.getElementById('{!$Component.number}').value,'{!rowNum}');"  id="number" style="width:30px;text-align:center;" value="{!g.Order__c}" /> </apex:column>
                  <apex:column headerValue="Tier 1" id="col1" width="10%"> <apex:inputField value="{!g.Level_1_Goals__c}" />  </apex:column>
                  <apex:column headerValue="Tier 2" id="col2" width="10%"><apex:inputField value="{!g.Level_2_Goals__c}"/>  </apex:column>
                  <apex:column headerValue="Description" width="10%" >
                
                    <apex:inputField value="{!g.Comments__c}"  />
                  
                    </apex:column>
                  <apex:column headerValue="Time Frame" id="col4" width="10%"><apex:inputField value="{!g.Time_Frame__c}" />  </apex:column>
                  <apex:column headerValue="Validated Date" id="col6" width="10%"><apex:inputField value="{!g.Validated_Date__c}"  />  </apex:column>
                  <apex:column headerValue="Status" id="col5" width="10%"><apex:inputField value="{!g.Status__c}" />  </apex:column>
                  <apex:column headerValue="Action" width="10%">
                    <apex:commandLink value="Delete" action="{!processDeleted}" reRender="table" >
                           <apex:param value="{!rowNum}" name="index" />
                        </apex:commandLink>
                     <apex:variable var="rowNum" id="rowNum" value="{!rowNum+1}"/>                
                  </apex:column>
                   
            </apex:pageBlockTable>       
            <apex:actionFunction name="ChangeRow" status="status"  action="{!UpdateRow}" rerender="table">
             <apex:param value="" name="first"  > </apex:param>
             <apex:param value=""  name="Second"/>        
            
             </apex:actionFunction>
            
              <apex:outputpanel >
                <apex:actionstatus id="status">
                <apex:facet name="start">
                <div id="el_loading" style="background-color: #fbfbfb;height: 100%;opacity:0.65;width:100%;">
                <div style="top: 74.2px; width: 91px;">
                <img src="/img/loading.gif" title="Please Wait…" />
                <span>Loading…</span>
                </div>
                </div>
                </apex:facet>
                </apex:actionstatus>
             </apex:outputpanel>
           
        </apex:pageBlock>
        </apex:outputPanel>
          <div align="center">
             
              <apex:commandLink value="Save" action="{!SaveAndClose}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/>
              <!--<apex:commandButton value="Save" action="{!UpsertGoalRecord}" rerender="table"/> &nbsp;&nbsp;-->
             <apex:commandButton value="Save and Add" action="{!saveAndAdd}" rerender="table"/> &nbsp;&nbsp;
              <!--apex:commandButton value="Reorder" action="{!Reorder}" rerender="table"/--> &nbsp;&nbsp;
           
            </div>
            <br/>
            <br/>
            <br/>
            <div align="center">
            <p style="font-weight:italic;font-size:16px;" >********* This information is for ‘CRM’ purposes only and is not intended as a replacement for the information maintained in other systems. *********</p>
            </div>
    </apex:form>
</apex:page>
 
Mitchell SpanoMitchell Spano
Here is the class

Public Class GoalOperations1{
    public String first{get;set;}
    public String Second{get;set;}
    Account acc {get; set;}

    public String getsizeofGoal(){
        return String.valueof(GoalList.size()); 
    }
    public void setsizeofGoal(String sizeofGoal){
        sizeofGoal=sizeofGoal;
    }  
    public List<Goal__C> GoalList {get; set;}
    public List<Goal__C> GoalNewOrderList = new List<Goal__C>(); 
    Id clientId = apexpages.currentpage().getparameters().get('id');
    Boolean Saveflag =false;
    Integer counter  = 0;
    Boolean deleteflag = false;
    public Integer rowNum{get ; set ;}
    
   public GoalOperations1(ApexPages.StandardController controller) {

  this.Acc= (Account)controller.getRecord();
  
}
    
    public List<Goal__C> getGoals() {
    if(GoalList == null) {
    GoalList = new List<Goal__C>();
    } 
    if(deleteflag==false){
        if(!Saveflag  ){
            if(counter== 0){
            Integer num=1;
            try{
            List<Goal__C>  tempGoal  =  [select id,name,Level_1_Goals__c,Level_2_Goals__c,Client__c,Time_Frame__c,Order__C,Priority__c,Validated_Date__c,
                                         Goal_Description__c,Comments__c,status__C From Goal__C where client__c=:clientId  ]; 
            Reorder(tempGoal);
            Integer Assign=  tempGoal.size();
            for(Goal__C goals: tempGoal) {
                  if(goals.order__C==null){
                  goals.order__C=Assign;
                  Assign--;
                  GoalNewOrderList.add(goals);
                  }else{
                  if(goals.order__C!=num){
                    goals.order__C=num;
                    GoalNewOrderList.add(goals);
                   } 
                  }
                  GoalList.add(goals);
                  num++;
                  
            }
            }catch(Exception e){ }
                 counter++;
            if(GoalList.size()!=0 && num>1 ){
                 // Update GoalList;
            } 
            Integer i =GoalList.size();
            system.debug('****'+'outside else***'+i); 
            if(i<5){
            while(i<5){
            Goal__C goals = new Goal__C();
            goals.order__C=i+1;
            GoalList.add(goals);
             i++;
            }
            
            }
               Reorder(GoalList);
            }
            system.debug('****'+'inside if----'+GoalList.size());
           // saveflag=true;
            }else{
                Saveflag =false;
            }
                      
      } else{
         deleteflag =false;
      } 
           
        
        return GoalList;
    }
     
     Public PageReference SaveAndClose(){
         UpsertGoalRecord();
        
         pagereference goalPage = new PageReference('/'+clientId );
         return goalPage ;
      }
   

      Public void SaveAndAdd(){
           Saveflag = true;
           UpsertGoalRecord();    
           Integer i =0;
           system.debug('****'+'in else');
           if(i<5){
              while(i<5){
                Goal__C goals = new Goal__C();
                goals.Validated_Date__c=Date.TODAY();
                goals.order__C= GoalList.size()+1;
                GoalList.add(goals);
                
                 i++;
           } 
           }

      }
      
      
      public void UpsertGoalRecord(){  
        List<Goal__C> upd = new List<Goal__C>();
        //try{
        for(Goal__C s: GoalList  ){
         
        if(!String.isBlank(s.Level_1_Goals__c) || !String.isBlank(s.Level_2_Goals__c)  || !String.isBlank(s.Time_Frame__c)  ||
            !String.isBlank(s.comments__c )){
              system.debug('+++++++++'+s.Level_1_Goals__c+'level1'+s.Level_2_Goals__c+'level2'+s.Time_Frame__c+'Time frame'
                 +s.Status__c+'Status'+s.comments__c+'Comments'
              );
                  
              s.client__c=clientId;         
              upd.add(s);
       }
          
        }
         upsert upd;

            
        
      } 

    public PageReference processDeleted() {

               
        List<Goal__C> deletedGoal = new List<Goal__C>();
       
        rowNum = Integer.valueOf(ApexPages.currentPage().getParameters().get('index'));
        if((GoalList[rowNum].id !=null) &&( GoalList[rowNum].Level_1_Goals__c!=null || GoalList[rowNum].Level_2_Goals__c!=null ||
                                        GoalList[rowNum].comments__c!=null ||GoalList[rowNum].Time_Frame__c!=null || GoalList[rowNum].Status__c!=null)){
           if(GoalNewOrderList !=null && GoalNewOrderList.size()!=0){
              update GoalNewOrderList ;
           }
           delete GoalList[rowNum] ;
                         
        }
        GoalList.remove(rowNum);
        deleteflag = true;
        system.debug('*****'+rownum);
               
   
        integer i =0;
        for(Goal__C goals:[select id,name,Level_1_Goals__c,Level_2_Goals__c,Client__c,Time_Frame__c,Order__C,Priority__c,
                           Goal_Description__c,Comments__c,Validated_Date__c,status__C From Goal__C where client__c=:clientId  ]) {
             goalList[i]= goals;
                i++;             
             }
        i=rownum;
        while(i<goalList.size()){
        goalList[i].order__c=i+1;               
        i++;
        }

                          
        Reorder(goalList);
        //  delete deletedGoal;
        return null;
    }

  
   public PageReference Reorder(List<Goal__C> goalList){
          for (Integer c = 0 ; c < (GoalList.size()- 1 ); c++)
          {
            for (Integer d = 0 ; d <GoalList.size() - c - 1; d++)
            {
              if (GoalList[d].order__c > GoalList[d+1].order__c) /* For decreasing order use < */
              {
             Goal__c  swap  = GoalList[d];
                GoalList[d]   = GoalList[d+1];
                GoalList[d+1] = swap  ;
              }
            }
          }
     return null;
   }
   
 public PageReference UpdateRow(){
  
              
     first= Apexpages.currentPage().getParameters().get('first');
     second= Apexpages.currentPage().getParameters().get('second');
     Integer numb = Integer.ValueOf(first);
     Integer rowNum1= Integer.ValueOf(second);
      
      try{
       Goal__c g=GoalList[rowNum1];
         GoalList.remove(rowNum1);
        if(GoalList.size()==numb-1){
          GoalList.add(g);
        }else{
         GoalList.add(numb-1,g);
       }
       
       if(numb >(rowNum1+1)){
         Integer i = numb-1;
         while(i>rownum1){
             GoalList[i-1].order__C = i;
             i--;            
         }
       }  
        if(numb <(rowNum1+1)){
         Integer i = numb;
         while(i<rownum1+1){
             GoalList[i].order__C = i+1;
             i++;            
         }
       }  
       
     }catch(Exception e){}  
     return null;

   }
  
}