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
Abdul RazzaqAbdul Razzaq 

Get DeveloperName from recordtype by passing recordtypeid which is fetched from url.

This is my code:-

public class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
        this.controller = controller;
    }
   
    public PageReference Redir() {

        PageReference newPage;
        PageReference standardpage = New PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType=012900000011wvV&ent=Lead&nooverride=1');
        
        RecordType r;
        r = [Select developerName from RecordType Where SobjectType='Lead' And id = :ApexPages.currentPage().getParameters().get('RecordType')];
        
        if ( r.developerName == 'LeadVisualforcePage') {
        
        System.debug('----------------------------------------------------------------------');
        
            newPage = Page.leadtask;
            
            return newPage;
        } else {
        
         System.debug('**********************************************************************');
         
         return standardpage;
        }

    }

    private final ApexPages.StandardController controller;
}

Best Answer chosen by Abdul Razzaq
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Abdul Razzaq:

   Can you check if you have any class saved by the name RecordType ?? If you find any, rename it and try it again!


Thanks,
balaji

All Answers

Pankaj_GanwaniPankaj_Ganwani
Hi,

The code looks fine to me. Can you please specify what problem you are facing by using this code?

Thanks,
Pankaj
Abdul RazzaqAbdul Razzaq

Thanks for replying Pankaj.
To be Specific the error I am getting is "Compile Error: Illegal assignment from List<RecordType> to RecordType at line 13 column 9"

Pankaj_GanwaniPankaj_Ganwani
Can you please try using this:
       List<RecordType> r = [Select developerName from RecordType Where SobjectType='Lead' And id = :ApexPages.currentPage().getParameters().get('RecordType') LIMIT 1];
Abdul RazzaqAbdul Razzaq
I already did. The Error just changes to Illegal assignment from List<recordtype> to List<recordtype>
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Abdul Razzaq:

   Can you check if you have any class saved by the name RecordType ?? If you find any, rename it and try it again!


Thanks,
balaji
This was selected as the best answer
Abdul RazzaqAbdul Razzaq

That was very simple @Balaji. Came through this solution on many forums. But I was confident enough that I have not created any RecordType class. However, checked and found an empty RecordType class. That might have been created unknowingly.

Thank you so much @Balaji.