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
Pooja ShahPooja Shah 

Retrieving record types of contract in a s control

I need to navigate to a different page other than the one shown by default for a particular record type of a contract.
I am writing a s control for the same. How do i retrieve and compare a contract record type and do the navigation using a S control

Thanks in advance

Pooja
jwetzlerjwetzler
You should not need an s control for this anymore.  You can create a Visualforce page and use the action attribute on the apex:page component.  In your action method, query for the recordTypeId of your contract and redirect as appropriate.
Pooja ShahPooja Shah
Thanks.
 But it is not from a particular visual force page that i have developed.
It is when the view link is clicked with in the contract this has to happen
so i have coded it like this
But this goes into an infintie loop. Any idea of how to solve this issue.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/12.0/connection.js"></script>
    <script>
 
function redirectToContractSummary()
{
    //Retrieving values about the current contract.
    var clickingUser = sforce.connection.getUserInfo();
    var currentContractId = "{!Contract.Id}";
    var contractResults = sforce.connection.query ("select Id, RecordTypeId from Contract where Id = '" +currentContractId+ "'");
    var contractRecords = contractResults.getArray("records");
    var createdBy = "{!Contract.CreatedBy}";
    var UserId = "{!User.Name}";
    
    if (contractRecords[0].RecordTypeId == '012T0000000CmwkIAC')
    {
        
        this.parent.top.location.replace("/apex/contract_summary?contractId="+currentContractId);
        }
    else if (contractRecords[0].RecordTypeId == '012700000000vXAAAY')
    {
       
        this.parent.top.location.replace("/"+currentContractId);
        
    }        
}
redirectToContractSummary();
    </script>
</head>

<body>
</body>
</html>


dchasmandchasman
As Jill suggested a better option (going to save a number of round trips and perform quite a bit better - this is also the recommended direction because scontrols are on life support now) would be to leverage visualforce's conditional routing support for this kind of thing. Basically, add a page level action method to /apex/contract_summary that either displays the current page or routes to /currentContractID based on the record type, e.g. something like this:

Code:
<apex:page controller="RerouteDemo" action="{!reroute}">
  Your main content goes here
</apex:page>

public class RerouteDemo {
public PageReference reroute() {
return currentRecordTypeIsBlah() ? null : new PageReference('/' + contractId);
}

private boolean currentRecordTypeIsBlah() {
// Your logic basic on record type goes here
return true;
}

private String contractId;
}



Message Edited by dchasman on 06-18-2008 10:01 AM
jwetzlerjwetzler
Right. What I've usually suggested is a simple detail page

Code:
<apex:page standardController="contract" extensions="RerouteDemo" action="{!reroute}">
<apex:detail/>
</apex:page>

 This page, with just a detail component in it, looks exactly like your current detail page, driven off of page layout and everything.

So you set this one to be your override page for contract view and then reroute() will get run whenever the view is brought up, redirecting to your new page if necessary.

Code:
public class RerouteDemo {
    public PageReference reroute() {
        if(currentRecordTypeIsBlah()) {
          return null; //stay on the same page
        } else {
          PageReference p = Page.myRecordTypePageName;
          p.setRedirect(true);
          return p;
        }
    }

    private boolean currentRecordTypeIsBlah() {
        // Your logic basic on record type goes here
        return true;
    }
}

 

Pooja ShahPooja Shah
Thanks
Pooja ShahPooja Shah
even if i apply this, I cant make a page override when i go to Contracts -->Buttons and links -->view>override
when i select on the radio button of s controls it shows me a list of existing s controls but when I say visual source page, it doesnt give me any list.

 I guess i will have to create another dummy apex page such that it mimicks the look and feel of the contract page

Let me know your suggestions on the same
jwetzlerjwetzler
did you copy the page that I posted?  In order to override the New, Edit, or View pages your page has to have a standardController of type contract.
Pooja ShahPooja Shah
with standardcontroller = contract i get the visual force page and i can make it over ride it. Thanks for point to that.

However it gives me an error (unknown constructor -RerouteDemo.RerouteDemo(Apexpages.standardController controller ) if i put the extensions = "RerouteDemo"

I have copied the code that you have posted without any changes.


Pooja
Pooja ShahPooja Shah
I figured out that I was missing a constructor

public RerouteDemo(ApexPages.StandardController stdController) {
        //do Nothing
    }
dchasmandchasman
Right - that specific constructor is needed for VF to be able to inject a reference to the standard controller into your extension. If you are using either the in page editor (Development Mode) or Setup you should have been given a quick fix along with the error message that will add the correct ctor for you automatically.
jwetzlerjwetzler
take a look at the doc for extensions.  You can use the standardController that's passed in to call getId(), which you'll need when you query for recordTypeId