I have 13 to 14 sections on a page. I want to call them using actionfunction asynchronusly using queue or chaining mechanism.
So that only one section is called at a time. And performance of page is enhanced.
Has any one done action function chaining ?
Please help
Here is code :
<apex:form >
<apex:pageBlock title="{!$Label.Leads_Requiring_Attention}" id="LeadPB" rendered="{!IF(UnacceptedLeads.SIZE==0 && AcceptedLeads.SIZE==0 && QualifiedLeads.SIZE==0 , 'false', 'true')}" >
<!-- LEAD SECTION 1 : UNACCEPTED LEADS -->
<apex:pageBlocksection title="Unaccepted leads – assigned but not accepted ({!$Label.Record_Count}: {!NoOfEntriesFound}){!$Label.AlertUnacceptedleads}" id="LeadBlock2" collapsible="false" columns="1" rendered="{!IF(UnacceptedLeads.SIZE>0, 'true', 'false')}" >
<apex:pageBlockTable value="{!UnacceptedLeads}" var="lead" id="Leadtable2" style="width:100%" >
<apex:column headerValue="Name">
<apex:outputlink value="/{!lead.Id}" >
<!-- <apex:param name="leadId" value="{!lead.Id}"/> -->
{!lead.Name}
</apex:outputlink>
</apex:column>
<apex:column headerValue="Company" value="{!lead.Company}"/>
<apex:column headerValue="Lead Source" value="{!lead.LeadSource}"/>
<apex:column headerValue="Lead Source Details" value="{!lead.Lead_Source_Details_del__c}"/>
<apex:column headerValue="Created Date " value="{!lead.CreatedDate}"/>
<apex:column headerValue="Days Open" value="{!lead.Days_Open_Unaccepted_leads__c}"/>
<apex:column headerValue="Owner Name" value="{!lead.Owner.Name}" rendered="{!IF(ownername, 'true', 'false')}"/>
</apex:pageBlockTable>
<!-- LEAD SECTION 1 : PAGINATION -->
<apex:panelGrid columns="2" style="font-weight: bold;" id="pgtable1" >
<apex:commandLink action="{!previous}" rerender="Leadtable2,pgtable1" immediate="true" status="Loading1" ><font color="blue">Previous</font></apex:commandLink>
<apex:commandLink action="{!next}" rerender="Leadtable2,pgtable1" immediate="true" status="Loading1"><font color="blue">Next</font></apex:commandLink>
<apex:outputText value="Page {!pageNumber} of {!pages} " />
</apex:panelGrid>
<apex:actionStatus id="Loading1" >
<apex:facet name="start" ><font color="red">Loading the data, please wait....</font></apex:facet>
<apex:facet name="stop"><font color="blue">Data Loaded ,Thanks for patience!</font></apex:facet>
</apex:actionStatus>
</apex:pageBlocksection>
<!-- LEAD SECTION 2 : ACCEPTED LEADS -->
<apex:pageBlocksection title="Accepted Stuck leads – in a
or contacting status for more than 7 days ({!$Label.Record_Count}: {!NoOfEntriesFoundAL}). Review to see if it can progress or if it should be closed " id="LeadBlock3" collapsible="false" columns="1" rendered="{!IF(AcceptedLeads.SIZE>0, 'true', 'false')}" >
<apex:pageBlockTable value="{!AcceptedLeads}" var="lead" id="Leadtable3" rows="5" style="width:100%">
<apex:column headerValue="Name">
<apex:outputlink value="/{!lead.Id}" >
<!-- <apex:param name="leadId" value="{!lead.Id}"/> -->
{!lead.Name}
</apex:outputlink>
</apex:column>
<apex:column headerValue="Company" value="{!lead.Company}"/>
<apex:column headerValue="Lead Source" value="{!lead.LeadSource}"/>
<apex:column headerValue="Lead Source Details" value="{!lead.Lead_Source_Details_del__c}"/>
<apex:column headerValue="Created Date " value="{!lead.CreatedDate}"/>
<apex:column headerValue="Accepted Date " value="{!lead.Accepted_Date__c}"/>
<!-- <apex:column headerValue="Days Since Accepted Old" value="{!lead.Untouched_Duration__c}"/> -->
<apex:column headerValue="Days Since Accepted " value="{!lead.Days_Since_Accepted__c}"/>
<apex:column headerValue="Owner Name" value="{!lead.Owner.Name}" rendered="{!IF(ownername, 'true', 'false')}"/>
</apex:pageBlockTable>
<!-- LEAD SECTION 2 : PAGINATION -->
<apex:panelGrid columns="2" style="font-weight: bold;" id="pgtable3">
<apex:commandLink action="{!previousAL}" rerender="Leadtable3,pgtable3" immediate="true" status="Loading3"><font color="blue">Previous</font></apex:commandLink>
<apex:commandLink action="{!nextAL}" rerender="Leadtable3,pgtable3" immediate="true" status="Loading3"><font color="blue">Next</font></apex:commandLink>
<apex:outputText value="Page {!pageNumberAL} of {!pagesAL} " />
</apex:panelGrid>
<apex:actionStatus id="Loading3" >
<apex:facet name="start" ><font color="red">Loading the data, please wait....</font></apex:facet>
<apex:facet name="stop"><font color="blue">Data Loaded ,Thanks for patience!</font></apex:facet>
</apex:actionStatus>
</apex:pageBlocksection>
<!-- LEAD SECTION 3 : QUALIFIED LEADS -->
<apex:pageBlocksection title="Qualified Stuck leads – in qualified status for more than 30 days ({!$Label.Record_Count}: {!NoOfEntriesFoundQL}). Review to see if it can be converted to an opportunity or if it should be closed" id="LeadBlock4" collapsible="false" columns="1" rendered="{!IF(QualifiedLeads.SIZE>0, 'true', 'false')}">
<apex:pageBlockTable value="{!QualifiedLeads}" var="lead" id="Leadtable4" style="width:100%">
<apex:column headerValue="Name">
<apex:outputlink value="/{!lead.Id}" >
<!-- <apex:param name="leadId" value="{!lead.Id}"/> -->
{!lead.Name}
</apex:outputlink>
</apex:column>
<apex:column headerValue="Company" value="{!lead.Company}"/>
<apex:column headerValue="Lead Source" value="{!lead.LeadSource}"/>
<apex:column headerValue="Lead Source Details" value="{!lead.Lead_Source_Details_del__c}"/>
<apex:column headerValue="Created Date " value="{!lead.CreatedDate}"/>
<apex:column headerValue="Accepted Date " value="{!lead.Accepted_Date__c}"/>
<apex:column headerValue="Days Stuck" value="{!lead.Untouched_Duration__c}"/>
<apex:column headerValue="Owner Name" value="{!lead.Owner.Name}" rendered="{!IF(ownername, 'true', 'false')}"/>
</apex:pageBlockTable>
<!-- LEAD SECTION 3 : PAGINATION -->
<apex:panelGrid columns="2" style="font-weight: bold;" id="pgtable4">
<apex:commandLink action="{!previousQL}" rerender="Leadtable4,pgtable4" immediate="true" status="Loading"><font color="blue">Previous</font></apex:commandLink>
<apex:commandLink action="{!nextQL}" rerender="Leadtable4,pgtable4" immediate="true" status="Loading"><font color="blue">Next</font></apex:commandLink>
<apex:outputText value="Page {!pageNumberQL} of {!pagesQL}" />
</apex:panelGrid>
<apex:actionStatus id="Loading" >
<apex:facet name="start" ><font color="red">Loading the data, please wait....</font></apex:facet>
<apex:facet name="stop"><font color="blue">Data Loaded ,Thanks for patience!</font></apex:facet>
</apex:actionStatus>
</apex:pageBlocksection>
<!-- *********************** LEAD SECTION THREE ENDS ************************************************************************ -->
</apex:pageBlock>
<apex:pageBlock title="{!$Label.OpportunitiesRequiringAttention}" rendered="{!IF(Oppsclosepast.SIZE==0 , 'false', 'true')}">
<!-- *********************** SECTION ONE : Opportunities_with_close_dates_in_the_past ************************************************************************ -->
<apex:pageBlocksection title="{!$Label.Opportunities_with_close_dates_in_the_past} ({!$Label.Record_Count}: {!NoOfEntriesFoundCPO}). Update the close date or close it" id="OppBlock2" collapsible="false" columns="1" rendered="{!IF(Oppsclosepast.SIZE>0, 'true', 'false')}">
<apex:pageBlockTable title="{!$Label.Opportunities_with_close_dates_in_the_past}" value="{!Oppsclosepast}" var="opp" id="table2" style="width:100%" >
<apex:column headerValue="Opportunity Name">
<apex:outputlink value="/{!opp.Id}">
<!-- <apex:param name="oppId" value="{!opp.Id}"/> -->
{!opp.Name}
</apex:outputlink>
</apex:column>
<apex:column headerValue="Account Name" value="{!opp.Account.Name}"/>
<apex:column headerValue="Stage" value="{!opp.StageName}"/>
<apex:column headerValue="Amount" value="{!opp.Amount}"/>
<apex:column headerValue="Estimated Close Date" value="{!opp.CloseDate}"/>
<apex:column headerValue="Days Past Estimated Close Date" value="{!opp.Age__c}"/>
<apex:column headerValue="Owner Name" value="{!opp.Owner.Name}" rendered="{!IF(ownername, 'true', 'false')}"/>
</apex:pageBlockTable>
<!-- OPPORTUNITY SECTION 1 : PAGINATION -->
<apex:panelGrid columns="2" style="font-weight: bold;" id="OppPgtable2">
<apex:commandLink action="{!previousCPO}" rerender="table2,OppPgtable2" immediate="true" status="LoadingOpp2"><font color="blue">Previous</font></apex:commandLink>
<apex:commandLink action="{!nextCPO}" rerender="table2,OppPgtable2" immediate="true" status="LoadingOpp2"><font color="blue">Next</font></apex:commandLink>
<apex:outputText value="Page {!pageNumberCPO} of {!pagesCPO} " />
</apex:panelGrid>
<apex:actionStatus id="LoadingOpp2" >
<apex:facet name="start" ><font color="red">Loading the data, please wait....</font></apex:facet>
<apex:facet name="stop"><font color="blue">Data Loaded ,Thanks for patience!</font></apex:facet>
</apex:actionStatus>
</apex:pageBlocksection>
<!-- *********************** EMPTY SECTION ************************************************************************ -->
<apex:pageBlock title="{!$Label.No_Records_to_Display}" rendered="{!IF( AcceptedLeads.SIZE==0 && UnacceptedLeads.SIZE==0 && QualifiedLeads.SIZE==0 && Oppsclosepast.SIZE == 0 && Oppsclosein30days.SIZE == 0 && Opps.SIZE == 0 && Oppswithoutcontacts.SIZE == 0 && OppsSameStage60days.SIZE == 0 && OppswithoutTask.SIZE == 0 && OppsByStage.SIZE == 0 && OppsInactiveOwners.SIZE == 0, 'true', 'false')}">
<style type="text/css">
p { color: #f65; font-weight: bold; }
</style>
<p>{!$Label.Great_job_There_are_no_records_that_need_your_attention_today}</p>
</apex:pageBlock>
</apex:form>
<!-- ********* To include task functionality with old implementation **** <apex:include pageName="ViewMyAttentionTask"/> -->
Controller :
public class AttentionController {
public boolean ownername{get;set;}
static Set<String> UserIdsSet= new Set<String>();
public List<Lead> leadResult{get;set;}
public List<Opportunity> oppResult{get;set;}
static Set<String> UserIdsSetInActive= new Set<String>();
/******** Constructor **************/
public AttentionController(){
UserIdInfo();
UserIdInfoInactive();
}
/***************Comman methods starts **************************************************/
/*
Method Name : UserIdInfo()
Usage : FOR GMS profiles there is criteria for User type and Region used to filter Query
Component : Custom Settings : Sales_Representative__c
Field : Manager2.
Migration details : Migrated custom settings and Manager2 feild data as well.
*/
public void UserIdInfo()
{
if(UserIdsSet.size() == 0) {
Map <String,Sales_Representative__c> allSalesRep =Sales_Representative__c.getall();
if(!allSalesRep.containsKey(UserInfo.getProfileId()))
{
String userId =UserInfo.getUserId();
String UserIds ;// FOR GMS profiles there is criteria for User type and Region so filtering Query
if(UserInfo.getProfileId() == '00e80000001C7XOAA0'){
UserIds = 'Select Id From User where Manager2__c=\''+userId+'\' AND IsActive=True AND Region__c = \'EMEA\' AND UserType =\'Outside Sales Rep\' ';
} else if (UserInfo.getProfileId()== '00e80000001C7XMAA0') {
UserIds = 'Select Id From User where Manager2__c=\''+userId+'\' AND IsActive=True AND Region__c = \'EMEA\' AND UserType =\'Outside Sales Manager\' ';
}
else{
UserIds = 'Select Id From User where Manager2__c=\''+userId+'\' AND IsActive=True';
}
System.debug('-----------<><><><>< UserIds ' +UserIds);
List<User> UserIdsList= Database.query(UserIds);
System.debug('UserIdsList****-------:'+UserIdsList.Size());
UserIdsSet.add(userId);
for(User ur: UserIdsList){
UserIdsSet.add(ur.Id);
ownername=true;
}
}
else{
UserIdsSet.add(UserInfo.getUserId());
ownername=false;
}
System.debug('UserIdsSet****-------:'+UserIdsSet.Size());
System.debug(UserIdsSet);
}
}
/*
Method Name : UserIdInfoInactive()
Usage :This method returns all inactive users satisfing below criteria
FOR GMS profiles there is criteria for User type and Region used to filter Query
Component : Custom Settings : Sales_Representative__c
Field : Manager2.
Migration details : Migrated custom settings and Manager2 feild data as well.
*/
public void UserIdInfoInactive()
{
if(UserIdsSetInActive.size() == 0) {
Map <String,Sales_Representative__c> allSalesRep =Sales_Representative__c.getall();
if(!allSalesRep.containsKey(UserInfo.getProfileId()))
{
String userId =UserInfo.getUserId();
String UserIds ;// FOR GMS profiles there is criteria for User type and Region so filtering Query
if(UserInfo.getProfileId() == '00e80000001C7XOAA0'){
UserIds = 'Select Id From User where Manager2__c=\''+userId+'\' AND Region__c = \'EMEA\' AND UserType =\'Outside Sales Rep\' ';
} else if (UserInfo.getProfileId()== '00e80000001C7XMAA0') {
UserIds = 'Select Id From User where Manager2__c=\''+userId+'\' AND Region__c = \'EMEA\' AND UserType =\'Outside Sales Manager\' ';
}
else{
UserIds = 'Select Id From User where Manager2__c=\''+userId+'\' ' ;
}
System.debug('-----------<><><><>< UserIds ' +UserIds);
List<User> UserIdsList= Database.query(UserIds);
System.debug('UserIdsList****-------:'+UserIdsList.Size());
for(User ur: UserIdsList){
UserIdsSetInActive.add(ur.Id);
ownername=true;
}
UserIdsSetInActive.add(userId);
}
else{
UserIdsSetInActive.add(UserInfo.getUserId());
ownername=false;
}
System.debug('UserIdsSetInActive****-------:'+UserIdsSetInActive.Size());
}
}
/*
Method Name : getCommaSeperatedStringList()
Usage : Convert Set to comma seprated string.
*/
public static String getCommaSeperatedStringList(Set<String> stringSet) {
String commaSeperatedString = '';
if(stringSet != null && stringSet.size() > 0) {
commaSeperatedString += '(';
Boolean isFirstValue = true;
for (String value : stringSet) {
if(isFirstValue) {
commaSeperatedString += '\'' + String.escapeSingleQuotes(value) + '\'';
isFirstValue = false;
} else {
commaSeperatedString += ', \'' + String.escapeSingleQuotes(value) + '\'';
}
}
commaSeperatedString += ')';
}
return commaSeperatedString;
}
/*********************** Unaccepted Leads Section 1 In VF****************************************/
public ApexPages.StandardSetController setConUnacceptedLeads {
get {
String queryUnacceptedLeads = '';
if(setConUnacceptedLeads == null) {
if(UserIdsSet.Size()>0){
queryUnacceptedLeads = 'SELECT Name, CreatedDate ,Company,LeadSource, Lead_Source_Details_del__c,Owner.Name, Days_Open_Unaccepted_leads__c FROM Lead WHERE Sales_Accepted__c = FALSE AND Status IN (\'Contacting\',\'New\',\'Qualified\') AND OwnerId IN '+getCommaSeperatedStringList(UserIdsSet) + 'ORDER BY Days_Open_Unaccepted_leads__c DESC LIMIT 200 ' ;
List<Lead> leadResult = Database.query(queryUnacceptedLeads);
setConUnacceptedLeads = new ApexPages.StandardSetController(leadResult);
setConUnacceptedLeads.setPageSize(5);
}
}
return setConUnacceptedLeads;
}
set;
}
// Initialize setConUnacceptedLeads and return a list of records
public List<Lead> getUnacceptedLeads() {
List<Lead> temp = new List<Lead>();
if(setConUnacceptedLeads != null)
return (List<Lead>) setConUnacceptedLeads.getRecords();
else
/** Temporary Fix ***/
return temp;
}
/********** Pagination Methods ***********************/
public Integer pageNumber{
get {
return setConUnacceptedLeads.getPageNumber();
}
set;
}
public PageReference next() {
Integer p = setConUnacceptedLeads.getPageNumber();
if(hasNext) {
setConUnacceptedLeads.setPageNumber(p+1);
}
return null;
}
public Integer getNoOfEntriesFound() {
Integer num = setConUnacceptedLeads.getResultSize();
return num ;
}
public PageReference previous() {
Integer p = setConUnacceptedLeads.getPageNumber();
if(hasPrevious) {
setConUnacceptedLeads.setPageNumber(p-1);
}
return null;
}
public Boolean hasPrevious {
get {
return setConUnacceptedLeads.getHasPrevious();
}
}
public Boolean hasNext {
get {
return setConUnacceptedLeads.getHasNext();
}
}
public Integer pages
{
get{
pages = setConUnacceptedLeads.getResultSize()/setConUnacceptedLeads.getPageSize();
system.debug('>>>>>>' + pages);
if(math.mod(setConUnacceptedLeads.getResultSize(),5) == 0)
return (pages);
else
return (pages+1);
}
set;
}
/*********************************** End UnAccepted Leads : Section One Ends**********************************/
/********************************** Accepted Leads Section2 In VF *****************************/
public ApexPages.StandardSetController setConAcceptedLeads {
get {
String queryAcceptedLeads = '';
if(setConAcceptedLeads == null) {
if(UserIdsSet.Size()>0){
queryAcceptedLeads = 'SELECT Name, CreatedDate ,Company,LeadSource, Lead_Source_Details_del__c, Owner.Name,Days_Since_Accept__c,Accepted_Date__c,Untouched_Duration__c,Days_Since_Accepted__c FROM Lead WHERE Sales_Accepted__c=True AND Status IN (\'Contacting\',\'New\') AND Days_Since_Accepted__c > 7 AND OwnerId IN '+getCommaSeperatedStringList(UserIdsSet)+' ORDER BY Untouched_Duration__c DESC ';
leadResult = Database.query(queryAcceptedLeads);
setConAcceptedLeads = new ApexPages.StandardSetController(leadResult);
setConAcceptedLeads.setPageSize(5);
}
}
return setConAcceptedLeads;
}
set;
}
public List<Lead> getAcceptedLeads() {
List<Lead> temp = new List<Lead>();
if(setConAcceptedLeads != null)
return (List<Lead>) setConAcceptedLeads.getRecords();
else
/** Temporary Fix **/
return temp;
}
/********** Pagination Methods ***********************/
public Integer pageNumberAL{
get {
return setConAcceptedLeads.getPageNumber();
}
set;
}
public PageReference nextAL() {
Integer p = setConAcceptedLeads.getPageNumber();
if(hasNextAL) {
setConAcceptedLeads.setPageNumber(p+1);
}
return null;
}
public Integer getNoOfEntriesFoundAL() {
Integer num = setConAcceptedLeads.getResultSize();
return num ;
}
public PageReference previousAL() {
Integer p = setConAcceptedLeads.getPageNumber();
if(hasPreviousAL) {
setConAcceptedLeads.setPageNumber(p-1);
}
return null;
}
public Boolean hasPreviousAL {
get {
return setConAcceptedLeads.getHasPrevious();
}
}
public Boolean hasNextAL {
get {
return setConAcceptedLeads.getHasNext();
}
}
public Integer pagesAL{
get{
pagesAL = setConAcceptedLeads.getResultSize()/setConAcceptedLeads.getPageSize();
if(math.mod(setConAcceptedLeads.getResultSize(),5) == 0)
return (pagesAL);
else
return (pagesAL+1);
}
set;
}
/*********************** Qualified Leads Section 3 In VF****************************************/
public ApexPages.StandardSetController setConQualifiedLeads {
get {
String queryQualifiedLeads = '';
if(setConQualifiedLeads == null) {
if(UserIdsSet.Size()>0){
queryQualifiedLeads = 'SELECT Name, CreatedDate ,Company,LeadSource, Lead_Source_Details_del__c, Owner.Name,Days_Stuck__c ,Untouched_Duration__c,Accepted_Date__c FROM Lead WHERE Status = \'Qualified\' AND Untouched_Duration__c >= 30 AND OwnerId IN '+getCommaSeperatedStringList(UserIdsSet)+' ORDER BY Untouched_Duration__c DESC LIMIT 200';
List<Lead> leadResult = Database.query(queryQualifiedLeads);
setConQualifiedLeads = new ApexPages.StandardSetController(leadResult);
setConQualifiedLeads.setPageSize(5);
}
}
return setConQualifiedLeads;
}
set;
}
public List<Lead> getQualifiedLeads() {
List<Lead> temp = new List<Lead>();
if(setConQualifiedLeads != null)
return (List<Lead>) setConQualifiedLeads.getRecords();
else
/** Temporary Fix ***/
return temp;
}
/********** Pagination Methods ***********************/
public Integer pageNumberQL{
get {
return setConQualifiedLeads.getPageNumber();
}
set;
}
public PageReference nextQL() {
Integer p = setConQualifiedLeads.getPageNumber();
if(hasNextQL) {
setConQualifiedLeads.setPageNumber(p+1);
}
return null;
}
public Integer getNoOfEntriesFoundQL() {
Integer num = setConQualifiedLeads.getResultSize();
return num ;
}
public PageReference previousQL() {
Integer p = setConQualifiedLeads.getPageNumber();
if(hasPreviousQL) {
setConQualifiedLeads.setPageNumber(p-1);
}
return null;
}
public Boolean hasPreviousQL {
get {
return setConQualifiedLeads.getHasPrevious();
}
}
public Boolean hasNextQL {
get {
return setConQualifiedLeads.getHasNext();
}
}
public Integer pagesQL
{
get{
pagesQL = setConQualifiedLeads.getResultSize()/setConQualifiedLeads.getPageSize();
system.debug('>>>>>>' + pagesQL);
if(math.mod(setConQualifiedLeads.getResultSize(),5) == 0)
return (pagesQL);
else
return (pagesQL+1);
}
set;
}
/*********************************** End Qualified Leads : Section One Ends**********************************/
}//End of class
Best Answer
You can try to call actionFunction sequentially after the section is loaded, something like:
Class:
Page: