+ Start a Discussion
ministe2003ministe2003 

Overridden Opp New/View/Edit now cannot change Record Type

Hi all,

Major problem.  We have overridden the opportunity new, view and edit controls and visualforced all opportunity view and edit pages.  In the visualforce I have added the [change] link next to the Record Type on the view page.

 

When I click the change link next to the record type and choose a type from the drop down then click continue, it takes me back to the view page (which I would expect) but the record type has not changed:

 


 

Also on another page I'm just using the detail tag (thereby not writing the [change] link manually) and it still doesnt work.  Seems to me the problem is caused because the Edit  function is overwritten with a visualforce page.  The record type change page is managed by a jsp page but it would seem the owner isnt actually changed here and somehow it is passed somewhere else once the Continue button is clicked but because we have overridden view and edit, whatever process that would normally handle the record type change is now no longer being called.

 

Seems strange that salesforce would give me the option to override these pages when it clearly leads to a problem of this kind, can anyone offer a suggsetion?

 

Thanks

Steven

ministe2003ministe2003

noone can offer an opinion?

WhyserWhyser
I'm running into this issue too... I'm surprised there aren't any more people having issues with this:

So I want to override the Edit page using this


<apex:page standardController="Opportunity">
<script>
window.top.location.replace("{!URLFOR($Action.Opportunity.Edit, opportunity.id, [saveURL='/apex/Google_Analytics', retURL='/'+opportunity.id, cancelURL='/'+opportunity.id], true)}");
</script>
</apex:page>



So when a user wants to save any changes to the Opportunity, I want to go through some logic and determine whether to send some statistical information to Google Analytics.

All this seems to work okay, but users have started noticing that when the Edit button is overridden, their ability to modify the Record Type on the Opportunity is no longer available.

The button to change the Record type [change] is still there, and selecting the record type is still works, but normally after selecting the record type, you're taken to the edit page for any additional editing. The record type displayed on the Edit page is the same as the original record type and not the new one that is selected.

I tried adding the recordtype to the URL by going like this (bolded)


<apex:page standardController="Opportunity">

<script>
window.top.location.replace("{!URLFOR($Action.Opportunity.Edit, opportunity.id, [saveURL='/apex/Google_Analytics', retURL='/'+opportunity.id, cancelURL='/'+opportunity.id, recordtype=opportunity.recordtype], true)}");
</script>

</apex:page>


and that passes the NEW recordtype ID to the edit page in the URL


https://cs12.salesforce.com/006V0000004B8DGIA0/e?retURL=%2F006V0000004B8DGIA0&nooverride=1&saveURL=%2Fapex%2FGoogle_Analytics&cancelURL=%2F006V0000004B8DGIA0&recordtype=012500000000j1rAAA



but the page still displays that the record type is still the original one. And when you save it, the record type is unchanged.

How do you get the new record type to be recognized by the edit page if you've overrode the Edit button?
WhyserWhyser
Okay it looks like I found an answer to my problem though it took me a while to understand.

The solution was found here:

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008pZoIAI

Essentially, if I tried getting the Record Type by using opportunity.recordtype, it would return the ORIGINAL record type value.
It's not clear that this happens, but the selected Record Type is actually passed to the edit page via URL parameter, but things happen so fast that you don't see it.

I had to modify the link in my previous post to grab the record type from the URL parameter and only then did the Edit page display the selected and correct value.

Here is the modified code:

<script>
window.top.location.replace("{!URLFOR($Action.Opportunity.Edit, opportunity.id, [retURL='/'+opportunity.id, cancelURL='/'+opportunity.id, saveURL='/apex/Google_Analytics?gaID='+opportunity.Google_Analytics_ID__c+'&Status='+opportunity.stagename], true)}" + (getUrlParameters( 'RecordType','',false ) != false ? "&RecordType=" + getUrlParameters( 'RecordType','',false ) : "" ) );
</script>
and the getURLParameter function is as follows:

<script>
        //helper function to get the URL parameters
        function getUrlParameters(parameter, staticURL, decode)
        {
            var currLocation = (staticURL.length)? staticURL : window.location.search,
            parArr = currLocation.split("?")[1].split("&"),
            returnBool = true;
       
            for(var i = 0; i < parArr.length; i++)
            {
                parr = parArr[i].split("=");
                if(parr[0] == parameter)
                {
                    return (decode) ? decodeURIComponent(parr[1]) : parr[1];
                    returnBool = true;
                }
                else
                {
                    returnBool = false;            
                }
           }
           if(!returnBool) return false;
       }
   
    </script>

This will take you to the default Edit page with the selected Record Type that was done in the Record Type selection page.

I hope this helps anyone who is running into the same issues as the original poster  and me.