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

I get Internal Server Error....

I'm trying to stop lead conversion if someone tries to convert a lead that isn't owned by themselves.
I have a custom button for leads that looks like this (Detail Page Button):



...And the apex page looks like this:

<apex:page standardController="lead" 

 ...And the controller class looks like this:

public class leadConvertController {
        Public lead lObj;
        Public Id leadId;
        public leadConvertController (ApexPages.StandardController stdController)  {
            leadId = ApexPages.currentPage().getParameters().get('id');                    
      public PageReference DoConvert()  {      
            Database.LeadConvert lc = new database.LeadConvert();
            LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];            
            lObj = [SELECT ID, OwnerId from lead where id =: leadid];         
            if(lObj.OwnerId == UserInfo.getUserId() ){  // perform the lead convert
                Database.LeadConvertResult lcr = Database.convertLead(lc);
                Id oppId = lcr.getOpportunityId();
                String sServerName = ApexPages.currentPage().getHeaders().get('Host');
                sServerName = 'https://' + sServerName + '/';
                PageReference Page = new PageReference(sServerName+oppId);
                return Page;
            else {  // can't do the convert
                lObj.addError('You must be the Lead Owner to Convert this lead!');
                lObj.addError('Please login as the lead owner');
            return null;

 Everything seems fine - I get an Opportunity ID back, but the redirect never takes place.

I tried just putting the ID of the created opportunity on the URL line

(like;,) and SF replied with "Data Not Available".


Anyone know what I'm doing wrong?





Best Answer chosen by Admin (Salesforce Developers) 

Well, I logged a call with Salesforce and they confirmed it was a bug with the Spring '12 release - fixed and all's well now.

The interesting thing was that if I chose not to create an Opportunity (just an account) it all worked well.