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
NikunjVadiNikunjVadi 

page isn't getting redirected

hey,

In my code when i click on command button, data is getting inserted and updated, but page isn't getting redirected after click.  
please help me out here:
code:

vf page:
<apex:page standardController="Project__c" sidebar="false" showHeader="false" extensions="ProjectTime_Controller" id="TimeTrack" standardStylesheets="true" docType="html-5.0">
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
            <meta name="viewport" content="width=device-width, initial-scale=1"/>
            <meta name="description" content=""/>
            <meta name="author" content=""/>
    
            <title>Time Station</title>
    
            <!-- Bootstrap core CSS -->
            <apex:stylesheet value="{!URLFOR($Resource.Bootstrap3_3_2, '/bootstrap-3.3.2-dist/css/bootstrap.min.css')}" />
            <!-- Bootstrap theme -->
            <apex:stylesheet value="{!URLFOR($Resource.Bootstrap3_3_2, '/bootstrap-3.3.2-dist/css/bootstrap-theme.min.css')}" />
        </head>

        <body role="document">
            <div class="panel panel-default">
            <div class="panel-body">  
            <div class="well">
                <p>Bonjour {!$User.FirstName} {!$User.LastName}</p>
            </div>
            <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">Time Station</h3>
            </div>
            <div class="panel-body">
            
            

    <apex:includeScript value="{!$Resource.modernizr}"/>
    
    <script>
        function doTheGeoThang1()
            {
            if (Modernizr.geolocation){
                navigator.geolocation.getCurrentPosition(
                function(position) {
                    loc1(position.coords.latitude,position.coords.longitude);
                }
                );
            }
            else 
            {
                alert ("Your browser isn't hit. Upgrade man!");
            }
            }
            function doTheGeoThang2() {
                if (Modernizr.geolocation){
                    navigator.geolocation.getCurrentPosition(
                function(position) {
                   loc2(position.coords.latitude,position.coords.longitude);
                }
            );
            }
            else {
                alert ("Your browser isn't hit. Upgrade man!");
                }
            }
    </script>
    
    <apex:form >
                <apex:actionRegion >
                    <center><apex:commandButton value="Punch In" onclick="doTheGeoThang1();" rendered="{!renderbutton}" /></center>
                        <apex:actionFunction name="loc1" action="{!PunchIn}" rerender="jsvalues">
                        <apex:param name="lat" value="" assignTo="{!valueLat}"/>
                        <apex:param name="long" value="" assignTo="{!valueLong}"/>
                        </apex:actionFunction>
                   <apex:outputPanel id="jsvalues"></apex:outputPanel>
                </apex:actionRegion>
                <apex:actionRegion >
                        <center><apex:commandButton value="Punch out" onclick="doTheGeoThang2();" rendered="{!render_pout}" /></center>
                        <apex:actionFunction name="loc2" action="{!PunchOut}" rerender="jsvaluespanel">
                        <apex:param name="lat" value="" assignTo="{!valueLat}"/>
                        <apex:param name="long" value="" assignTo="{!valueLong}"/>
                        </apex:actionFunction>
                    <apex:outputPanel id="jsvaluespanel"></apex:outputPanel>
                </apex:actionRegion>
                <br/><b>Name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><apex:outputField value="{!Project__c.Name}"/>
                <br/><br/><b>Account &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><apex:outputField value="{!Project__c.Account__c}"/>
                <br/><br/><b>Total Project Time &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><apex:outputField value="{!Project__c.Total_Project_Time__c}"/>
                <br/><br/><b>Client &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><apex:outputField value="{!Project__c.Client_Rate__c}"/> <br/> <br/>
              
    </apex:form>
            </div>
            </div>
            </div>
            </div>
        <center><apex:relatedList list="Project_time__r" title="Times" /> </center>

        </body>
    </html>
</apex:page>

controller:
 
public class ProjectTime_Controller {
      Apexpages.StandardController controller;
      public Project__c myCustomObject;
      public boolean renderbutton{get;set;}
      public boolean render_pout{get;set;}
 
      public ProjectTime_Controller (ApexPages.StandardController sc) {
          this.controller = sc;
          myCustomObject = (Project__c) sc.getRecord();   
          Id pageid = controller.getId();

          list<Project_Time__c> results = [select Name,id,Active__c  From Project_Time__c WHERE Active__c = True AND Project__c =:pageid AND Owner.id = :UserInfo.getUserId() Limit 1];

//count of active times
          Integer num = [select count() From Project_Time__c WHERE Active__c = True AND Project__c =:pageid AND Owner.id = :UserInfo.getUserId() Limit 1];
          if(num<1)
          {
              renderbutton=true;
              render_pout=false;
          }
          else
          {
              renderbutton=false;
              render_pout=true;
          }
          System.Debug(renderbutton);
       }

    public double valueLong { get; set; }
    public double valueLat { get; set; }
 
//Action functionality for PunchIn CommandButton
        public pagereference PunchIn() {
        Id pageid = controller.getId();
    
        Integer PunchCount = [select count() From Project_Time__c WHERE Active__c = True AND Project__c =:pageid Limit 1];
        Project_Time__c obj = new Project_Time__c();
    
        obj.Project__c = pageid;
        obj.Latitude__c = valuelat;
        obj.Longitude__c = valuelong;
        obj.Punch_In_Time__c=System.NOW();
        insert obj;
        PageReference reference=new PageReference('http://www.google.com');
        reference.setRedirect(true);

        return reference;
        }
        
//Action functionality for PunchOut CommandButton
    public pagereference PunchOut() {
        Id pageid = controller.getId();
        Project_Time__c obj2 = new Project_Time__c();
        Project_Time__c results = [select Name,id,Active__c  From Project_Time__c WHERE Active__c = True AND Project__c =:pageid Limit 1];
      
        obj2.ID = ((ID)results.get('id'));
    
        obj2.Punch_Out_Latitude__c= valuelat;
        obj2.Punch_Out_Longitude__c= valuelong;
        obj2.Punch_Out_Time__c=System.NOW();
        update obj2;

//Counts Total hours of the project
        project__c objproject = new project__c();
        AggregateResult TotalHours = [select project__c  ,sum(Total_Time__c)sumofhours FROM project_time__c Where Active__c = false group by project__c  having project__c = :pageid ];
        objproject.id=((ID)TotalHours.get('project__c'));
        objproject.Total_Project_Time__c=((decimal)TotalHours.get('sumofhours'));
        
        Update objproject;
        Pagereference ref = new Pagereference('/apex/Pool_PH_WaterQuality');
        ref.setRedirect(true);
        return ref;
    }
}

 
SaranSaran
Hi,

I think by removing the rerender="jsvalues" attribute might help to redirect to another page.

Thanks.
NikunjVadiNikunjVadi
hey,

removing rerender is solving issue, but it isnèt getting co-ordinates. is there anyother way?