• harish r 20
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi 


vf page 

public class leadController {
        
public leadController(ApexPages.StandardController controller) {
}
public Task getTask(){
    Task tsk = new Task();
    return tsk;
}
    
}

apex class 


public class leadController {
        
public leadController(ApexPages.StandardController controller) {
}
public Task getTask(){
    Task tsk = new Task();
    return tsk;
}
    
}



In this code press convert button it will refresh to get same page. what i have to in this situation? 

please reply me as soon as possible


Regards
Harish.R
harishramachandruni04@gmail.com
 
 

Hi All, in my custom object I am having a cutom button"convert" when i click this button"convert"it will  create new Account,Contact and Opportunity. But I need to do same as Lead(Ie,. in Lead if click "convert" button it will go to an other page where we can existing Account for that or we can create a new Account. For creating Opportunity it will have a checkbox which will ask us whether we have to new opportunity for that record, after we made all this we again  "convert")

Like that when i click my custom button"convert" on my custom tab, it must go to another window from that page we have select Account for that(existing or new) if i select existing account means all Account must be displayed in the listbox, we have to select any from that and we have to  create a new opportunity for that record.

 

Here i have attached my Apex code to create Account, contact and opportunity.Also VF page code.

Apex code:

 

public class Convert
{

public PageReference RedirecttoSite()
{
String currentLead = '/' + siteObj.Id;
PageReference pageRef = new PageReference(currentLead);
return pageRef;
}

private Site__c siteObj;
//public ID Cus_Account_ID, Cus_obj_Record_ID;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public Convert(ApexPages.StandardController stdController)
{
System.debug('******sai******');
siteObj = (Site__c)stdController.getRecord();
// Cus_obj_Record_ID=siteObj.Id;
}
List<Account> acctList = new List<account>();
public void convertbutton()
{

Account acc = new Account();
acc.Name = siteObj.Company_Name__c;
acctList = [select id from Account where Name = :acc.Name];
if (acctList.size() > 0)
{

ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'Account Name ' + acc.Name + ' already exists,Duplicate Account Name not allowed');
ApexPages.addMessage(errormsg);
return;
}
acc.BillingStreet = siteObj.Company_Address__c;
acc.BillingCity = siteObj.Company_City__c;
acc.BillingState= siteObj.Company_State__c;
acc.BillingPostalCode = siteObj.Company_Postal_Code__c;
acc.Phone = siteObj.Company_Phone__c;
acc.Website = siteObj.Company_Email__c;
acc.Fax = siteObj.Company_Fax__c;
// acc.CurrencyIsoCode = siteObj.CurrencyIsoCode;

try
{
insert acc;
ApexPages.Message successmsg = new ApexPages.Message(ApexPages.severity.confirm,'New Account ' + acc.Name + ' is created, Related Contact and Opporunity also created' );
ApexPages.addMessage(successmsg);
}
Catch (Exception ex1)
{
ex1.getmessage();
}
Contact cc = new Contact();
cc.LastName = siteObj.Contact_Name__c;
cc.Email = siteObj.Contact_Email__c;
cc.Phone = siteObj.Contact_Mobile__c;
cc.AccountId = acc.Id;

try
{
insert cc;
}
Catch (Exception ex2)
{

ex2.getmessage();
}

Opportunity opp = new Opportunity();
opp.Name = siteObj.Opp_Name__c;
opp.AccountId= acc.Id;
opp.CloseDate = siteObj.Opp_CloseDate__c;
opp.StageName = siteObj.Opp_stage__c;
if(opp.StageName == 'Needs Analysis')
opp.Probability= 20;
else if(opp.StageName == 'Prospecting')
opp.Probability= 10;
else if(opp.StageName == 'Negotiation/Review')
opp.Probability= 90;
else if(opp.StageName == 'Closed Won')
opp.Probability= 100;
else if(opp.StageName == 'Closed Lost')
opp.Probability= 0;

try
{
insert opp;
}
Catch (Exception ex3)
{
 ex3.getmessage();
}

}
 }

 

VF page code for "convert"button:

<apex:page standardController="Site__c" cache="true" action="{!convertbutton}" extensions="Convert" >
<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>
<!--<apex:pagemessages />-->
<apex:outputField value="{!Site__c.Company_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Address__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_City__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_State__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Postal_Code__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Phone__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Company_Fax__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Contact_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Email__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Contact_Mobile__c}" rendered="false"/>

<!--<apex:outputField value="{!Site__c.CurrencyIsoCode}" rendered="false"/>-->
<apex:outputField value="{!Site__c.ConvertedSite__c}" rendered="false"/>

<apex:outputField value="{!Site__c.Opp_Name__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_CloseDate__c}" rendered="false"/>
<apex:outputField value="{!Site__c.Opp_stage__c}" rendered="false"/>


<apex:commandLink value="Redirect to Site" style="color:blue; font-weight:bold;" action="{!RedirecttoSite}"/>

</center>

</apex:form>
</apex:page>

 

Any one tell how to do this. kindly give me any idea for this and tell me any sample code for this.Waitng for your reply

 

Regards,

Lavanya.

 

Hi All

 

I am trying to convert the lead to opportunity and there are many custom fields required in the convert page. so i written a vf page to include all my custom fields in the page. the issue i am facing is i want the Account to be lookup in the VF page and the convert button is not working with the code i written in the VF page. please have a look at my VF page and the apex class i written for this task. appreciate for all your help

 

VF Page:

 

<apex:page standardController="lead" tabStyle="Lead" extensions="leadController" >
<apex:messages />
<apex:sectionHeader title="Convert Lead"/>
<apex:form >
<apex:pageBlock mode="Edit">
<apex:pagemessages />
<apex:pageBlockSection title="Convert Lead">
         <apex:pageBlockSectionItem >
            <apex:outputLabel value=" Record Owner" for="Record Owner"/>
            <apex:inputField value="{!Lead.OwnerID}"/>
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
           <apex:OutputLabel for="Send Email to the Owner">Send Email to the Owner:</apex:OutputLabel>
           <apex:inputCheckbox onclick=""/>
           </apex:pageBlockSectionItem>            
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Account Name">Account Name</apex:outputLabel>
             <apex:inputField id="Owner" value="{!Lead.Company}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Oppt Name">Opportunity Name:</apex:outputLabel>
             <apex:inputField id="Owner" value="{!Lead.Company}" />
          </apex:pageBlockSectionItem>
          <apex:pageblockSectionItem >
          <apex:outputLabel for="no oppty">Do not create new opportunity upon conversion</apex:outputLabel>
          <apex:inputCheckbox onselect=""/>
          </apex:pageblockSectionItem>
          <apex:pageBlockSectionItem >
                      <apex:outputLabel for="ConStatus">Converted Status:</apex:outputLabel>
             <apex:inputField id="ConStatus" value="{!Lead.Status}" />
          </apex:pageBlockSectionItem>
          </apex:pageBlockSection>         
<apex:pageBlockSection title="Address Information" columns="2" id="AddressInformation">
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="StreetAdd">Street Address:</apex:outputLabel>
          <apex:inputField Id="StreetAdd" Value="{!Lead.Street}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="City">City:</apex:outputLabel>
          <apex:inputField Id="City" Value="{!Lead.City}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="State">State:</apex:outputLabel>
            <apex:inputField Id="State" Value="{!Lead.State}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Zip">Postal Code:</apex:outputLabel>
            <apex:inputField Id="Zip" Value="{!Lead.PostalCode}" />
          </apex:pageBlockSectionItem>                    
          </apex:pageBlockSection>
 <apex:pageBlockSection title="Additional Information" columns="2" id="AdditionalInformation">
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="NoofEmp">No. Of Employees:</apex:outputLabel>
            <apex:inputField Id="Owner" Value="{!Lead.NumberOfEmployees}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Revenue">Annual Revenue:</apex:outputLabel>
                <apex:inputField Id="Revenue" Value="{!Lead.AnnualRevenue}" />      
                      </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Industry">Industry:</apex:outputLabel>
           <apex:inputField Id="Industry" Value="{!Lead.Industry}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Description">Description:</apex:outputLabel>
            <apex:inputField Id="Description" Value="{!Lead.Description}" />
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Website">Website:</apex:outputLabel>
          <apex:inputField Id="Website" Value="{!Lead.Website}" />
          </apex:pageBlockSectionItem>  
          </apex:pageBlockSection>                                   
<apex:pageBlockSection title="Task Information" columns="2" id="TaskInformation">
          
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Subject">Subject</apex:outputLabel>
            <apex:inputField value="{!Task.Subject}"/>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Status">Status</apex:outputLabel>
            <apex:inputField value="{!Task.Status}"/>
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="DueDate">Due Date</apex:outputLabel>
            <apex:inputField value="{!Task.ActivityDate}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Priority">Priority</apex:outputLabel>
            <apex:inputField value="{!Task.Priority}"/>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="EndDate">Completed Date:</apex:outputLabel>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Followupdate">Followup Date:</apex:outputLabel>
          </apex:pageBlockSectionItem>
          </apex:pageBlockSection>      
<apex:pageBlockSection title="Description Information" columns="1" id="DescriptionInformation">
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Sub">Subject:</apex:outputLabel>
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="Comments">Comments</apex:outputLabel>
            <apex:inputField value="{!Task.Description}"/>
          </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel for="ExtDescription">Extended Description:</apex:outputLabel>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
          <apex:OutputLabel for="Send Notification Email">Send Notification Email:</apex:OutputLabel>
           <apex:inputCheckbox onclick=""/>
           </apex:pageBlockSectionItem>
          </apex:pageBlockSection>    
<apex:pageBlockButtons >  
        <apex:commandButton value="Convert"/>
        <apex:commandButton Action="{!Cancel}" value="Cancel"/>
         </apex:pageBlockButtons>                                     
          </apex:pageBlock>  
</apex:form>               
</apex:page>
Class:

 
public class leadController {
        
public leadController(ApexPages.StandardController controller) {
}
public Task getTask(){
    Task tsk = new Task();
    return tsk;
}
    
}