-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
65Replies
error message on vf pages
Hi visual force experts
Please help me out to achieving following functionality,
current functionality
----------------------------
Error messages are displaying at top of account table,if we doesn't found any opportunities or contacts for selected accounts.
expected functionality
------------------------------
1.)In case the selected accounts doesn't have any opportunities.,error message should display in blank opportunity table under account table with "No Opportunites Found" message.
2.)In case the selected accounts doesn't have any contacts.,error message should display in blank contact table under account table with "No contacts Found" message.
please help me out.
I here by providing my code,please make modifications according to requirement
-----------------------------------------------------------------------------------------------------------------------
Apex class
--------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
// //dispalys error message if we does't found any contact records for selected accounts.
for(accountwrapper aw : actwrap)
{
if(aw.acflag)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
}
else
{
flag3 = false;
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
//dispalys error message if we does't found any opportunity records for selected accounts.
for(accountwrapper aw : actwrap) {
if(aw.acflag)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
} else {
flag2 = false;
}
}
//it hides contacts and dispalys opportunitites on uncheck of contact check box
public void Hideandshowopp()
{
if(oppbox)
{
submit();
} else
{
flag2 = false;
}
}
// it hides opportunities and dispalys contacts on uncheck of opportunities check box
public void HideandshowCon()
{
if(conbox)
{
submit();
}
else
{
flag3 = false;
}
}
public void Hideandshowoppcon() {
Hideandshowopp();
Hideandshowcon();
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap() {
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper
{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false.
public accountwrapper(account a)
{
acc=a;
acflag=false;
}
}
}
vf page
=======
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form>
<!--This block dispalying account record details-->
<apex:pageblock rendered="true">
<apex:pageMessages></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column>
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}">
<apex:actionSupport event="onchange" action="{!Hideandshowoppcon}"/>
</apex:inputCheckbox>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center>
<apex:inputCheckbox value="{!oppbox}">
<apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageMessages></apex:pageMessages>
<apex:pageblocktable value="{!opts}" var="o">
<apex:pageMessages ></apex:pageMessages>
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageMessage summary="info pageMessage" severity="info" strength="3"/>
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
Please help me out to achieving following functionality,
current functionality
----------------------------
Error messages are displaying at top of account table,if we doesn't found any opportunities or contacts for selected accounts.
expected functionality
------------------------------
1.)In case the selected accounts doesn't have any opportunities.,error message should display in blank opportunity table under account table with "No Opportunites Found" message.
2.)In case the selected accounts doesn't have any contacts.,error message should display in blank contact table under account table with "No contacts Found" message.
please help me out.
I here by providing my code,please make modifications according to requirement
-----------------------------------------------------------------------------------------------------------------------
Apex class
--------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
flag2 = false;
flag3 = false;
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
// //dispalys error message if we does't found any contact records for selected accounts.
for(accountwrapper aw : actwrap)
{
if(aw.acflag)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
}
else
{
flag3 = false;
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
//dispalys error message if we does't found any opportunity records for selected accounts.
for(accountwrapper aw : actwrap) {
if(aw.acflag)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
} else {
flag2 = false;
}
}
//it hides contacts and dispalys opportunitites on uncheck of contact check box
public void Hideandshowopp()
{
if(oppbox)
{
submit();
} else
{
flag2 = false;
}
}
// it hides opportunities and dispalys contacts on uncheck of opportunities check box
public void HideandshowCon()
{
if(conbox)
{
submit();
}
else
{
flag3 = false;
}
}
public void Hideandshowoppcon() {
Hideandshowopp();
Hideandshowcon();
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap() {
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper
{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false.
public accountwrapper(account a)
{
acc=a;
acflag=false;
}
}
}
vf page
=======
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form>
<!--This block dispalying account record details-->
<apex:pageblock rendered="true">
<apex:pageMessages></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column>
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}">
<apex:actionSupport event="onchange" action="{!Hideandshowoppcon}"/>
</apex:inputCheckbox>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center>
<apex:inputCheckbox value="{!oppbox}">
<apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageMessages></apex:pageMessages>
<apex:pageblocktable value="{!opts}" var="o">
<apex:pageMessages ></apex:pageMessages>
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageMessage summary="info pageMessage" severity="info" strength="3"/>
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
- anu deep 6
- October 05, 2016
- Like
- 0
visual force bugs need to be fixed
Hi salesforce experts,
I here by requesting you to please help me in fixing following bugs.
current functionality:
==============
1.)If I deselet account records still opportunities and contact records are displaying.
required functionalitiy:
===============
1.)If I deselect account records related opportunities and contact records need to be disappear.
2.)If I select account records,related opportunities and contact records need to be display.
And also plese fix following bugs,
-->Even though I didn't select any account and selected opportunites and clicked on submit it is showing error message. If I select any account and select opportunites check box and click on submit, then only it should show the error message.
-->I need to display a blank table with "No Opportunites Found" message in case the selected accounts doesn't have any opportunities.
The same is the case with contacts.
-->If click on next button in accounts table, still It is displaying opportunities and contacts even though I didn't select anything.
please help me to fix above bugs.
I here by providing code
==================
-->Apex class
--------------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
flag3=true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
flag2=false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//hides contacts and shows opportunities related to accounts,when ever user selects only opportunities check box
public void Hideandshowopp()
{
if(oppbox)
{
submit();
}
else
{
flag2=false;
}
}
//hides opportunities and shows contacts related to accounts,when ever user selects only contats check box
public void HideandshowCon()
{
if(conbox)
{
submit();
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class Accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
---------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="True">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!--check boxs for opportunities and contacts-->
<center>
<apex:inputCheckbox value="{!oppbox}">
<!--On check/uncheck of opp check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<!--On check/uncheck of contact check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}" id="con">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c.id}" Action="{!URLFOR($Action.contact.edit,c.id)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
I here by requesting you to please help me in fixing following bugs.
current functionality:
==============
1.)If I deselet account records still opportunities and contact records are displaying.
required functionalitiy:
===============
1.)If I deselect account records related opportunities and contact records need to be disappear.
2.)If I select account records,related opportunities and contact records need to be display.
And also plese fix following bugs,
-->Even though I didn't select any account and selected opportunites and clicked on submit it is showing error message. If I select any account and select opportunites check box and click on submit, then only it should show the error message.
-->I need to display a blank table with "No Opportunites Found" message in case the selected accounts doesn't have any opportunities.
The same is the case with contacts.
-->If click on next button in accounts table, still It is displaying opportunities and contacts even though I didn't select anything.
please help me to fix above bugs.
I here by providing code
==================
-->Apex class
--------------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
flag3=true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
flag2=false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//hides contacts and shows opportunities related to accounts,when ever user selects only opportunities check box
public void Hideandshowopp()
{
if(oppbox)
{
submit();
}
else
{
flag2=false;
}
}
//hides opportunities and shows contacts related to accounts,when ever user selects only contats check box
public void HideandshowCon()
{
if(conbox)
{
submit();
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class Accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
---------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="True">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!--check boxs for opportunities and contacts-->
<center>
<apex:inputCheckbox value="{!oppbox}">
<!--On check/uncheck of opp check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<!--On check/uncheck of contact check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}" id="con">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c.id}" Action="{!URLFOR($Action.contact.edit,c.id)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
- anu deep 6
- October 04, 2016
- Like
- 0
check box functionality
Hi salesforce family,
followig functionality need to be achieved in below code.Please help me.
current functionality
----------------------------
1.)currently if we uncheck the check boxes of opportunitis and contacts and click submitt button all the contacts and opportunities records related to accounts are getting disappear.
required functionality
-----------------------------
1.)On uncheck the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to disappear.
2.)If we select the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to dispaly.
please try to achieve required functionality and also provide code coverage.
I here by providing code
=================
Apex class
---------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//it hides contacts and dispalys opportunitites on uncheck of contact check box
public void Hideandshowopp()
{
if(oppbox==true)
{
flag2=true;
}
else
{
flag2=false;
}
}
// it hides opportunities and dispalys contacts on uncheck of opportunities check box
public void HideandshowCon()
{
if(conbox==true)
{
flag3=true;
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
----------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="true">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}">
<apex:actionSupport event="onchange" action="{!Hideandshowopp}" rerender="block"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<apex:actionSupport event="onchange" action="{!HideandshowCon}" rerender="block"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
==============================================================================
followig functionality need to be achieved in below code.Please help me.
current functionality
----------------------------
1.)currently if we uncheck the check boxes of opportunitis and contacts and click submitt button all the contacts and opportunities records related to accounts are getting disappear.
required functionality
-----------------------------
1.)On uncheck the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to disappear.
2.)If we select the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to dispaly.
please try to achieve required functionality and also provide code coverage.
I here by providing code
=================
Apex class
---------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//it hides contacts and dispalys opportunitites on uncheck of contact check box
public void Hideandshowopp()
{
if(oppbox==true)
{
flag2=true;
}
else
{
flag2=false;
}
}
// it hides opportunities and dispalys contacts on uncheck of opportunities check box
public void HideandshowCon()
{
if(conbox==true)
{
flag3=true;
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
----------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="true">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}">
<apex:actionSupport event="onchange" action="{!Hideandshowopp}" rerender="block"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<apex:actionSupport event="onchange" action="{!HideandshowCon}" rerender="block"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
==============================================================================
- anu deep 6
- October 03, 2016
- Like
- 0
please fix bugs
HI experts,
requirement:-
=========
Create a visual force page which list all accounts in a table with a check box in front of every row.
Display two check boxes Opportunities and contacts and one submit button, on click of it should show the opportunities/contact list or both according to the selection.
every id column in all tables should point to detail record.
Opportunities and contacts should be editable and saved at a time on click of 'Save Opportunities','Save Contacts' button.
Almost I achieved this requirement but following bugs need to be fixed
=========================================================
1.Opportunities or contacts are not displaying in the same screen.
means :-contacts and opportunities are displaying on another screen,they should display on same screen under Account records table.
======
2.contacts/opportunities checkbox should disappear if user un selects and vice versa.
3.If there are no contacts or accounts for selects Accounts error message should be displayed,empty table should not display.
example error message:-contact records are not found for selected Accounts
================
but currently empty table is displaying.
following is code
=============
Apex controller
=================
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
flag3=true;
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
for(Contact con:snts)
{
if(con.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found contact records for selected Accounts'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
flag2=true;
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
for(Opportunity opt:opts)
{
if(opt.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found opportunity records for selected Accounts'));
}
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
======
vf page
==========
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="{!flag1}">
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}" disabled=""/>Opportunities
<apex:inputCheckbox value="{!conbox}" disabled=""/>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block">
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
=============================================================================================================================
requirement:-
=========
Create a visual force page which list all accounts in a table with a check box in front of every row.
Display two check boxes Opportunities and contacts and one submit button, on click of it should show the opportunities/contact list or both according to the selection.
every id column in all tables should point to detail record.
Opportunities and contacts should be editable and saved at a time on click of 'Save Opportunities','Save Contacts' button.
Almost I achieved this requirement but following bugs need to be fixed
=========================================================
1.Opportunities or contacts are not displaying in the same screen.
means :-contacts and opportunities are displaying on another screen,they should display on same screen under Account records table.
======
2.contacts/opportunities checkbox should disappear if user un selects and vice versa.
3.If there are no contacts or accounts for selects Accounts error message should be displayed,empty table should not display.
example error message:-contact records are not found for selected Accounts
================
but currently empty table is displaying.
following is code
=============
Apex controller
=================
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
flag3=true;
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
for(Contact con:snts)
{
if(con.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found contact records for selected Accounts'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
flag2=true;
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
for(Opportunity opt:opts)
{
if(opt.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found opportunity records for selected Accounts'));
}
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
======
vf page
==========
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="{!flag1}">
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}" disabled=""/>Opportunities
<apex:inputCheckbox value="{!conbox}" disabled=""/>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block">
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
=============================================================================================================================
- anu deep 6
- September 30, 2016
- Like
- 0
display record
dear experts plz help me
Create a VF page which list all accounts in a table with a check box infront of every row. Display two check boxes Opportnities and contacts and one submit button, on click of it should show the opportunitie/contact list or both according to the selection.
every id column in all tables should point to detail record. Opportunities and contacts should be editable and saved at a time on click of 'Save Opportunities','Save Contacts' button.
Create a VF page which list all accounts in a table with a check box infront of every row. Display two check boxes Opportnities and contacts and one submit button, on click of it should show the opportunitie/contact list or both according to the selection.
every id column in all tables should point to detail record. Opportunities and contacts should be editable and saved at a time on click of 'Save Opportunities','Save Contacts' button.
- anu deep 6
- September 20, 2016
- Like
- 0
visual force bugs need to be fixed
Hi salesforce experts,
I here by requesting you to please help me in fixing following bugs.
current functionality:
==============
1.)If I deselet account records still opportunities and contact records are displaying.
required functionalitiy:
===============
1.)If I deselect account records related opportunities and contact records need to be disappear.
2.)If I select account records,related opportunities and contact records need to be display.
And also plese fix following bugs,
-->Even though I didn't select any account and selected opportunites and clicked on submit it is showing error message. If I select any account and select opportunites check box and click on submit, then only it should show the error message.
-->I need to display a blank table with "No Opportunites Found" message in case the selected accounts doesn't have any opportunities.
The same is the case with contacts.
-->If click on next button in accounts table, still It is displaying opportunities and contacts even though I didn't select anything.
please help me to fix above bugs.
I here by providing code
==================
-->Apex class
--------------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
flag3=true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
flag2=false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//hides contacts and shows opportunities related to accounts,when ever user selects only opportunities check box
public void Hideandshowopp()
{
if(oppbox)
{
submit();
}
else
{
flag2=false;
}
}
//hides opportunities and shows contacts related to accounts,when ever user selects only contats check box
public void HideandshowCon()
{
if(conbox)
{
submit();
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class Accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
---------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="True">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!--check boxs for opportunities and contacts-->
<center>
<apex:inputCheckbox value="{!oppbox}">
<!--On check/uncheck of opp check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<!--On check/uncheck of contact check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}" id="con">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c.id}" Action="{!URLFOR($Action.contact.edit,c.id)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
I here by requesting you to please help me in fixing following bugs.
current functionality:
==============
1.)If I deselet account records still opportunities and contact records are displaying.
required functionalitiy:
===============
1.)If I deselect account records related opportunities and contact records need to be disappear.
2.)If I select account records,related opportunities and contact records need to be display.
And also plese fix following bugs,
-->Even though I didn't select any account and selected opportunites and clicked on submit it is showing error message. If I select any account and select opportunites check box and click on submit, then only it should show the error message.
-->I need to display a blank table with "No Opportunites Found" message in case the selected accounts doesn't have any opportunities.
The same is the case with contacts.
-->If click on next button in accounts table, still It is displaying opportunities and contacts even though I didn't select anything.
please help me to fix above bugs.
I here by providing code
==================
-->Apex class
--------------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
flag3=true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
flag2=false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//hides contacts and shows opportunities related to accounts,when ever user selects only opportunities check box
public void Hideandshowopp()
{
if(oppbox)
{
submit();
}
else
{
flag2=false;
}
}
//hides opportunities and shows contacts related to accounts,when ever user selects only contats check box
public void HideandshowCon()
{
if(conbox)
{
submit();
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class Accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
---------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="True">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!--check boxs for opportunities and contacts-->
<center>
<apex:inputCheckbox value="{!oppbox}">
<!--On check/uncheck of opp check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!Hideandshowopp}"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<!--On check/uncheck of contact check box it records appear/disapper-->
<apex:actionSupport event="onchange" action="{!HideandshowCon}"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}" id="con">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c.id}" Action="{!URLFOR($Action.contact.edit,c.id)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
- anu deep 6
- October 04, 2016
- Like
- 0
check box functionality
Hi salesforce family,
followig functionality need to be achieved in below code.Please help me.
current functionality
----------------------------
1.)currently if we uncheck the check boxes of opportunitis and contacts and click submitt button all the contacts and opportunities records related to accounts are getting disappear.
required functionality
-----------------------------
1.)On uncheck the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to disappear.
2.)If we select the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to dispaly.
please try to achieve required functionality and also provide code coverage.
I here by providing code
=================
Apex class
---------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//it hides contacts and dispalys opportunitites on uncheck of contact check box
public void Hideandshowopp()
{
if(oppbox==true)
{
flag2=true;
}
else
{
flag2=false;
}
}
// it hides opportunities and dispalys contacts on uncheck of opportunities check box
public void HideandshowCon()
{
if(conbox==true)
{
flag3=true;
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
----------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="true">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}">
<apex:actionSupport event="onchange" action="{!Hideandshowopp}" rerender="block"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<apex:actionSupport event="onchange" action="{!HideandshowCon}" rerender="block"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
==============================================================================
followig functionality need to be achieved in below code.Please help me.
current functionality
----------------------------
1.)currently if we uncheck the check boxes of opportunitis and contacts and click submitt button all the contacts and opportunities records related to accounts are getting disappear.
required functionality
-----------------------------
1.)On uncheck the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to disappear.
2.)If we select the check boxs of opportunities and contacts with out clicking submitt button all the contacts and opportunities records related to accounts need to dispaly.
please try to achieve required functionality and also provide code coverage.
I here by providing code
=================
Apex class
---------------
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
if(snts.size()>0)
{
flag3=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'contact records are not found for selected Accounts.'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
if(opts.size() >0)
{
flag2=true;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'opportunity records are not found for selected Accounts.'));
}
}
}
//it hides contacts and dispalys opportunitites on uncheck of contact check box
public void Hideandshowopp()
{
if(oppbox==true)
{
flag2=true;
}
else
{
flag2=false;
}
}
// it hides opportunities and dispalys contacts on uncheck of opportunities check box
public void HideandshowCon()
{
if(conbox==true)
{
flag3=true;
}
else
{
flag3=false;
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
----------
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="true">
<apex:pageMessages ></apex:pageMessages>
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}">
<apex:actionSupport event="onchange" action="{!Hideandshowopp}" rerender="block"/>
</apex:inputCheckbox>Opportunities
<apex:inputCheckbox value="{!conbox}">
<apex:actionSupport event="onchange" action="{!HideandshowCon}" rerender="block"/>
</apex:inputCheckbox>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block" >
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
==============================================================================
- anu deep 6
- October 03, 2016
- Like
- 0
please fix bugs
HI experts,
requirement:-
=========
Create a visual force page which list all accounts in a table with a check box in front of every row.
Display two check boxes Opportunities and contacts and one submit button, on click of it should show the opportunities/contact list or both according to the selection.
every id column in all tables should point to detail record.
Opportunities and contacts should be editable and saved at a time on click of 'Save Opportunities','Save Contacts' button.
Almost I achieved this requirement but following bugs need to be fixed
=========================================================
1.Opportunities or contacts are not displaying in the same screen.
means :-contacts and opportunities are displaying on another screen,they should display on same screen under Account records table.
======
2.contacts/opportunities checkbox should disappear if user un selects and vice versa.
3.If there are no contacts or accounts for selects Accounts error message should be displayed,empty table should not display.
example error message:-contact records are not found for selected Accounts
================
but currently empty table is displaying.
following is code
=============
Apex controller
=================
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
flag3=true;
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
for(Contact con:snts)
{
if(con.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found contact records for selected Accounts'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
flag2=true;
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
for(Opportunity opt:opts)
{
if(opt.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found opportunity records for selected Accounts'));
}
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
======
vf page
==========
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="{!flag1}">
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}" disabled=""/>Opportunities
<apex:inputCheckbox value="{!conbox}" disabled=""/>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block">
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
=============================================================================================================================
requirement:-
=========
Create a visual force page which list all accounts in a table with a check box in front of every row.
Display two check boxes Opportunities and contacts and one submit button, on click of it should show the opportunities/contact list or both according to the selection.
every id column in all tables should point to detail record.
Opportunities and contacts should be editable and saved at a time on click of 'Save Opportunities','Save Contacts' button.
Almost I achieved this requirement but following bugs need to be fixed
=========================================================
1.Opportunities or contacts are not displaying in the same screen.
means :-contacts and opportunities are displaying on another screen,they should display on same screen under Account records table.
======
2.contacts/opportunities checkbox should disappear if user un selects and vice versa.
3.If there are no contacts or accounts for selects Accounts error message should be displayed,empty table should not display.
example error message:-contact records are not found for selected Accounts
================
but currently empty table is displaying.
following is code
=============
Apex controller
=================
public class Acc_con_Opp_Details
{
//list of collection of the wrapper class object
public list<accountwrapper> actwrap {set;get;}
//list of collection of Account,contact and opportunity objects
public list<Account> accounts {set;get;}
public list<Account> acts {set;get;}
public list<opportunity> opts {set;get;}
public list<opportunity> sopts {set;get;}
public list<contact> cnts {set;get;}
public list<contact> snts {set;get;}
public boolean oppbox {set;get;}//used as check box for opportunity
public boolean conbox {set;get;}//used as check box for contact
public boolean flag1 {set;get;}//used in account page block
public boolean flag2 {set;get;}//used in contact page block
public boolean flag3 {set;get;}//used in opportunity page block
//this variables are used for pagination purpose
private integer totalRecs = 0;//stores no.of total records
private integer index = 0;//used for tracking offset
private integer blockSize =5;//for setting size of page
//in this constructor we are setting values to boolean values
public Acc_con_Opp_Details()
{
flag1=true;
flag2=false;
flag3=false;
totalRecs = [select count() from Account];//returns total no.of account records
getactwrap();//calling getactwrap method.
}
//this method displays first five records
public void beginning()
{
oppbox=false;
conbox=false;
index = 0;
getactwrap();
}
//this method displays prevoius records
public void previous()
{
oppbox=false;
conbox=false;
index = index-blockSize;
getactwrap();
}
//this method displays next records
public void next()
{
oppbox=false;
conbox=false;
index = index+blockSize;
getactwrap();
}
//this method displays last remaining records
public void end()
{
oppbox=false;
conbox=false;
index = totalrecs - math.mod(totalRecs,blockSize);
getactwrap();
}
//this variable is used to enable or disable first and previous buttons
public boolean prev{get
{
if(index == 0)
return true;
else
return false;
} set;}
//this variable is used to enable or disable next and last buttons
public boolean nxt{get
{
if((index + blockSize) > totalRecs)
return true;
else
return false;
} set;}
//used to display opportunities and contacts w.r.t selected accounts
public void submit()
{
flag1=false;
acts=new list<Account>();
for(accountwrapper aw:actwrap)
{
if(aw.acflag){
acts.add(aw.acc);
}
}
//if we select contact check box,then it displays contacts for selected accounts
if(conbox)
{
flag3=true;
snts=[select id,lastName,Department,account.name from contact where accountid IN:acts];
for(Contact con:snts)
{
if(con.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found contact records for selected Accounts'));
}
}
//if we select opportunity check box,then it displays opportunities for selected accounts
if(oppbox)
{
flag2=true;
opts=[select id,name,stageName,leadsource,account.name from opportunity where accountId IN:acts];
for(Opportunity opt:opts)
{
if(opt.id==null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'could not found opportunity records for selected Accounts'));
}
}
}
//This method uses a simple SOQL query to return a List of Accounts
public void getactwrap(){
accounts = Database.Query('SELECT id,Name,phone FROM Account LIMIT :blockSize OFFSET :index');
actwrap=new list<accountwrapper>();
// As each Account is processed we create a new accountwrapper object and add it to the wrapper class(accountwrapper) list.
for(account a:accounts)
{
actwrap.add(new accountwrapper(a));
}
}
// this method uses dml operation to edit the existing opportunities values or to insert new oppt values
public void saveopps()
{
list<opportunity> opps=new list<opportunity>();
opps.addAll(opts);
upsert opps;
}
//his method uses dml operation to edit the existing contact values or to insert new contact values
public void savecons()
{
cnts = new list<contact>();
cnts.addall(snts);
upsert cnts;
}
//This is wrapper class which is collection of other class instances
//here wrapper class contains both the standard salesforce object Account and a Boolean value acflag
public class accountwrapper{
public account acc{set;get;}
public boolean acflag{set;get;}
//In this contructor When we create a new accountwrapper object we pass a Account that is set to the acc property.
// We also set the boolean value to false
public accountwrapper(account a){
acc=a;
acflag=false;
}
}
}
vf page
======
vf page
==========
<apex:page controller="Acc_con_Opp_Details" showHeader="false" docType="html-5.0">
<apex:form >
<!--This block dispalying account record details-->
<apex:pageblock rendered="{!flag1}">
<apex:pageblocktable value="{!actwrap}" var="a">
<apex:column >
<apex:facet name="header" >Select</apex:facet>
<apex:inputCheckbox value="{!a.acflag}"/>
</apex:column>
<!-- displays id,name and phone number for accounts-->
<apex:column value="{!a.acc.id}"/>
<apex:column value="{!a.acc.name}"/>
<apex:column value="{!a.acc.phone}"/>
</apex:pageblocktable>
<!-- this buttons are used to paginate account records-->
<apex:pageblockButtons >
<!--displays first five records-->
<apex:commandButton value="first" action="{!beginning}" disabled="{!prev}"/>
<!--displays previous records-->
<apex:commandButton value="previous" action="{!previous}" disabled="{!prev}"/>
<!--displays previous next records-->
<apex:commandButton value="next" action="{!next}" disabled="{!nxt}"/>
<!-- displays last records-->
<apex:commandButton value="last" action="{!end}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<!-- check boxs for opportunities and contacts-->
<center> <apex:inputCheckbox value="{!oppbox}" disabled=""/>Opportunities
<apex:inputCheckbox value="{!conbox}" disabled=""/>Contacts
<apex:commandButton value="submit" action="{!submit}"/>
</center>
</apex:pageblock>
<!--this block displays opportunity details-->
<apex:pageblock rendered="{!flag2}" id="block">
<apex:pageblocktable value="{!opts}" var="o">
<apex:column >
<apex:facet name="header">Opportunity Id</apex:facet>
<apex:commandlink value="{!o.id}" Action="{!URLFOR($Action.opportunity.edit,o.Id)}"/>
</apex:column>
<apex:column value="{!o.account.name}" />
<apex:column >
<apex:facet name="header">Opportunity Name</apex:facet>
<apex:inputtext value="{!o.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Stage</apex:facet>
<apex:inputtext value="{!o.stagename}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Leadsource</apex:facet>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Opportunities" action="{!saveopps}"/>
</apex:pageblock>
<!--this block is used for displaying contact details -->
<apex:pageblock rendered="{!flag3}">
<apex:pageblocktable value="{!snts}" var="c">
<apex:column >
<apex:facet name="header">Contact Id</apex:facet>
<apex:commandlink value="{!c}" Action="{!URLFOR($Action.contact.edit,c)}"/>
</apex:column>
<apex:column value="{!c.account.name}"/>
<apex:column >
<apex:facet name="header">Contact Lastname</apex:facet>
<apex:inputtext value="{!c.lastname}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Contact Department</apex:facet>
<apex:inputtext value="{!c.Department}"/>
</apex:column>
</apex:pageblocktable>
<apex:commandButton value="Save Contacts" action="{!savecons}"/>
</apex:pageblock>
</apex:form>
</apex:page>
=============================================================================================================================
- anu deep 6
- September 30, 2016
- Like
- 0