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
sf_evolutionsf_evolution 

Trying to get the Page view ID...

 

Hi all,

 

I have to definitively count the number of times a rep has read his/her particular leads...

I got the code working great, but I seem to be missing the "Back to List: Leads" link and

it's causing me to lose some goodwill with the CSRs.

 

I basically have a lead page override that looks like:

 

<apex:page standardController="Lead" extensions="LeadPageLoadCode" action="{!loadEvent}">

<apex:form >
    <apex:detail subject="{!Lead.Id}" relatedList="true" showchatter="true" inlineEdit="true" />
</apex:form>
</apex:page>

 

...And the LeadPageLoadCode is actually a bit of work, because I have to check if the lead is converted, owned by someone else, etc...  but FWIW, here it is;

public with sharing class LeadPageLoadCode {
    private final Lead Lead;   
    
    public LeadPageLoadCode (ApexPages.StandardController stdController){       
        System.debug('Entering Constructor...');
        this.Lead = (Lead) stdController.getRecord();
        }
        
     public PageReference loadEvent() {       
        PageReference leadPage = new ApexPages.StandardController(Lead).view(); 
        System.debug('Entering loadEvent...');
        String strLeadId  = this.Lead.Id;
        Id myId = UserInfo.getUserId();
        List<Lead> myLeads = [SELECT IsUnRead__c, OwnerId , IsConverted from Lead where Id = :strLeadId LIMIT 1];
        
        if(myLeads[0].IsConverted == true) {    // can't do anything....
            System.debug('Redirecting to  ViewConvertedLead');
            leadPage = new PageReference ('/p/lead/ViewConvertedLead/d?id='+myLeads[0].Id);
            return leadPage;
            }           
        
        if(myLeads.size() != 0 ) {  // we have work to do...
            if(myLeads[0].IsUnRead__c == null) {myLeads[0].IsUnRead__c = 0;}            
            if( myLeads[0].OwnerId == myId) {                
                if(myLeads[0].IsUnRead__c <= 0) {
                    System.debug('Lead.IsUnRead = 0');
                    myLeads[0].IsUnRead__c += 1;
                    update myLeads;                   
                    leadPage.setRedirect(True);
                    }
                 else {
                    System.debug('Lead.IsUnRead: '+myLeads[0].IsUnRead__c);
                    leadPage = new PageReference ('/apex/LeadPageAnchor');
                    }         
                 return leadPage;
                 }
            else {
                System.debug('Lead.IsUnRead: '+myLeads[0].IsUnRead__c);
                leadPage = new PageReference ('/apex/LeadPageAnchor');
                }                          
            }
        else {   // This is not the lead owner - do nothing
            System.DEBUG('This is not the lead owner - do nothing');
            leadPage = new PageReference ('/apex/LeadPageAnchor');            
            }
        return leadPage;    
        }
}

 

...I'm omittintg the "LeadPageAnchor" for brevity, but suffice it to say it's just the same thing as the anchor--- it just keeps the page from going into an infinite loop.   Also, this code only counts to 1 - but I fixed that elsewhere....

 

 

My problem is The "Back to List: Leads" link disappears.

 

Is there a way I can build this? it doesn't seem like I can get access to the Lead Page View ID on the view button override.

Any help is greatly appreciated.

 

 

Thanks!

 

 

 

 

Rahul_sgRahul_sg

Hi,

It seems SFDC uses some javascript to generate this link.

 

If you want to implement similar feature you can do something like this : 

<apex:outputLink value="/{!MyObject.Id}">Back to List</apex:outputLink>

where 

MyObject = Leadid or you can redirect to lead tab by specifying "/00Q/o" in value.

 

Thanks,

Rahul

kevindotcarkevindotcar

Hi Rahul,

 

{!MyObject.Id} is the ID of the object, not the pageview, unless I'm missing something. 

It also looks like pageviews are meta-data, and not objects, so things are looking more and more complicated.

 

 

Basically, if I display a lead page view and the URL looks like this:

   https://cs4.salesforce.com/00Q?fcf=00BP0000000Ugau

 

...I need the "00BP0000000Ugau" part to get back to the previous page.

 

Thanks,

 

Rahul_sgRahul_sg

by MyObject I mean a public varible defined & used in the controller class

kevindotcarkevindotcar

 

Hi Rahul,

 

The only variable I have in my controller class is the lead.

When I put the line you suggested in my page (the apex:outputLink);

 

<!-- apex:page standardController="Lead" !-->
<apex:page standardController="Lead" extensions="KevinsPageLoadCode" action="{!loadEvent}">
<apex:form >
    <apex:outputLink value="/{!Lead.Id}">Back to List</apex:outputLink >  
    <apex:detail subject="{!Lead.Id}" relatedList="true" showchatter="true" inlineEdit="true" />
</apex:form>
</apex:page>

 

...All that happens is the lead page is re-displayed --

I need to go back to the view of the leads.  Sorry if I wasn't clear.

 

I think I need a way to capture the fcf=00BP0000000Ugau in the controller, but it doesn;t seem to be passed vhen using an apex:detail tag.

 

kevindotcarkevindotcar

Hi Rahul,

 

Specifying "/00Q/o" in the commandlink, like

 

<apex:commandlink value="Back To Leads: " action="/00Q/o"/>

 Gets me back to the home page of the views, and not the specific view the user was on.

 

 

 

Rahul_sgRahul_sg

Hi bro,

 

As per SFDC...this is how the link works..... The "Back To List" link takes you back to the last ListView, on the last unadultrated SalesForce page that you viewed, if and only if you navigated through a link on that list. 

 

Doesn't matter where you go in SF after that, or if you navigate through other ListViews if they're on custom VisualForce pages.  From that point fwd all "Back To List" links will point back to that last listview of theirs that you navigated through.

 

Basically it uses Javascript & cache values to redirect to the previos view. So with native Visualforce programming its not possible to implement the exac functionality.

 

So as I mentioned earlier you can redirect the user back to any fixed list view. e.g with "/00Q/o" it will redirect you to Leads TAB.

You may also vote on the following Idea : http://success.salesforce.com/ideaView?id=08730000000KHu0

kevindotcarkevindotcar

Yeah, I read and voted and even commented on that idea too.

 

The deal is that I navigate to a lead from the lead view via a page that uses an <apex:detail> token, and the link is disappearing.

 

There is talk of an S control out there that does this, but I haven't been able to find it.    If you can find any info I'd appreciate it.