You need to sign in to do that
Don't have an account?

getParameters().get('RecordType') returns null in case of one visible record type
Hello everybody,
I have a problem with my code. I have created a new page for the account. I only want to show this page, for certain record types. So I created a redirect page, which redirects the user to either the original page, or the new account page. Below is my code.
public PageReference redirectToPage() { System.debug('In redirectToPage from AccountRedirectController'); PageReference newPage = null; System.debug('Getting record type parameter:' +ApexPages.currentPage().getParameters().get('RecordType')); if(ApexPages.currentPage().getParameters().get('RecordType') == RECORDTYPE_OTHER_ACCOUNT.Id) { System.debug('Creating newPage from step with selected record types'); newPage = Page.NewAccountPage1; newPage.getParameters().put('RecordType', RECORDTYPE_OTHER_ACCOUNT..Id); } else { if(ApexPages.currentPage().getParameters().get('RecordType') != null && ApexPages.currentPage().getParameters().get('RecordType') != RECORDTYPE_TP_ACCOUNT.Id) { System.debug('*** information **'+ApexPages.currentPage().getParameters().get('RecordType')); newPage = new Pagereference('/001/e?retURL=/001/o&RecordType='+ApexPages.currentPage().getParameters().get('RecordType')+'&ent=Account'); newPage.getParameters().put('nooverride', '1'); } } return newPage; }
The problem is with the line
ApexPages.currentPage().getParameters().get('RecordType')
This returns null, when the user only has rights to one specific recordtype. While if the user has rights to multiple recordtypes, and he selects one this line always has a valid ID.
Why is the record type not set if the user has only access to one specific record type? And how do I get this specific recordtype in my code, so that I can build a correct redirect?
Any help would be appreciated, thanks, Jan-Dirk
Hi Everybody,
Got it solved by creating a method which search for the default record type in case the record type is not set. The method rtInfo.isAvailable() only returns true if the specific user has rights to that record type. I have added a call to this method in the first line of my method redirectToPage().
Hope it helps others,
Greetings, JD
All Answers
Jan,
I will recomand you , dont access recordtype Id in this way,
retrive all recordType by SOQL as follow
Hope this will help you
Thanks,
Bala
Hi Bala,
Thanks for your post, but I don't think that that will do the trick. Since I also think I already do that now, or I understand you wrong:smileysurprised:. My problem is not with retrieving an recordtype, but with retrieving the actual recordtype.
I cleaned my code and below is the complete code, including VF class. The problem what I have, in case the user has the record type selection screen, the record ID is set, but when he doesn't it is not set for some reason. And I don't understand this since when I do not override my new page with this VF page, I can find the record type ID in the parameters behind the URL on the standard edit screen. Also when I only have the rights for one record type.
VF page: ( I overrule the new button with this page)
APEX
Btw, the reason I am doing this, is that I only want to have a specific group of users(and indirect a related record type) have access to another VF page, NewAccountPage1
Hope it clears up the problem I am facing
Could you please explain what is actualRecordType ?
If you want to restrict the access of VF page on basis of Profile/User, you can check same in Page Load and Redirect to some Error page
Thanks,
Bala
Bala,
Actual record type is basically the type of the record, when I create a new account. (So when I hit the new account button).
As administrator, I have rights to all recordtypes, so I got the selection screen first, I select recordtype 'MyType', hit continue, then my VF redirect page is loaded and tadaa, the actual record type is filled, and my redirect works fine :)
But as userx, I only have rights to see recordtype 'MyType' and I don't get the selection screen, but immediately goes to the VF redirect page. The actual record type is null. Now my code crashes, the record ID is not set.
But as userX, when the new button is not overrided, I definetely see the actual ID of MyType in the URL, when I create a new account using the same button.
So it looks like, that when I only can see one record type, the record ID is not set before loading the redirect page. But how can I figure out in that case what the record type is the user is going to create? I wonder, maybe it's already set in the account, and I can retrieve by getting the account from my standard controller... gonna try that now
Thanks a lot for updates
I got your point ..
It's driving my nuts.. tried below, and it does not work either :(
If anybody has an idea /workaround... would be welcome
Hi Everybody,
Got it solved by creating a method which search for the default record type in case the record type is not set. The method rtInfo.isAvailable() only returns true if the specific user has rights to that record type. I have added a call to this method in the first line of my method redirectToPage().
Hope it helps others,
Greetings, JD
Thanks for posting this JD, I was just facing the exact same problem. It's a wonky work-around for something that should be pretty straightforward.
I posted an idea on the Idea Exchange to try and get this resolved, please go vote! https://sites.secure.force.com/success/ideaView?c=09a30000000D9xtAAC&id=08730000000KSixAAG