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
SFDHSFDH 

how to hide/show pageblocksection upon button selection?

hi ...

 

 I was trying to create a custom Vf lead conversion page , in which i want to have a contact section which is to display a Existing contact bydefault and upon user's selection of clicking a button i want to display some input fields to create NEW contact , i have created the VF but the Contact section is not working as expected ... i tried checkbox method also but same result , when i use this contact pageblocksection in seperate VF page it works but not working with that Lead conversion page ... I am stuck with something and dont know what to do ... please help ......

 

  • If the existing contact selected it should use that contact for that lead ( this works for me )
  • if User wants to create a new Contact then while converthing it should create a new contact ..

 

My VF code : 

 

<apex:page standardController="lead" tabStyle="Lead" extensions="leadconvertController" >
<apex:messages />
<apex:sectionHeader title="Convert Lead"/>

 

<apex:form >
<apex:pageBlock mode="Edit">
<apex:pagemessages />
<apex:pageBlockSection title="Convert Lead" columns="1">

<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="{!Lead.Ownerid}"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel for="Last Name">Last Name</apex:outputLabel>
<apex:inputField id="Name" value="{!Lead.LastName}" />
</apex:pageBlockSectionItem>

 

<apex:pageBlockSectionItem >
<apex:outputLabel for="Account Name">Account Name</apex:outputLabel>
<apex:inputField required="true" id="Owner" value="{!Lead.Company}" />
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel for="Oppt Name">Opportunity Name:</apex:outputLabel>
<apex:inputField required="true" 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 required="true" onselect="{!lead.Company}"/>
</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="Contact Information" rendered="{!!hideShow}">
Do you want to Create New Contact—<br/>
<apex:commandButton action="{!showSection1}" value="Yes" styleClass="btn" rerender="details"></apex:commandButton>

</apex:pageBlockSection>

 


<apex:pageBlockSection >

<apex:pageBlockSectionItem id="pbsi" >
<apex:outputLabel value="Existing contact Name" for="contactName"/>
<apex:selectList id="contactname" value="{!contactName}" size="1" multiselect="false">
<apex:selectoptions value="{!ContactList}" />
</apex:selectList>
</apex:pageBlockSectionItem>

</apex:pageBlockSection>

 

<apex:pageBlockSection id="newData" title="Discount Rates" rendered="{!hideshow}">

<apex:pageBlockSectionItem id="pbsi1">
<apex:outputLabel value="First Name" for="Firstname" />
<apex:inputText id="Firstname" value="{!FirstName}" size="40"/>
</apex:pageBlockSectionItem>


<apex:pageBlockSectionItem id="pbsi2" >
<apex:outputLabel value="Last Name" for="Lastname"/>
<apex:inputText id="Lastname" value="{!LastName}" size="40"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Phone" for="Phone"/>
<apex:inputText value="{!Phone}" id="Phone"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Mobile" for="MobilePhone" />
<apex:inputText value="{!Mobile}" id="MobilePhone"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Title" for="Title"/>
<apex:inputText value="{!Title}" id="Title"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Email" for="Email"/>
<apex:inputText value="{!Email}" id="Email"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Website" for="Website"/>
<apex:inputText value="{!Website}" id="Website"></apex:inputText>
</apex:pageBlockSectionItem>

<apex:pageBlockSection >
<apex:inputField value="{!lwn.ReportsToId}"/>
<apex:outputLabel />
</apex:pageBlockSection>

</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="Phone">Phone</apex:outputLabel>
<apex:inputField required="true" id="Phone" value="{!Lead.Phone}"/>
</apex:pageblockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel for="Email">Email</apex:outputLabel>
<apex:inputField required="true" id="Email" value="{!Lead.Email}"/>
</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="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:pageBlockSection>

<apex:pageBlockSection title="Description Information" columns="1" id="DescriptionInformation">
<apex:pageBlockSectionItem >
<apex:outputLabel for="Subject">Subject</apex:outputLabel>
<apex:inputField required="true" value="{!Task.Subject}"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel for="Comments">Comments</apex:outputLabel>
<apex:inputField value="{!Task.Description}"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:OutputLabel for="Send Notification Email">Send Notification Email</apex:OutputLabel>
<apex:inputCheckbox onclick=""/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockSection title="Reminder" columns="1" id="Reminder">
<apex:pageBlockSectionItem >
<apex:outputLabel for="Reminder">Reminder</apex:outputLabel>
<apex:inputField id="Reminder" value="{!task.ReminderDateTime}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockButtons >
<apex:commandButton action="{!convertLead}" value="Convert"/>
<apex:commandButton Action="{!Cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

My CLASS:

public class leadconvertController
{

Opportunity opty;
Id optt;
Account account;
Contact contact;
Boolean testval = false;
public Boolean isChecked { get; set; }
public String contactName{get;set;}
private final Lead Lead;
public String leadName{get;set;}
public String FirstName {get; set;}
public String LastName {get; set;}
public contact lwn {get; set;}
public String Description{get;set;}
public String leadSource{get;set;}
public String leadIndustryName{get;set;}
public String leadstatus{get;set;}
public string Mobile{get;set;}
public string Phone{get;set;}
public string email{get;set;}
public string Website{get;set;}
public string leadrating{get;set;}
public string Title{get;set;}
Public String Street{get;Set;}
Public String City{get;Set;}
Public String State{get;Set;}
Public String PostalCode{get;Set;}
Public String Country{get;Set;}

public List<SelectOption> getContactList()

{
Contact[] Contacts = [SELECT Id,Firstname,Lastname,name,reportstoid FROM Contact];
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('- None Selected - ','- None Selected - '));
for (Contact acc : Contacts)
{
options.add(new SelectOption(acc.Name,acc.Name));
}
return options;
}

public Task getTask()
{
Task tsk = new Task();
return tsk;
}

public List<SelectOption> getStatus()
{
List<SelectOption> options = new List<SelectOption>();

Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Lead.fields.status;

List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}

public List<SelectOption> getLeadIndustryNames()
{
List<SelectOption> options = new List<SelectOption>();

Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Lead.fields.Industry;

List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}

public List<SelectOption> getPriority()
{
List<SelectOption> options = new List<SelectOption>();

Schema.DescribeFieldResult fieldResult = Schema.sObjectType.Account.fields.CustomerPriority__c;

List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}

public leadconvertController(ApexPages.StandardController stdController)
{
this.Lead = (Lead)stdController.getRecord();
}



public PageReference convertlead()
{
try
{
String id = ApexPages.currentpage().getParameters().get('id');
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);
if(lcr.isSuccess())
{
String cId = lcr.getContactId();
Contact con = [select LastName, FirstName from Contact where Id = :cId];
String[] nameProxy = contactName.split(' ');
if(nameProxy.size() == 1)
{
con.LastName = nameProxy[0];
}
else
{
con.FirstName = nameProxy[0];
con.LastName = nameProxy[1];
}
update con;
PageReference redirect = new PageReference('/' + cId);
redirect.setRedirect(true);
return redirect;
}
}
catch(Exception e)
{
ApexPages.addMessages(e);
}
return null;
}

public pagereference showSection1()
{
setHideshow(true);
return null;
}


public Boolean getHideshow()
{
return this.testval;
}
public void setHideshow(boolean s)
{
this.testval = s;
}
}

 

please suggest me a solution :

 

mail id : sfdc1026@gmail.com

Skype : SFDC1026