function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
milind_devmilind_dev 

problem in creating batch apex class...

hi,

    in my issue i have 4 objects.

    1-County

    2-County Assignment

    3-Lead Program

    4- Dealer

 

    County Assignment has a lookup fields for all other 3 objects.... Now  i have created a visualforce page and its controller class. in          this i am fetching County Assignment records based on the selection of Lead Program and County..and add it to Dealer's related list... its working fine.. now i want to fetch more than 50 million records... so i have to use batch apex class.. but i have seen somewhere that batch apex class can't intract with visualforce page.. so what should i do ...???

 

can any one give me the sample code for this...

 

Thanks in advance

Milind

 

MagulanDuraipandianMagulanDuraipandian

Go with wrapper class...

 

http://infallibletechie.blogspot.in/2012/10/collection-size-maximum-size-of-1000.html

 

Check this site for example

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

SFDC Blog

If this post is your solution, kindly mark this as the solution.

amidstcloudamidstcloud

Make a batchclass with certain Variable in it . . . Call that batch from you controller and in the Contructor of the batch class pass all the values and then intialize the batch class valirbale . . 

 

If you need a sample code . please post your code for page and Controller . . 

 

Thanks 

Ankit

milind_devmilind_dev

thanks Ankit Khandelwal and Magulan D  for replying..  Below is my visualforce page and controller class..

 

 

VF page--

 

<apex:page standardcontroller="Location__c" extensions="extAddCountyAssignment">
<apex:form >
<apex:sectionHeader title="Add County Assignments" subtitle="{!Location__c.Name}" />
<style>
.requiredLegend {display:none;}
</style>

<apex:pageBlock id="thePage" mode="edit">
<apex:pageMessages id="msgs" />
<apex:facet name="header">
<apex:panelGrid columns="2" columnClasses="pbTitle,pbButton">
<h2 class="mainTitle">Add County Assignments to Dealer</h2>
<apex:actionstatus id="loadingItems">
<apex:facet name="start">
<apex:outputPanel layout="block" styleclass="loadingMessage">
<img width="16" height="16" title="Processing..." alt="Processing..." src="/img/loading.gif" />
<apex:outputPanel styleclass="loadingText">Loading...</apex:outputPanel>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:panelGrid>
</apex:facet>
<apex:facet name="footer">
<apex:panelGrid columns="2" columnClasses="pbTitle,pbButton">
<h2 class="mainTitle">&nbsp;</h2>
<apex:panelGroup >
<apex:commandButton value=" Add " action="{!addCA}" disabled="{!NOT(AND(NOT(ISNULL(CAList)),(CAList.size > 0)))}" />
<apex:commandButton value=" Done " action="{!cancel}" />
</apex:panelGroup>
</apex:panelGrid>
</apex:facet>
<apex:pageblocksection columns="1" title="Filter Options" collapsible="false">
<apex:panelGrid columns="9">
<apex:outputLabel value="Lead Program:" style="font-weight:bold;" />
<apex:selectList value="{!selectedLeadProgram}" size="1">
<apex:selectOptions value="{!LeadPrograms}" />
</apex:selectList>

<apex:outputLabel value="State:" style="font-weight:bold;" />
<apex:selectList value="{!selectedState}" size="1">
<apex:selectOptions value="{!States}"/>
<apex:actionSupport event="onchange" rerender="county" status="loadingItems" />
</apex:selectList>

<apex:outputLabel value="County:" style="font-weight:bold;" />
<apex:selectList value="{!selectedCounty}" size="1" id="county">
<apex:selectOptions value="{!Counties}" />
</apex:selectList>

<apex:outputLabel value="Slot:" style="font-weight:bold;" />
<apex:inputText value="{!slot}" id="slot" />

<apex:commandbutton value="Search" action="{!RefreshDataSet}" rerender="thePage" status="loadingItems" />
</apex:panelGrid>
</apex:pageblocksection>
<apex:pageblocksection title="Search Result [{!CALIST.size}]" collapsible="false" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Notification Contact" rendered="{!AND(NOT(ISNULL(CAList)),(CAList.size > 0))}"/>
<apex:inputField value="{!ProxyDealer.Contact_2__c}" rendered="{!AND(NOT(ISNULL(CAList)),(CAList.size > 0))}" />
</apex:pageBlockSectionItem>
</apex:pageblocksection>

<c:GridView gridID="tableGridView"
objectRecords="{!CALIST}"
value="{!selVal}"
rowNum="10"
skinName="overcast"
searchOnColumns="true"
multiSelect="true"
columns="Id,Name,County__c,County__r.Name,State__c,Lead_Program__c,Lead_Program__r.Name,Lead_Program__r.Type__c,Slot__c"
colNames="'ID','County Name','','County','State','','Lead Program','Type','Slot'"
colModel="
{
name:'Id',
index:'Id',
sortable:false,
hidden:true,
search:false,
key:true
},
{
name:'Name',
name:'Name',
width:250,
isLink:true,
linkValue:'Id',
formatter:LinkFormatter
},
{
name:'County__c',
name:'County__c',
width:200,
hidden:true
},
{
name:'County__r.Name',
name:'County__r.Name',
width:200,
isLink:true,
linkValue:'County__c',
formatter:LinkFormatter,
},
{
name:'State__c',
name:'State__c',
width:50
},
{
name:'Lead_Program__c',
name:'Lead_Program__c',
width:200,
hidden:true
},
{
name:'Lead_Program__r.Name',
name:'Lead_Program__r.Name',
width:200,
isLink:true,
linkValue:'Lead_Program__c',
formatter:LinkFormatter,
},
{
name:'Lead_Program__r.Type__c',
name:'Lead_Program__r.Type__c',
width:100
},
{
name:'Slot__c',
name:'Slot__c',
width:50
}
"
/>
</apex:pageBlock>

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

 

 

 

 

 

 

Controller Class--

 

public with sharing class extAddCountyAssignment {

private Boolean isTest { get;set; }
public String slot {get; set;}
private ApexPages.Standardcontroller con;
private Location__c dealer;
public extAddCountyAssignment (ApexPages.Standardcontroller controller) {
con = controller;
dealer = (Location__c) con.getRecord();
isTest = false;
selVal = '';
selectedLeadProgram = '';
selectedState = '';
selectedCounty = '';
ProxyDealer = new Location__c();
countiesList = new List<County_Assignment__c>();
}
public Location__c ProxyDealer { get;set; }
public String selectedLeadProgram { get;set; }
public String selectedState { get;set; }
public String selectedCounty { get;set; }

public List<SelectOption> getLeadPrograms() {
List<SelectOption> items = new List<SelectOption>();
items.add(new SelectOption('',' - Select -'));
Lead_Programs__c[] lp;
if (isTest)
lp = [Select ID, Name From Lead_Programs__c Where Inactive__c = false Order By Name limit 5];
else
lp = [Select ID, Name From Lead_Programs__c Order By Name];
for (Lead_Programs__c c : lp)
{
items.add(new SelectOption(c.ID, c.Name));
}
return items;
}
public List<SelectOption> getStates() {
List<SelectOption> items = new List<SelectOption>();
items.add(new SelectOption('',' - Select -'));
State__c[] st;
if (isTest)
st = [Select ID, Name From State__c Order By Name limit 5];
else
st = [Select ID, Name From State__c Order By Name];
for (State__c c : st)
{
items.add(new SelectOption(c.ID, c.Name));
}
return items;
}
public List<SelectOption> getCounties() {
List<SelectOption> items = new List<SelectOption>();
items.add(new SelectOption('',' - Select -'));
County__c[] st;
if (isTest)
st = [Select ID, Name From County__c Order By Name limit 5];
else
st = [Select ID, Name From County__c Where State__c =: selectedState Order By Name];
for (County__c c : st)
{
items.add(new SelectOption(c.ID, c.Name));
}
return items;
}
public PageReference RefreshDataSet() {
if ((selectedLeadProgram == null || selectedLeadProgram == '') && (selectedState == null || selectedState == '')) {
Log.Message('Please select Lead Program or State.');
return null;
}

String qry = 'Select ID, Name,County__c,County__r.Name,Dealer__c,Dealer_2__c,Dealer_3__c,Lead_Program__c,Lead_Program__r.Name,Lead_Program__r.Inactive__c,State__c,Slot__c,Lead_Program__r.Lead_Source__c,Lead_Program__r.Type__c From County_Assignment__c ';
qry += 'Where (Dealer__c = null Or Dealer_2__c = null Or Dealer_3__c = null) And (Lead_Program__r.Inactive__c = false) ';

if (selectedLeadProgram != null && selectedLeadProgram != '') {
qry += 'And Lead_Program__c = \''+selectedLeadProgram+'\' ';
}
if (selectedState != null && selectedState != '') {
qry += 'And County__r.State__c = \''+selectedState+'\' ';
}
if (selectedCounty != null && selectedCounty != '') {
qry += 'And County__c = \''+selectedCounty+'\' ';
}

if (slot != null && slot != '') {
qry += 'And Slot__c = '+ slot;
}

qry += ' Order By State__c, County__c, Lead_Program__r.Lead_Source__c,Lead_Program__r.Type__c, Slot__c ';

//Log.Message('Query : '+qry);
if (isTest)
qry += 'limit 10';
else
qry += 'limit 40000';
countiesList = database.query(qry);
if (countiesList.size() >= 40000)
Log.Message('The number of records reached a preset limit, please use Filter Options to filter the result set.');
return null;
}
public string selVal { get;set; }
private list<County_Assignment__c> countiesList;
public List<County_Assignment__c> getCAList() {
if (countiesList.size() > 0)
return countiesList;
return null;
}
private Integer SelectDealerIndex(County_Assignment__c ca)
{
if (ca.Dealer__c == null)
return 1;
if (ca.Dealer_2__c == null)
return 2;
if (ca.Dealer_3__c == null)
return 3;
return -1;
}
public PageReference AddCA() {
if (selVal == null || selVal == '') {
Log.Message('Select at least one record.');
return null;
}
set<String> selValIDs = new set<String>();
for (String s : selVal.split(','))
selValIDs.add(s);
County_Assignment__c[] items = new County_Assignment__c[] {};
for (County_Assignment__c CA : [Select Id,Dealer__c,Dealer_2__c,Dealer_3__c From County_Assignment__c Where ID IN: selValIDs])
{
//log.Message(CA+'');
Integer ind = SelectDealerIndex(CA);
if (ind == 1)
CA.Dealer__c = con.getId();
if (ind == 2)
CA.Dealer_2__c = con.getId();
if (ind == 3)
CA.Dealer_3__c = con.getId();

CA.Notification_Contact__c = ProxyDealer.Contact_2__c;
items.add(CA);
}
try {
update items;
//return con.view();
Log.Message(items.size() + ' County Assignment(s) added successfully.');
}
catch (Exception ex) {
ApexPages.addMessages(ex);
}
return null;
}


}

 

ArunaAruna

Hi,

 

I am also same boat, did get any replay any answers to this problem , if could you please send me the Vf code and controller with batch inner class.

 

please help out meo this . 

milind_devmilind_dev

sorry aruna i am still stuck in this problem...

ArunaAruna

If you find any solution please let me know