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
SFDC n12SFDC n12 

user detail page redirection through link

Hi,

I am having the following below javascript in a vf page which is displaying the users in a table


I have added a link to the user where on click of the link it should redirect me to the corresponding user record, i have added the link using <a href > tag, 

Need help on user record redirection

My Java script



<apex:page showheader="true" sidebar="true">
    <script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
    </script>
    <script src="../../soap/ajax/29.0/connection.js"
          type="text/javascript"></script>

<script>
function getUserInfo() 
  {    
  try
  {
  var userInfoById = {};   
  var output='<font size="2" color="blue"><table><tr><th>User&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Open Tasks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Open Opportunity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Open Threat</th></tr></font>';

  //logic to fetch the frozen users list
  var result = sforce.connection.query("Select Id,LastModifiedDate ,FirstName, LastName from User where Id in(Select userId  From UserLogin WHERE IsFrozen = TRUE) AND IsActive=true");      
  var it = new sforce.QueryResultIterator(result);  
  while(it.hasNext())  
  {     
  var record = it.next();
 
  //logic to fetch the open Task count 
  var taskcount = sforce.connection.query("Select id from Task where Status!='completed' AND ownerid='"+record.Id+"'");      
  var taskresultset =taskcount.getArray("records"); 
  var taskresultcount;
  if(taskresultset!=null)
  {
  taskresultcount=taskresultset.length;
 
  }
  else
  {
  taskresultcount ='';
  }
 
  //logic to fetch the open opportunity count
 
  var opportunitycount = sforce.connection.query("SELECT ID FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' AND ownerid='"+record.Id+"'");      
  var oppresultset =opportunitycount.getArray("records"); 
  var oppresultcount;
  if(oppresultset!=null)
  {
  oppresultcount=oppresultset.length;
 
  }
  else
  {
  oppresultcount='';
  }
 
 
  //logic to fetch the open Threat count 
  var threatcount = sforce.connection.query("Select id from Threat__c where Status__c !='Closed Won' AND Status__c !='Closed Lost'  AND ownerid='"+record.Id+"'");      
  var threatresultset =threatcount.getArray("records"); 
  var threatresultcount;
  if(threatresultset!=null)
  {
  threatresultcount=threatresultset.length;
 
  }
  else
  {
  threatresultcount='';
  }
 

  var name=record.FirstName + ' ' + record.LastName;
  var date = new Date(record.LastModifiedDate);
  console.log(date.toISOString().slice(0,10));
  output+='<tr><td><a href="#">'+name+'</a></td><td>'+date+'</td><td>'+taskresultcount+'</td><td>'+oppresultcount+'</td><td>'+threatresultcount+'</td><td>';
  output+='</td></tr>';
  output+='</td></tr>';

  }      
  output+='</table>';
  document.getElementById('output').innerHTML=output;
  }
  catch (e)
  {
     alert('Exception = ' + e);
  }  
  }
  </script>
 

<apex:sectionHeader title="Frozen State Users:"/>

  <div id="output"> </div>
  
  <script>
    getUserInfo();
  </script>
</apex:page>


Thanks in Advance


Best Answer chosen by SFDC n12
Prafull G.Prafull G.
Try using the record Id directly in href to navigate. Like

output+='<tr><td><a href="/'+record.Id+'?noredirect=1">'+name+'</a></td><td>'+date+'</td><td>'+taskresultcount+'</td><td>'+oppresultcount+'</td><td>'+threatresultcount+'</td><td>';
Let us know if it helps.

All Answers

Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
If you want in javascript then go for window.location
http://www.w3schools.com/js/js_window_location.asp
SFDC n12SFDC n12
Hi,

can you help me with the code pls

output+='<tr><td><a href="#">'+name+'</a></td><td>'+date+'</td><td>'+taskresultcount+'</td><td>'+oppresultcount+'</td><td>'+threatresultcount+'</td><td>';

i am new to javascript 

Thanks
Prafull G.Prafull G.
Try using the record Id directly in href to navigate. Like

output+='<tr><td><a href="/'+record.Id+'?noredirect=1">'+name+'</a></td><td>'+date+'</td><td>'+taskresultcount+'</td><td>'+oppresultcount+'</td><td>'+threatresultcount+'</td><td>';
Let us know if it helps.
This was selected as the best answer