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
community Name.ax928community Name.ax928 

Lead Conversion -mapping of all Lead Related Lists

Hi,

i created a vf page and controller for lead conversion page and i am having some issues in that

 

can anyone help me out with the following issues.

 

when we convert the lead into Account, contact and Opportunity, lead related lists(activities, notes and Attachments and campaign members) are not converting into account, contact and opprty .

 

if anyone implemented this kind of scenario before can you please help me out in this.

 

thanks in advance.

forecast_is_cloudyforecast_is_cloudy

Are you using the standard 'leadConvert' Apex function to convert the lead in your VF controller class? If so that should automatically convert Note, Attachments and activites to the Account, Contact and Opp records. The campaign history information should also automatically be transferred to the Contact record. Is that not happening?

Note that any Notes and Attachments associated with the Lead record will only be carried over to the Account and Contact records (and not the Opp record) as per the standard Salesforce Lead Convert functionality.

community Name.ax928community Name.ax928

thanks for reply,

 

i am using the standard controller for lead conversion VF controller, but i could not able to get the activity, notes and attachments to Accounts,activity, notes and attachments and campaign history information to contacts and activites to oppty.

 

is there anything particularlly i need to add the controller to that information.

 

if you have any sample data can you please post it here 

 

thanks again.

forecast_is_cloudyforecast_is_cloudy

I didn't mean if you were using the Standard Lead controller for your custom VF page (which you have anyway in order to be able to overide the default Lead Convertion functionality in Salesforce). I ment if you were use the standard Apex DML function 'convertLead' inside your VF extension class. Please review the following documentation on how to use the convertLead DML operation and make sure that your code uses that operation to convert the Lead - http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_convertLead.htm 

community Name.ax928community Name.ax928

thanks for the reply again,

here is code that i am using for VF controller.
can you please verify and change the code if anything wrong. 
public class LeadController {
   // public String strAcName {get;set;}
    public boolean bolVal;
    public boolean bolValNotification;
    public String strBody;
     //public Opportunity myOpp {get;set;}
    public String strStage {get;set;}   
   // public String strPriority {get;set;}
   // public String strSubject {get;set;}
     OpportunityContactRole role;
     AccountContactRole acrole;
     Opportunity op;
     
    
    //Lead ld;
   //public Lead getLead(){
       //if(ld==null)
   //         ld = new Lead();
   //     return ld;
    //} 
   //public ApexPages.StandardController sc;
    private final Lead ld;
    private String strStatus;
    private String strSubject1;
    private String strPriority;
    private Date dtDate;
    private String strDesciption;
    private DateTime dtDateTime;
    private Date comDate;
    private Date folDate;
    private String strExtDescription;
    Task tsk;
    Account ac; 
   
   // private Task task;
   public LeadController(ApexPages.StandardController controller) {
        ld= (Lead)controller.getRecord();
 
        //this.sc = controller;
        //tssk=(Task)controller.getRecord();
    }
    
   /* public String getStage()//status
    {
        return strStage;
    }
    /*public String getPriority()//status
    {
        return strPriority;
    }
    /*public String getSubject()
    {
        return strSubject;
    }*/
    
   //Property for client agreement checkbox
    public Boolean showClientAgreement{
        get{
            if(showClientAgreement == null){
                showClientAgreement = False;
               // bolval=false;
            }          
            return showClientAgreement;   
        }
        set;
    }  
    
    //Property for Task creation
    public Boolean DonotcreateTaskUponConversion{
        get{
            if(DonotcreateTaskUponConversion == null){
                DonotcreateTaskUponConversion = False;
            }          
            return DonotcreateTaskUponConversion;   
        }
        set;
    }
    
    //Proprty of Bol Notificatoin Email
    public Boolean showTaskNotification{
        get{
            if(showTaskNotification== null){
                showTaskNotification= false;
                //bolValNotification=false;
            }           
           
            return showTaskNotification;   
        }
        set;
    }
    //Property of Bol Notificatoin Email
    public Boolean SentEmailToOwner{
        get{
            if(SentEmailToOwner== null){
                SentEmailToOwner= false;
                //bolValNotification=false;
            }           
           
            return SentEmailToOwner;   
        }
        set;
    } 
    public Boolean IsConverted{
       get{
       if(IsConverted != null){
           IsConverted = true;
       }
       return IsConverted;
       }
       set{
       IsConverted = true;
       }
       }
//leadConvert.setConvertedStatus(convertedStatus);
//leadConvert.setSendNotificationEmail(sendEmailToOwner);
    
    public Task getTask(){
        if(tsk==null)
            tsk = new Task();
      // this.strStatus = tsk.Status;
       ///this.strPriority = (String) tsk.Priority;
       //this.strDate = tsk.ActivityDate;
       this.strSubject1 = tsk.Subject;
       this.dtDate = tsk.ActivityDate;
       this.strPriority = tsk.Priority;
       this.strStatus = tsk.Status;
       this.strDesciption = tsk.Description;
       this.dtDateTime = tsk.ReminderDateTime;
       this.comDate = tsk.Completed_Date__c;
       this.folDate = tsk.Follow_Up_date__c;
       this.strExtDescription = tsk.Extended_Description__c;
      
        return tsk;
    }
    public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('CreateNewAccount','Create New Account'));
            options.add(new SelectOption('AddToExistingAccount','Add To Existing Account'));
           
        
            return options;
        }
    //this is for Task Priority
    /*public List<SelectOption> getPriorityList () {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('High','High'));
            options.add(new SelectOption('Normal','Normal'));
            options.add(new SelectOption('Low','Low'));
            return options;
        }*/
    public PageReference ConvertLead(){  
    
       
         
     i could not able put all the code at a time beacause it can't take more than 20000 characters.
i posted the remaining code in the next reply.
thanks,
   

 

community Name.ax928community Name.ax928

 

  //Account ac = new Account(name=strAcName);
        /*Account ac = new Account();
        ac.name=ld.Company;
        ac.billingStreet=ld.Street;
        ac.billingCity=ld.City;
        ac.billingState=ld.State;
        ac.billingPostalCode=ld.PostalCode;
        ac.NumberOfEmployees=ld.NumberOfEmployees;
        ac.AnnualRevenue=ld.AnnualRevenue;
        ac.Industry= ld.Industry;
        ac.Description=ld.Description;
        ac.Phone=ld.Phone;
        ac.Fax=ld.Fax;
        ac.Website=ld.Website;
        ac.Rating=ld.Rating;
        insert ac;*/   
        
        if(strStage=='AddToExistingAccount')
        {
            ac = [select name, billingStreet, billingCity, billingState, billingPostalCode,
                            NumberOfEmployees, AnnualRevenue, Industry, Description, Phone, Website
                             from Account where name = :ld.Company];
            ac.name=ld.Company;
            ac.billingStreet=ld.Street;
            ac.billingCity=ld.City;
            ac.billingState=ld.State;
            ac.billingPostalCode=ld.PostalCode;
            ac.NumberOfEmployees=ld.NumberOfEmployees;
            ac.AnnualRevenue=ld.AnnualRevenue;
            ac.Industry= ld.Industry;
            ac.Description=ld.Description;
            ac.Phone=ld.Phone;
            ac.Website=ld.Website;
            update ac;
        }
        else
        {
            ac = new Account();
            ac.name=ld.Company;
            ac.billingStreet=ld.Street;
            ac.billingCity=ld.City;
            ac.billingState=ld.State;
            ac.billingPostalCode=ld.PostalCode;
            ac.NumberOfEmployees=ld.NumberOfEmployees;
            ac.AnnualRevenue=ld.AnnualRevenue;
            ac.Industry= ld.Industry;
            ac.Description=ld.Description;
            ac.Phone=ld.Phone;
            ac.Website=ld.Website;
            insert ac;
        }
                      
        Contact ct = new Contact();
        ct.assistantName = ld.Company;
        ct.Lastname=ld.LastName;
        ct.FirstName=ld.FirstName;
        ct.MailingCity = ld.City;
        ct.MailingCountry = ld.Country;
        ct.MailingPostalCode = ld.PostalCode;
        ct.MailingState = ld.State;
        ct.MailingStreet = ld.Street;
        ct.Phone=ld.Phone;
        ct.MobilePhone = ld.MobilePhone;
        ct.Email = ld.Email;
        ct.Fax=ld.Fax;
        ct.Description=ld.Description;
        ct.LeadSource=ld.LeadSource;
        ct.Title=ld.Title;
        ct.accountId = ac.id;
        insert ct;
        
       
        
        if(showClientAgreement == False)
        {
            OpportunityContactRole role = new OpportunityContactRole();
            op = new Opportunity();
            //Opportunity op = new Opportunity();
            op.name=ld.Company;
            op.LeadSource=ld.LeadSource;
            op.Description=ld.Description;
            op.CloseDate=System.today();
            op.StageName='Qualification';
            //op.AccountId = ct.AccountId;
            op.AccountId = ac.id;
            insert op;
        
        }
   if(DonotcreateTaskUponConversion == False){
        Task tsk = new Task();
        tsk.Subject = strSubject1;//  'mysubject';//task.Subject;
        tsk.Status = strStatus; //'In Progress';//task.Status;
        tsk.Priority = strPriority;//task.Priority;
        tsk.ActivityDate = dtDate;
        tsk.Description = strDesciption;
        tsk.IsReminderSet = true;
       // task.ReminderDateTime = DateTime.valueOf(dtDateTime); //system.now()+1;// dtDateTime;
        tsk.ReminderDateTime = system.now();// dtDateTime;
        tsk.Completed_Date__c = comDate;
        tsk.Follow_Up_date__c = folDate;
        tsk.Extended_Description__c = strExtDescription;
        tsk.WhoId = ct.Id;             
        if(showClientAgreement == false){
            tsk.WhatId = op.Id;
        }
        insert tsk;
       }
                                                                                                                       
        //send email to owner
        if(SentEmailToOwner== true){
        strBody = 'Converting a lead into the following records has successfully completed:' +
                    '\n\n' + 
                    'Account: ' + ld.Company +
                    '\nhttps://' + ApexPages.currentPage().getHeaders().get('Host') + '/' + ac.Id + 
                    '\n\n' +
                    'Contact: ' + ld.LastName +
                    '\nhttps://' + ApexPages.currentPage().getHeaders().get('Host') + '/' + ct.Id +  
                    '\n\n';
                    
                    if(op!=null){
                        strBody = strBody + 
                        'Opportunity: '+ op.Name +'-' +
                        '\nhttps://' + ApexPages.currentPage().getHeaders().get('Host') + '/' + op.Id ;
                    }
                    strBody = strBody +  
                    '\n\n\n' +
                    'Thank You,' + 
                  sendEmailNotification(strBody, 'New Lead has been assigned to you.');        
         }
        //Send Notification email 
        if(showTaskNotification== true){
            strBody = 'New Task' +
                        '\n' +
                        'To: ' + Userinfo.getFirstName() + ' '+ userinfo.getLastName() +  
                        '\n\n' + 
                        Userinfo.getFirstName() + ' '+ userinfo.getLastName()+ ' has assigned you the following new task:' + 
                        '\n\n' + 
                        'Subject: ' + strSubject1 + 
                        '\nContact: '+ ld.LastName +
                         '\nAccount: '+ ld.Company +
                        '\nOpportunity: '+ ld.Company  +'-' +
                        '\nPriority: ' + strPriority +
                        '\nComments: ' + strDesciption + 
                        '\n\n' + 
                     
                      'For more details, click the following link:' +
                        '\n\n' +  
                       'Thank You,' + 
           sendEmailNotification(strBody, strSubject1);
  
                 }        
               
        delete ld;
        
        PageReference accPage = new PageReference('/' + ac.id);
        accPage.setRedirect(true);
        return accPage ;
       
    }
    
    //To send Email
    public void sendEmailNotification(String strEmailBody, String strEmailSub)
    {
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {userinfo.getUserName()}; 
        String[] ccAddresses = new String[] {userinfo.getUserName()}; 
        mail.setToAddresses(toAddresses); 
        mail.setCcAddresses(ccAddresses);    
        mail.setSenderDisplayName(Userinfo.getFirstName() + ' '+ userinfo.getLastName());    //This shoudl be user name
        //mail.setSubject('New Case Created1 : ' + ct.Id);
        mail.setSubject(strEmailSub);
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setPlainTextBody(strEmailBody);
        //mail.setPlainTextBody('Your Case: ' + ct.Id +' has been created');        
       /* mail.setHtmlBody('Your case:<b> ' + ct.Id +' </b>has been created<p>'+
     ' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');    */
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

 

 

 

thanks,