You need to sign in to do that
Don't have an account?
kevindotcar
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):
../apex/ConvertThisLead?Id={!Lead.Id}
...And the apex page looks like this:
<apex:page standardController="lead" action="{!DoConvert}" extensions="leadConvertController"> </apex:page>
...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]; lc.setLeadId(leadId); lc.setConvertedStatus(convertStatus.MasterLabel); if(lObj.OwnerId == UserInfo.getUserId() ){ // perform the lead convert Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); Id oppId = lcr.getOpportunityId(); String sServerName = ApexPages.currentPage().getHeaders().get('Host'); sServerName = 'https://' + sServerName + '/'; PageReference Page = new PageReference(sServerName+oppId); Page.setRedirect(true); 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; https://cs4.salesforce.com/006P0000004E...,) and SF replied with "Data Not Available".
Anyone know what I'm doing wrong?
Thanks,
KC
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.