1.创建Lead
2.lead下创建task Event file等,会传递给contact account Opportunity ;去重:关键字匹配
3.convert:邮件提示,Assignment rule,
4.convert 后的lead 是不可见的,通过报表才可以看到信息
定义Convert Button: URL 指向:https://**.salesforce.com/apex/LeadConvert?retURL=%2F{!Lead.Id}&id={!Lead.Id}
页面:LeadConvert.page
<apex:page controller="LeadConvertController" tabstyle="lead" > <apex:sectionHeader title="Convert Lead" subtitle="{!lead.name}" help="../help/doc/user_ed.jsp?loc=help&target=leads_convert.htm§ion=Leads&showSplash=true"/> <apex:outputPanel > Leads can be converted to accounts, contacts, opportunities, and followup tasks.<br/> You should only convert a lead once you have identified it as qualified.<br/> After this lead has been converted, it can no longer be viewed or edited as a lead, but can be viewed in lead reports.<br/><br/> </apex:outputPanel> <style> </style> <script> function viewAccount(accountId) { var acc_id = document.getElementById(accountId); if (acc_id.value=="") { alert("You can only view existing accounts."); } else { printWin('/'+acc_id.value+'/p'); } } function oppSelect(oppName,doNotCreateOpp){ var opp_name = document.getElementById(oppName); var do_not_create_opp = document.getElementById(doNotCreateOpp); if(do_not_create_opp.checked==true){ do_not_create_opp.value=true; opp_name.disabled=true; }else{ do_not_create_opp.value=false; opp_name.disabled=false; } } function accountSelect(accountName,createNewAccount,oppName,doNotCreateOpp){ var acc_name = document.getElementById(accountName); var create_new_acc = document.getElementById(createNewAccount); var opp_name = document.getElementById(oppName); var do_not_create_opp = document.getElementById(doNotCreateOpp); if(create_new_acc.checked==true){ create_new_acc.value=true; acc_name.value="--"; acc_name.disabled=true; opp_name.disabled=true; do_not_create_opp.disabled=true; do_not_create_opp.checked=true; }else{ create_new_acc.value=false; acc_name.value=""; acc_name.disabled=false; opp_name.disabled=false; do_not_create_opp.disabled=false; do_not_create_opp.checked=false; } } function checkPage(accountName,createNewAccount){ var acc_name = document.getElementById(accountName); var create_new_account = document.getElementById(createNewAccount); if(create_new_account.checked==false&&acc_name.value==""){ alert("AccountName: You must enter a value or create a new account!"); return false; } } </script> <apex:form id="editPage" > <apex:pageBlock mode="edit"> <apex:messages /> <!-- 謖蛾聴 --> <apex:pageBlockButtons > <apex:commandButton value="Convert" action="{!Convert}" title="Convert" id="convert" onclick="return checkPage('{!$Component.convertLead.accountName}','{!$Component.convertLead.createNewAccount}');"/> <apex:commandButton value="Cancel" action="{!Cancel}" title="Cancel" immediate="true"/> </apex:pageBlockButtons> <!-- 謖蛾聴 --> <!-- Convert Lead --> <apex:pageBlockSection title="Convert Lead" columns="1" id="convertLead"> <apex:inputField value="{!leadConvert.ownerId__c}" required="true"/> <apex:inputField value="{!leadConvert.sendNotificationEmail__c}" /> <apex:inputField value="{!leadConvert.accountId__c}" id="accountName" required="true"> <!--<a style="cursor: pointer" href="javascript:viewAccount('{!$Component.accountName}');">View</a>--> <br/> <apex:inputCheckbox value="{!IscreateNewAccount}" id="createNewAccount" onclick="return accountSelect('{!$Component.accountName}','{!$Component.createNewAccount}','{!$Component.oppName}','{!$Component.doNotCreateOpp}')"/> Create New Account : <apex:outputLabel value="{!lead.company}" id="initAccountName"></apex:outputLabel> </apex:inputField> <apex:inputField value="{!opportunity.Name}" id="oppName" required="true"> <apex:inputCheckbox value="{!leadConvert.doNotCreateOpportunity__c}" id="doNotCreateOpp" onclick="return oppSelect('{!$Component.oppName}','{!$Component.doNotCreateOpp}')"/>Do not create a new opportunity upon conversion. </apex:inputField> <apex:inputField value="{!leadConvert.convertedStatus__c}" required="true"/> </apex:pageBlockSection> <!-- Convert Lead --> <!-- Task Information --> <apex:pageBlockSection title="Task Information" > <apex:inputField id="taskSubject" value="{!task.Subject}" required="true"/> <apex:inputField id="taskStatus" value="{!task.Status}" required="true" /> <apex:inputField id="taskActivityDate" value="{!task.ActivityDate}" /><br/> <apex:inputField id="taskPriority" value="{!task.Priority}" required="true"/><br/> <apex:inputField id="taskActivityCurrency" value="{!task.CurrencyIsoCode}" required="true" /> </apex:pageBlockSection> <!-- Task Information --> <!-- Description Information --> <apex:pageBlockSection title="Description Information" columns="2" > <apex:inputField id="taskDescription" value="{!task.Description}" style="600px;height:100px;" /><br/> <apex:outputPanel > <apex:inputCheckbox id="sendmail" value="{!IsSendNoticeMail}" />Send Notification Email<br/> </apex:outputPanel> </apex:pageBlockSection> <!-- Description Information --> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class LeadConvertController { Lead lead; LeadConvert__c leadConvert; Account account; Opportunity opportunity ; Task task; Contact contact; public Boolean IsNewOpportunity{get;set;} public Boolean IsSendNoticeMail{get;set;} public Boolean IsSendToOwner{get;set;} public Boolean IscreateNewAccount{get;set;} List<SelectOption> options = new List<SelectOption>(); public String id; public List<String> accountList{get;set;} Database.LeadConvert converter; //得到前一个页面传来的需要转换的lead的Id值 public void setId() { this.id= ApexPages.currentPage().getParameters().get('id'); } public String getId() { return ApexPages.currentPage().getParameters().get('id'); } public Lead getLead() { return lead; } public void setLeadConvert(LeadConvert__c lc ) { this.leadConvert = lc; } public LeadConvert__c getLeadConvert() { return leadConvert; } public void setAccount(Account a ) { this.account = a; } public Account getAccount() { return account; } public Opportunity getOpportunity() { return opportunity; } public void setOpportunity(Opportunity o) { this.opportunity=o; } public void setTask(Task t){ this.task= t; } public Task getTask(){ return task; } //LeadConvertController构造函数 public LeadConvertController() { leadConvert = new LeadConvert__c(); task=new Task(); account = new Account(); opportunity = new Opportunity(); contact = new Contact(); lead= [select OwnerId,Fax,NumberOfEmployees,Phone,Website, CompanyLocal, AnnualRevenue,firstname,lastname,name,Status,HasOptedOutOfEmail,Company,Industry,LastNameLocal, CurrencyIsoCode,Account_SCC__c,BU__c,Account_Account__c, PostalCode ,Country, City,Street, State , Amount__c, //account need Description,Email,LeadSource,MobilePhone ,ConvertedOpportunityId,ConvertedDate, //contact need ConvertedContactId,ConvertedAccountId,IsConverted from Lead where IsDeleted = false and id =:ApexPages.currentPage().getParameters().get('id')]; //leadConvert类用于将Lead 转换为Account、Contact 或者Opportunity(可选) leadConvert.Name = lead.Name; leadConvert.accountId__c=null; //leadConvert.ownerId__c,指定拥有任何新创建的帐户、联系人和机会的人员的ID,表现为页面中的record owner leadConvert.ownerId__c = lead.OwnerId; //leadConvert.opportunityName__c,要创建的销售机会的名称。如果未指定名称,那么此值默认是该销售线索的公司名称。表现为页面中的Opportunity Name opportunity.Name = lead.Company+'-'; leadConvert.opportunityName__c = opportunity.Name; //leadConvert.convertedStatus__c,转换的销售线索的有效LeadStatus 值。必需参数。表现为页面中的Converted Status LeadStatus leadStatus = new LeadStatus(); leadStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true]; leadConvert.convertedStatus__c = leadStatus.MasterLabel; task.OwnerId=leadConvert.ownerId__c; String id = Apexpages.currentPage().getParameters().get('error'); if(id=='1'){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Error'); ApexPages.addMessage(myMsg); } } //发送邮件的方法 public Messaging.SendEmailResult[] SendEmial(string[] toAddresses,string subject, string body){ Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); //Sets the paramaters of the email email.setSubject( subject ); email.setToAddresses( toAddresses); email.setPlainTextBody( body ); // Sends the email Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); return r; } //Convert Lead:Send Email to the Owner public void ownerEmail(Account account,Contact contact,Opportunity opportunity){ //邮件地址 User user=[select Email from User where id=:task.OwnerId]; String addresses=user.Email; String[] toAddresses = addresses.split(':', 0); //发送邮件给Owner String exbody= 'Your salesforce.com request to convert a lead into the following records has successfully completed: '; String accountbody =''; String contactbody =''; String opportunitybody =''; if(account.Id!=null){ accountbody = 'Account: '+account.Name+' '+'https://ap1.salesforce.com/'+account.id+' '; } if(contact.Id!=null){ if(contact.FirstName!=null&&contact.LastName!=null){ contactbody ='Contact: '+ contact.LastName+' '+contact.FirstName+' '+'https://ap1.salesforce.com/'+contact.id+' '; }else if(contact.FirstName == null){ contactbody ='Contact: '+ contact.LastName+' '+'https://ap1.salesforce.com/'+contact.id+' '; }else if(contact.LastName == null){ contactbody ='Contact: '+contact.FirstName+' '+'https://ap1.salesforce.com/'+contact.id+' '; } } if(opportunity.Id!=null){ opportunitybody ='Opportunity: '+opportunity.name+' '+'https://ap1.salesforce.com/'+opportunity.id+' '; } String midbody = accountbody +contactbody +opportunitybody ; String bodyEnding = 'Thank You, '+'salesforce.com '+'experience success '+'http://www.salesforce.com '; String body=exbody+midbody +bodyEnding ; String subject='Lead '+lead.name+' has been assigned to you.'; Messaging.SendEmailResult [] r =SendEmial(toAddresses,subject,body); } //Description Information:Send Notification Email public void notificationEmail(Contact contact,String taskId){ //邮件地址 User user=[select Email,Name from User where id=:task.OwnerId]; Task task=[select Subject,ActivityDate,Priority,Description,Id from Task where Id=: taskId]; String addresses=user.Email; String[] toAddresses = addresses.split(':', 0); //发送邮件给Owner String title_task = 'New Task '; String title_to= 'To: '+user.Name+' '; String body_title = user.Name+' has assigned you the following new task: '; String body_subject = 'Subject: '+task.Subject+' '; String contactbody =''; if(contact.Id!=null){ if(contact.FirstName!=null&&contact.LastName!=null){ contactbody ='Contact: '+ contact.LastName+' '+contact.FirstName+' '; }else if(contact.FirstName == null){ contactbody ='Contact: '+ contact.LastName+' '; }else if(contact.LastName == null){ contactbody ='Contact: '+contact.FirstName+' '; } } String taskbody = ''; if(task.ActivityDate==null&&task.Description==null){ taskbody = 'Priority: '+task.Priority+' '; } if(task.ActivityDate!=null&&task.Description==null){ taskbody = 'Due Date: '+task.ActivityDate+' '+'Priority: '+task.Priority+' '; } if(task.ActivityDate==null&&task.Description!=null){ taskbody = 'Priority: '+task.Priority+' '+'Comments: '+task.Description+' '; } if(task.ActivityDate!=null&&task.Description!=null){ taskbody = 'Due Date: '+task.ActivityDate+' '+'Priority: '+task.Priority+' '+'Comments: '+task.Description+' '; } String bodyEnding_1 = 'For more details, click the following link: '; String bodyEnding_2 = 'https://ap1.salesforce.com/'+taskId; String body=title_task+title_to +body_title+body_subject+contactbody+taskbody+bodyEnding_1+bodyEnding_2; String subject=task.Subject; Messaging.SendEmailResult [] r =SendEmial(toAddresses,subject,body); } //Cancel Button public PageReference Cancel() { PageReference leadPage = new ApexPages.StandardController(lead).view(); leadPage.setRedirect(true); return leadPage ; } //Convert Button public PageReference Convert() { Pagereference contactPage; converter = new Database.LeadConvert(); //不新建account if(IscreateNewAccount==false&&leadConvert.accountId__c!=null){ List<Contact> cons=[Select c.name From Contact c where c.firstname=:lead.FirstName and c.lastname=:lead.LastName and c.IsDeleted=false and c.accountid=:leadConvert.accountId__c]; account = [Select Id,Name From Account where Id =:leadConvert.accountId__c ]; if(leadConvert.doNotCreateOpportunity__c==true){//不新建opportunity //当选择的是已经存在的account时,判断是否存在重名的Contact //如果存在重名的Contact,则跳转到contact的选择页面 if(cons.size()!=0){ insert task; String e = '0'; String e2 = '0'; if(leadConvert.sendNotificationEmail__c==true){ e='1';//需要发送邮件 }else{ e='2';//不需要发送邮件 } if(IsSendNoticeMail==true){ e2='1';//需要发送邮件 }else{ e2='2';//不需要发送邮件 } contactPage = new Pagereference('/apex/leadConvert_contact?accid='+leadConvert.accountId__c+'&leadId='+lead.Id+'&conName='+lead.Name+'&taskId='+task.id+'&e='+e+'&e2='+e2+'&stage='+leadConvert.convertedStatus__c); }else{ //如果不存在重名的Contact,则进行新建,页面跳转到Account的显示页面 //contact的默认及必填字段 contact.OwnerId=leadConvert.ownerId__c; contact.AccountId =leadConvert.accountId__c; contact.Description=lead.Description; contact.Email=lead.Email; contact.Fax=lead.Fax; contact.firstname=lead.firstname; contact.lastname=lead.lastname; contact.CurrencyIsoCode=lead.CurrencyIsoCode; contact.MobilePhone=lead.MobilePhone; contact.Phone=lead.Phone; contact.MailingCity =lead.City; contact.MailingState=lead.State; contact.MailingCountry=lead.Country; contact.MailingPostalCode=lead.PostalCode; contact.Sync_from_SERP__c = false; /// Added by Jianjun Hu at Apr 9 2015 -Begin contact.recordtypeId = ([Select Id from RecordType where sObjectType='Contact' and developerName = 'PSA_Resource']).Id; /// Added by Jianjun Hu at Apr 9 2015 -End insert contact; task.WhoId = contact.Id; task.WhatId = leadConvert.accountId__c; insert task; if(leadConvert.sendNotificationEmail__c==true){ ownerEmail(account, contact, opportunity); } if(IsSendNoticeMail==true){ notificationEmail(contact, task.Id); } converter.setLeadId(lead.Id); converter.setAccountId(account.Id); converter.setContactId(contact.Id); converter.setDoNotCreateOpportunity(true); converter.setConvertedStatus(leadConvert.convertedStatus__c); Database.convertLead(converter,true); contactPage = new Pagereference('/'+leadConvert.accountId__c); } }else{//新建opportunity account = [Select Name From Account where Id =:leadConvert.accountId__c ]; OpportunityStage opps=[Select o.SortOrder,o.MasterLabel,o.IsActive From OpportunityStage o where IsActive=true order by SortOrder limit 1]; //新建opportunity opportunity.OwnerId=leadconvert.ownerId__c; opportunity.AccountId = account.Id; opportunity.LeadSource=lead.LeadSource; opportunity.CurrencyIsoCode=lead.CurrencyIsoCode; opportunity.Awarded_Price__c=lead.Amount__c; opportunity.CloseDate=Date.Today(); opportunity.StageName =opps.MasterLabel; /// Added by Jianjun Hu for Validation Rule [Co_Owner_EMP_is_Required_4_Non_BG1_User] at Apr 9 2015 -Begin // Employee__c coEmployee = new Employee__c(Name = 'Test_EMP_066', // BG__c = 'BG1', // BU__c = 'BG1', // CN_Name__c = 'IT Dev', // Employee_No__c = 'P9999999' // ); // insert coEmployee; // opportunity.Co_Owner_Employee__c = coEmployee.Id; User u = [SELECT Id, Employee_No__c, UserRoleId FROM User WHERE Id = :leadConvert.ownerId__c LIMIT 1][0]; List<Employee__c> lstEmployee = [SELECT Id,Name FROM Employee__c WHERE Employee_No__c = :u.Employee_No__c LIMIT 1]; if(lstEmployee.size()>0){ opportunity.Co_Owner_Employee__c = lstEmployee[0].Id; } /// Added by Jianjun Hu for Validation Rule [Co_Owner_EMP_is_Required_4_Non_BG1_User] at Apr 9 2015 -End insert opportunity; //插入数据库 if(cons.size()!=0){ //当存在同名的contact时,跳转到contact选择页面 insert task; String e = '0'; String e2 = '0'; if(leadConvert.sendNotificationEmail__c==true){ e='1';//需要发送邮件 }else{ e='2';//不需要发送邮件 } if(IsSendNoticeMail==true){ e2='1';//需要发送邮件 }else{ e2='2';//不需要发送邮件 } contactPage = new Pagereference('/apex/leadConvert_contact?accid='+leadConvert.accountId__c+'&leadId='+lead.Id+'&oppId='+opportunity.Id+'&conName='+lead.Name+'&taskId='+task.id+'&e='+e+'&e2='+e2+'&stage='+leadConvert.convertedStatus__c); }else{ //如果不存在重名的Contact,则进行新建,页面跳转到opportunity编辑页面 //contact的默认及必填字段 contact.OwnerId=leadConvert.ownerId__c; contact.AccountId =leadConvert.accountId__c; contact.Description=lead.Description; contact.Email=lead.Email; contact.Fax=lead.Fax; contact.firstname=lead.firstname; contact.lastname=lead.lastname; contact.CurrencyIsoCode=lead.CurrencyIsoCode; contact.MobilePhone=lead.MobilePhone; contact.Phone=lead.Phone; contact.MailingCity =lead.City; contact.MailingState=lead.State; contact.MailingCountry=lead.Country; contact.MailingPostalCode=lead.PostalCode; contact.MailingStreet=lead.Street; contact.Sync_from_SERP__c = false; /// Added by Jianjun Hu at Apr 9 2015 -Begin contact.recordtypeId = ([Select Id from RecordType where sObjectType='Contact' and developerName = 'PSA_Resource']).Id; /// Added by Jianjun Hu at Apr 9 2015 -End insert contact; task.WhoId = contact.Id; task.WhatId = leadConvert.accountId__c; insert task; if(leadConvert.sendNotificationEmail__c==true){ ownerEmail(account, contact, opportunity); } if(IsSendNoticeMail==true){ notificationEmail(contact, task.Id); } converter.setLeadId(lead.Id); converter.setAccountId(account.Id); converter.setContactId(contact.Id); converter.setDoNotCreateOpportunity(true); converter.setConvertedStatus(leadConvert.convertedStatus__c); Database.convertLead(converter,true); contactPage = new Pagereference('/'+opportunity.Id+'/e?retURL=%2F'+opportunity.Id); } } } //当选择新建account时,保存信息并跳转到account_edit页面 if(IscreateNewAccount==true){ // 新建account //转换必填字段 account.OwnerId = leadConvert.ownerId__c; account.Name = lead.Company; account.AnnualRevenue = lead.AnnualRevenue; account.NameLocal=lead.CompanyLocal; account.Fax=lead.Fax; account.NumberOfEmployees =lead.NumberOfEmployees; account.Phone=lead.Phone; account.Website=lead.Website; account.CurrencyIsoCode=lead.CurrencyIsoCode; account.BillingCity=lead.City; account.BillingCountry =lead.Country; account.BillingPostalCode =lead.PostalCode; account.BillingStreet =lead.Street; account.BillingState=lead.State; account.SCC__c=lead.Account_SCC__c; account.CFU_Account__c=lead.BU__c; account.Industry=lead.Industry; // Added by Jianjun Hu at Apr 9 2015 -Begin RecordType rtCUSTOMER = [ SELECT Id FROM RecordType WHERE Name = 'CUSTOMER'][0]; account.RecordType = rtCUSTOMER; User u = [SELECT Id, Employee_No__c, UserRoleId FROM User WHERE Id = :leadConvert.ownerId__c LIMIT 1][0]; System.debug('leadConvertController.ownerId__c:'+leadConvert.ownerId__c); System.debug('u.Employee_No__c:'+u.Employee_No__c); //Employee__c lstEmployee = [SELECT Id,Name FROM Employee__c // WHERE Employee_No__c = :u.Employee_No__c ]; List<Employee__c> lstEmployee = [SELECT Id,Name FROM Employee__c WHERE Employee_No__c = :u.Employee_No__c ]; System.debug('leadConvertController.lstEmployee.size():'+lstEmployee.size()); if(lstEmployee.size()>0){ account.Co_Owner_Employee__c = lstEmployee[0].Id; } // Added by Jianjun Hu at Apr 9 2015 -End insert account;//将新建的account插入到数据库中 // lead.IsConverted=true; //删除已转为account的lead //将task与该account关联起来,并存入到数据库 task.WhatId = account.Id; insert task; if(leadConvert.sendNotificationEmail__c==true){ contact = new Contact(); /// Added by Jianjun Hu at Apr 9 2015 -Begin account.RecordType = [ SELECT Id FROM RecordType WHERE Name = 'CUSTOMER'][0]; update account; contact.OwnerId=account.OwnerId; contact.accountId =account.id; contact.Description=lead.Description; contact.Email=lead.Email; contact.Fax=lead.Fax; contact.firstname=lead.firstname; contact.lastname=lead.lastname; contact.CurrencyIsoCode=lead.CurrencyIsoCode; contact.MobilePhone=lead.MobilePhone; contact.Phone=lead.Phone; contact.MailingCity =lead.City; contact.MailingState=lead.State; contact.MailingCountry=lead.Country; contact.MailingPostalCode=lead.PostalCode; contact.Sync_from_SERP__c = false; contact.MailingStreet=lead.Street; contact.Sync_from_SERP__c = false; contact.recordtypeId = ([Select Id from RecordType where sObjectType='Contact' and developerName = 'PSA_Resource']).Id; insert contact; converter.setContactId(contact.Id); /// Added by Jianjun Hu at Apr 9 2015 -End opportunity = new Opportunity(); ownerEmail(account, contact, opportunity); } if(IsSendNoticeMail==true){ notificationEmail(contact, task.Id); } converter.setLeadId(lead.Id); converter.setAccountId(account.Id); converter.setDoNotCreateOpportunity(true); converter.setConvertedStatus(leadConvert.convertedStatus__c); Database.convertLead(converter,true); //跳转到account_edit页面 contactPage = new Pagereference('/'+account.Id+'/e?retURL=%2F'+account.Id); } insert leadConvert; contactPage.setRedirect(true); return contactPage; } /* @IsTest public static void testLeadConvertController() { //Profile p = [select id from profile where name='Standard User']; //User u = new User(alias = 'gzgtest', email='gzgtest@testorg.com', //emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US', //localesidkey='en_US', profileid = p.Id, //timezonesidkey='America/Los_Angeles', username='gzgtesting@testorg.com'); //insert u; //System.runAs(u) //{ Lead lead = new Lead(Company='Hisoft1',Status='Qualified',FirstName='HFirst1', LastName='HLastName1', CurrencyIsoCode='USD', BU__c='USBU'); insert lead; Pagereference contactPage = new Pagereference('/LeadConvert?retURL=%2F'+lead.Id+'&id='+lead.Id); Test.setCurrentPageReference(contactPage ); LeadConvertController controller = new LeadConvertController(); Task task = new Task(Subject='TestTask1', Status='In Progress', Priority='Normal', CurrencyIsoCode='USD'); task.OwnerId = UserInfo.getUserId(); controller.setTask(task); controller.IscreateNewAccount=true; controller.IsSendNoticeMail=true; controller.leadConvert.sendNotificationEmail__c=true; controller.Cancel(); controller.Convert(); Lead lead2 = new Lead(Company='Hisoft2',Status='Qualified',FirstName='HFirst2', LastName='HLastName2', CurrencyIsoCode='USD', BU__c='USBU'); insert lead2; Pagereference contactPage2 = new Pagereference('/LeadConvert?retURL=%2F'+lead2.Id+'&id='+lead2.Id); Test.setCurrentPageReference(contactPage2 ); LeadConvertController controller2 = new LeadConvertController(); Account acc2 = new Account(Name = 'Test2', Rating = 'Hot', Account_Creation_Justification__c = 'PR', SCC__c = 'Non SCC', Type = 'Other', Account_Tier__c = 'Ordinary', Customer_Region__c = 'US', CFU_Account__c = 'USBU',Account_Approval__c = 'active'); insert acc2; controller2.leadConvert.accountId__c = acc2.Id; controller2.IscreateNewAccount=false; Task task2 = new Task(Subject='TestTask2', Status='In Progress', Priority='Normal', CurrencyIsoCode='USD'); controller2.setTask(task2); controller2.leadConvert.doNotCreateOpportunity__c = true; controller2.Convert(); Lead lead3 = new Lead(Company='Hisoft3',Status='Qualified',FirstName='HFirst3', LastName='HLastName3', CurrencyIsoCode='USD', BU__c='USBU'); insert lead3; Pagereference contactPage3 = new Pagereference('/LeadConvert?retURL=%2F'+lead3.Id+'&id='+lead3.Id); Test.setCurrentPageReference(contactPage3 ); LeadConvertController controller3 = new LeadConvertController(); Account acc3 = new Account(Name = 'Test3', Rating = 'Hot', Account_Creation_Justification__c = 'PR', SCC__c = 'Non SCC', Type = 'Other', Account_Tier__c = 'Ordinary', Customer_Region__c = 'US', CFU_Account__c = 'USBU',Account_Approval__c = 'active'); insert acc3; controller3.leadConvert.accountId__c = acc3.Id; controller3.IscreateNewAccount=false; Task task3 = new Task(Subject='TestTask2', Status='In Progress', Priority='Normal', CurrencyIsoCode='USD'); task3.OwnerId = UserInfo.getUserId(); controller3.setTask(task3); controller3.leadConvert.doNotCreateOpportunity__c = false; controller3.IsSendNoticeMail=true; controller3.leadConvert.sendNotificationEmail__c=true; controller3.Convert(); Lead lead4 = new Lead(Company='Hisoft4',Status='Qualified',FirstName='HFirst4', LastName='HLastName4', CurrencyIsoCode='USD', BU__c='USBU'); insert lead4; Pagereference contactPage4 = new Pagereference('/LeadConvert?retURL=%2F'+lead4.Id+'&id='+lead4.Id); Test.setCurrentPageReference(contactPage4 ); LeadConvertController controller4 = new LeadConvertController(); Account acc4 = new Account(Name = 'Test4', Rating = 'Hot', Account_Creation_Justification__c = 'PR', SCC__c = 'Non SCC', Type = 'Other', Account_Tier__c = 'Ordinary', Customer_Region__c = 'US', CFU_Account__c = 'USBU',Account_Approval__c = 'active'); insert acc4; controller4.leadConvert.accountId__c = acc4.Id; controller4.IscreateNewAccount=false; Task task4 = new Task(Subject='TestTask4', Status='In Progress', Priority='Normal', CurrencyIsoCode='USD'); controller4.setTask(task4); controller4.leadConvert.doNotCreateOpportunity__c = true; Contact c4 = new Contact(); c4.firstname=lead4.FirstName; c4.lastname = lead4.LastName; c4.accountid=acc4.Id; c4.Email = 'c4@c4.com'; insert c4; Pagereference contactPageA = controller4.Convert(); Test.setCurrentPageReference(contactPageA ); leadConvertContactController controllerA = new leadConvertContactController(); //controllerA.Cancel(); List<SelectOption> contactIdAs = controllerA.getContactOptions(); controllerA.contactId = contactIdAs[2].getValue(); controllerA.Convert(); Lead lead5 = new Lead(Company='Hisoft5',Status='Qualified',FirstName='HFirst5', LastName='HLastName5', CurrencyIsoCode='USD', BU__c='USBU'); insert lead5; Pagereference contactPage5 = new Pagereference('/LeadConvert?retURL=%2F'+lead5.Id+'&id='+lead5.Id); Test.setCurrentPageReference(contactPage5 ); LeadConvertController controller5 = new LeadConvertController(); Account acc5 = new Account(Name = 'Test5', Rating = 'Hot', Account_Creation_Justification__c = 'PR', SCC__c = 'Non SCC', Type = 'Other', Account_Tier__c = 'Ordinary', Customer_Region__c = 'US', CFU_Account__c = 'USBU',Account_Approval__c = 'active'); insert acc5; controller5.leadConvert.accountId__c = acc5.Id; controller5.IscreateNewAccount=false; Task task5 = new Task(Subject='TestTask5', Status='In Progress', Priority='Normal', CurrencyIsoCode='USD'); controller5.setTask(task5); controller5.leadConvert.doNotCreateOpportunity__c = false; Contact c5 = new Contact(); c5.firstname=lead5.FirstName; c5.lastname = lead5.LastName; c5.accountid=acc5.Id; c5.Email = 'c5@c5.com'; c5.Phone = '555555'; insert c5; Pagereference contactPageB = controller5.Convert(); Test.setCurrentPageReference(contactPageB ); leadConvertContactController controllerB = new leadConvertContactController(); List<SelectOption> contactIdBs = controllerB.getContactOptions(); controllerB.contactId = contactIdBs[1].getValue(); controllerB.Convert(); Lead lead6 = new Lead(Company='Hisoft6',Status='Qualified',FirstName='HFirst6', LastName='HLastName6', CurrencyIsoCode='USD', BU__c='USBU'); insert lead6; Pagereference contactPage6 = new Pagereference('/LeadConvert?retURL=%2F'+lead6.Id+'&id='+lead6.Id); contactPage6.getParameters().put('error','1'); Test.setCurrentPageReference(contactPage6 ); LeadConvertController controller6 = new LeadConvertController(); controller6.getId(); controller6.setId(); Account acc6 = new Account(Name = 'Test6', Rating = 'Hot', Account_Creation_Justification__c = 'PR', SCC__c = 'Non SCC', Type = 'Other', Account_Tier__c = 'Ordinary', Customer_Region__c = 'US', CFU_Account__c = 'USBU',Account_Approval__c = 'active'); insert acc6; controller6.setAccount(acc6); controller6.getLeadConvert().accountId__c = acc6.Id; controller6.IscreateNewAccount=false; Task task6 = new Task(Subject='TestTask6', Status='In Progress', Priority='Normal', CurrencyIsoCode='USD'); task6.ActivityDate = Date.today(); task6.OwnerId = UserInfo.getUserId(); controller6.setTask(task6); controller6.leadConvert.doNotCreateOpportunity__c = false; Contact c6 = new Contact(); c6.firstname=controller6.getLead().FirstName; c6.lastname = controller6.getLead().LastName; c6.accountid=controller6.getAccount().Id; c6.Email = 'c6@c6.com'; c6.Phone = '666666'; insert c6; controller6.IsSendNoticeMail=true; controller6.leadConvert.sendNotificationEmail__c=true; //controller6.Convert(); Pagereference contactPageC = controller6.Convert(); Test.setCurrentPageReference(contactPageC ); leadConvertContactController controllerC = new leadConvertContactController(); List<SelectOption> contactIdCs = controllerC.getContactOptions(); controllerC.contactId = contactIdCs[1].getValue(); //controllerC.Convert(); controllerC.Cancel(); //} }*/ }