-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
3Questions
-
2Replies
Creating a Dynamic Search bar for a table exceeding 1000 records.
I have had multiple issues creating a dynamic search bar(searching more than one field) that will allow me to search a table over 1000 records. I'm beginning to wonder if it is even possible or no matter what is Salesforce going to give me that error. This is what I have right now in my controller:
public with sharing class modemSearchController {
private String soql {get;set;}
public List<Modem__c> modemz {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to name
public String sortField {
get { if (sortField == null) {sortField = 'Name'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1500'; }
set;
}
// init the controller and display some sample data when the page loads
public modemSearchController() {
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
runQuery();
}
public PageReference create()
{
return Page.modemCreate;
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
modemz = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1000');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'I cant seem to find that record!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String name = Apexpages.currentPage().getParameters().get('name');
String IP = Apexpages.currentPage().getParameters().get('IP');
String ICCID = Apexpages.currentPage().getParameters().get('ICCID');
String carrier = Apexpages.currentPage().getParameters().get('carrier');
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
if (!name.equals(''))
soql += ' and Name LIKE \''+String.escapeSingleQuotes(name)+'%';
if (!IP.equals(''))
soql += ' and ModemIPEXT__c LIKE \''+String.escapeSingleQuotes(IP)+'%';
if (!ICCID.equals(''))
soql += ' and ModemICCID__c LIKE \''+String.escapeSingleQuotes(ICCID)+'%';
if (!carrier.equals(''))
soql += ' and ModemCarrier__c includes \"(+carrier+)';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> carriers {
get {
if (carriers == null) {
carriers = new List<String>();
Schema.DescribeFieldResult field = Modem__c.ModemCarrier__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
carriers.add(f.getLabel());
}
return carriers;
}
set;
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, ModemManufacturer__c, ModemModel__c, ModemICCID__c, ModemIPEXT__c, ModemCarrier__c, ModemActive__c FROM Modem__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Modem__c> getModem()
{
List<Modem__c> modemList = new List<Modem__c>();
for(Modem__c m : (List<Modem__c>)setCon.getRecords())
modemList.add(m);
return modemList;
}
public PageReference refresh() {
setCon = null;
getModem();
setCon.setPageNumber(1);
return null;
}
public Boolean hasNext
{
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious
{
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber
{
get {
return setCon.getPageNumber();
}
set;
}
public void first()
{
setCon.first();
}
public void last()
{
setCon.last();
}
public void previous()
{
setCon.previous();
}
public void next()
{
setCon.next();
}
}
My biggest issue here is 1. It will not allow me to display over 1000 records and I couldnt find a work around. and 2. It will not perform the search within the data, it comes up with an error and displays that it is finding Querying correct at the bottom but it will not actually display the records related to what is being searched.
public with sharing class modemSearchController {
private String soql {get;set;}
public List<Modem__c> modemz {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to name
public String sortField {
get { if (sortField == null) {sortField = 'Name'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1500'; }
set;
}
// init the controller and display some sample data when the page loads
public modemSearchController() {
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
runQuery();
}
public PageReference create()
{
return Page.modemCreate;
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
modemz = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1000');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'I cant seem to find that record!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String name = Apexpages.currentPage().getParameters().get('name');
String IP = Apexpages.currentPage().getParameters().get('IP');
String ICCID = Apexpages.currentPage().getParameters().get('ICCID');
String carrier = Apexpages.currentPage().getParameters().get('carrier');
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
if (!name.equals(''))
soql += ' and Name LIKE \''+String.escapeSingleQuotes(name)+'%';
if (!IP.equals(''))
soql += ' and ModemIPEXT__c LIKE \''+String.escapeSingleQuotes(IP)+'%';
if (!ICCID.equals(''))
soql += ' and ModemICCID__c LIKE \''+String.escapeSingleQuotes(ICCID)+'%';
if (!carrier.equals(''))
soql += ' and ModemCarrier__c includes \"(+carrier+)';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> carriers {
get {
if (carriers == null) {
carriers = new List<String>();
Schema.DescribeFieldResult field = Modem__c.ModemCarrier__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
carriers.add(f.getLabel());
}
return carriers;
}
set;
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, ModemManufacturer__c, ModemModel__c, ModemICCID__c, ModemIPEXT__c, ModemCarrier__c, ModemActive__c FROM Modem__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Modem__c> getModem()
{
List<Modem__c> modemList = new List<Modem__c>();
for(Modem__c m : (List<Modem__c>)setCon.getRecords())
modemList.add(m);
return modemList;
}
public PageReference refresh() {
setCon = null;
getModem();
setCon.setPageNumber(1);
return null;
}
public Boolean hasNext
{
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious
{
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber
{
get {
return setCon.getPageNumber();
}
set;
}
public void first()
{
setCon.first();
}
public void last()
{
setCon.last();
}
public void previous()
{
setCon.previous();
}
public void next()
{
setCon.next();
}
}
My biggest issue here is 1. It will not allow me to display over 1000 records and I couldnt find a work around. and 2. It will not perform the search within the data, it comes up with an error and displays that it is finding Querying correct at the bottom but it will not actually display the records related to what is being searched.
- Brendan Dunham
- October 14, 2014
- Like
- 0
VisualForce Page Doesn't Display a List of Records or Any Records BUT it can Display the List Size
**VisualForce** page not displaying a list of records - title says it all.
How do I get the **VF** page to display the records that it is obviously counting (as it says **1-15** of **7549** records).
The non-working page looks like this:
- '*Wells*' page
However, this is what we want it to look like (the one that we currently have working!):
- '*Modems*' page (I blacked out some fields, as the company we work for may not want this information disclosed)
My team is working on a salesforce.com application and we have an object, '*Modem*', that contains approximately **7,500** records.
# **ModemController** #
We have created a custom controller, **ModemController**:
# Custom **VF** page for '*Wells*' page #
Here is the custom **visualforce** page for the '*Wells*' page:
This **controller** works for other tabs, (see the '*Wells*' page, it uses an identical controller and it works!) but does not work for '*Modems*' page.
We see that '*Modems*' page is at least reading in the **7,549** records (by looking at a variable noOfRecords to count how many there are) but not displaying them. I have even tried adding **LIMIT** to the **SOQL** query, to no avail. (limited it to 2,000, 1999, 1001, 1000, 999, and even 30,20, and 10)
I don't think the amount of records is the issue, I could be wrong.
If anyone has any tips, it would be greatly appreciated!
# WellController #
If anyone requests, here is the working code for the '*Wells*' page, both **VisualForce** and **Apex** code:
*WellController*:
# **VF** page - '*Wells*' #
And the **VisualForce** page associated with the '*Wells*' object:
Thanks in advance!
How do I get the **VF** page to display the records that it is obviously counting (as it says **1-15** of **7549** records).
The non-working page looks like this:
- '*Wells*' page
However, this is what we want it to look like (the one that we currently have working!):
- '*Modems*' page (I blacked out some fields, as the company we work for may not want this information disclosed)
My team is working on a salesforce.com application and we have an object, '*Modem*', that contains approximately **7,500** records.
# **ModemController** #
We have created a custom controller, **ModemController**:
public class ModemController { public apexpages.standardsetcontroller con {get;set;} public Integer noOfRecords{get; set;} public Integer size{get; set;} public Modem__c modems {get; set;} public List<Modem__c> AllSearchModems { get { if (con!= null) return (List<Modem__c>)con.getRecords(); else return null; } set; } public ModemController() { AllSearchModems = new List<Modem__c>(); modems = new Modem__c(); String Name = ApexPages.currentPage().getParameters().get('Name'); List<Modem__c> modems = [SELECT Name FROM Modem__c WHERE ID= :Name]; } public PageReference save() { update modems; return new PageReference('/' + modems.Name); } public ApexPages.StandardSetController setCon { get{ if(setCon == null){ size = 15; string queryString = 'SELECT Name, ModemActive__c, ModemCarrier__c, ModemCarrierData__c, DataPlanName__c, ESNNumber__c, ModemICCID__c, IMEINumber__c, IMSINumber__c, ModemIPEXT__c, ModemJob__c, ModemManufacturer__c, ModemModel__c, ModemPhone__c, PortForwarding__c, ModemIPPort__c, SIMNumber__c, ModemIPSlave__c, ModemStaticIP__c, ModemFirmwareVersion__c FROM Modem__c ORDER BY Name'; setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString)); setCon.setPageSize(size); noOfRecords = setCon.getResultSize(); } return setCon; } set; } public List<Modem__c> getModems() { List<Modem__c> modemList = new List<Modem__c>(); for(Modem__c w : (List<Modem__c>)setCon.getRecords()) modemList.add(w); return modemList; } public PageReference refresh() { setCon = null; getModems(); setCon.setPageNumber(1); return null; } public PageReference Search() { if (modems.Name != null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, ModemActive__c,ModemCarrier__c,ModemCarrierData__c,DataPlanName__c,ESNNumber__c,ModemICCID__c, IMEINumber__c,IMSINumber__c,ModemIPEXT__c,ModemJob__c, ModemManufacturer__c,ModemModel__c,ModemPhone__c, PortForwarding__c, ModemIPPort__c,SIMNumber__c,ModemIPSlave__c,ModemStaticIP__c, ModemFirmwareVersion__c FROM Modem__c Modem__c WHERE Name= :modems.Name])); con.setPageSize(10); } else { con = null; } return null; } public Boolean hasNext { get { return setCon.getHasNext(); } set; } public Boolean hasPrevious { get { return setCon.getHasPrevious(); } set; } public Integer pageNumber { get { return setCon.getPageNumber(); } set; } public void first() { setCon.first(); } public void last() { setCon.last(); } public void previous() { setCon.previous(); } public void next() { setCon.next(); } }
# Custom **VF** page for '*Wells*' page #
Here is the custom **visualforce** page for the '*Wells*' page:
<apex:page controller="ModemController"> <apex:form > <apex:pageBlock id="pb"> <apex:pageBlockTable value="{!Modems}" var="m"> <apex:column value="{!m.Name}" /> <apex:column value="{!m.ModemManufacturer__c}"/> <apex:column value="{!m.ModemModel__c}"/> <apex:column value="{!m.ModemICCID__c}"/> <apex:column value="{!m.ModemIPEXT__c}"/> <apex:column value="{!m.ModemCarrier__c}"/> <apex:column value="{!m.ModemActive__c}"/> </apex:pageBlockTable> <apex:panelGrid columns="7"> <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/> <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/> <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/> <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/> <apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText> <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/> <apex:outputPanel style="color:#4AA02C;font-weight:bold"> <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/> </apex:outputPanel> </apex:panelGrid> </apex:pageBlock> </apex:form> </apex:page>
This **controller** works for other tabs, (see the '*Wells*' page, it uses an identical controller and it works!) but does not work for '*Modems*' page.
We see that '*Modems*' page is at least reading in the **7,549** records (by looking at a variable noOfRecords to count how many there are) but not displaying them. I have even tried adding **LIMIT** to the **SOQL** query, to no avail. (limited it to 2,000, 1999, 1001, 1000, 999, and even 30,20, and 10)
I don't think the amount of records is the issue, I could be wrong.
If anyone has any tips, it would be greatly appreciated!
# WellController #
If anyone requests, here is the working code for the '*Wells*' page, both **VisualForce** and **Apex** code:
*WellController*:
public class WellController { public apexpages.standardsetcontroller con {get;set;} public Integer noOfRecords{get; set;} public Integer size{get; set;} public Well__c wellz {get; set;} public List<Well__c> AllSearchWells { get { if (con!= null) return (List<Well__c>)con.getRecords(); else return null; } set; } public WellController() { AllSearchWells = new List<Well__c>(); wellz = new Well__c(); String Name = ApexPages.currentPage().getParameters().get('Name'); List<Well__c> wellz = [SELECT Name FROM Well__c WHERE ID = :Name]; } public PageReference save() { update wellz; return new PageReference('/' + wellz.Name); } public ApexPages.StandardSetController setCon { get{ if(setCon == null){ size = 15; string queryString = 'SELECT Name, WellLocActivationDate__c, Active__c, AntennaType__c, WellLocBillTo__c, CompanyName__c, CompanyName_del__c, WellLocCompanyName__c, ConnectedCarrier__c, ContactReponsible__c, DataNetwork__c, WellLocSPOCDataPlan__c, WellSiteEquipHistory__c, WellLoclPD__c, WellLocKillDate__c, ModemConnectedTo__c, Name__c, WellLocModemSerial__c, SignalQuality__c, SignalStrength__c, SimCardNumber__c, TechResponsible__c, Action__c, ActionDate__c, WellLocName__c, WellLocOwningCompanyName__c FROM Well__c ORDER BY Name'; setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString)); setCon.setPageSize(size); noOfRecords = setCon.getResultSize(); } return setCon; } set; } public List<Well__c> getWells() { List<Well__c> wellList = new List<Well__c>(); for(Well__c w : (List<Well__c>)setCon.getRecords()) wellList.add(w); return wellList; } public PageReference refresh() { setCon = null; getWells(); setCon.setPageNumber(1); return null; } public PageReference Search() { if (wellz.Name != null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, WellLocActivationDate__c, Active__c, AntennaType__c, WellLocBillTo__c, CompanyName__c, CompanyName_del__c, WellLocCompanyName__c, ConnectedCarrier__c, ContactReponsible__c, DataNetwork__c, WellLocSPOCDataPlan__c, WellSiteEquipHistory__c, WellLoclPD__c, WellLocKillDate__c, ModemConnectedTo__c, Name__c, WellLocModemSerial__c, SignalQuality__c, SignalStrength__c, SimCardNumber__c, TechResponsible__c, Action__c, ActionDate__c, WellLocName__c, WellLocOwningCompanyName__c FROM Well__c Well__c where Name = :wellz.Name])); con.setPageSize(10); } else { con = null; } return null; } public Boolean hasNext { get { return setCon.getHasNext(); } set; } public Boolean hasPrevious { get { return setCon.getHasPrevious(); } set; } public Integer pageNumber { get { return setCon.getPageNumber(); } set; } public PageReference make() { return Page.wellCreate; } public void first() { setCon.first(); } public void last() { setCon.last(); } public void previous() { setCon.previous(); } public void next() { setCon.next(); } }
# **VF** page - '*Wells*' #
And the **VisualForce** page associated with the '*Wells*' object:
<apex:page controller="WellController"> <apex:form > <apex:pageBlock title="Wells" id="pb"> <apex:pageBlockSection > <apex:commandButton action="{!make}" value="Create New"/> </apex:pageBlockSection> <apex:pageBlockTable value="{!Wells}" var="w"> <apex:column headerValue="Well Name"> <apex:outputLink value="/apex/wellEdit?id={!w.id}">{!w.WellLocName__c}</apex:outputLink> </apex:column> <apex:column value="{!w.WellLocModemSerial__c}" /> <apex:column value="{!w.WellLocCompanyName__c}" /> <apex:column value="{!w.WellLocOwningCompanyName__c}" /> <apex:column value="{!w.WellLocBillTo__c}" /> <apex:column value="{!w.Active__c}" /> </apex:pageBlockTable> <apex:panelGrid columns="7"> <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/> <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/> <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/> <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/> <apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText> <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/> <apex:outputPanel style="color:#4AA02C;font-weight:bold"> <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/> </apex:outputPanel> </apex:panelGrid> </apex:pageBlock> </apex:form> </apex:page>
Thanks in advance!
- Brendan Dunham
- October 03, 2014
- Like
- 0
Connecting a hyperlink on a record to an edit VF page
I am working with a database and would like to be able to connect a hyperlink to a custom edit page. Currently my biggest issue is not connecting the hyperlink to an edit page, but having the controller filter through the data and only display the information related to the hyperlink when loading the edit page. To be more specific the hyperlink is just a Name field within the database I have on my main page, once you click on a certain name you would like to edit, it should direct you to the edit page displaying the information only related to the Name hyperlink in which you clicked on. And to restate my problem: I am confused on what to put in the controller or my VF pages to only show the information related to that Name. And to make this more complicated the edit page has to be a custom VF page because I need to be able to add buttons and what not. It cannot be the standard edit page given to you by Salesforce since that cannot be edited with Visualforce. Please help.
- Brendan Dunham
- October 01, 2014
- Like
- 0
Creating a Dynamic Search bar for a table exceeding 1000 records.
I have had multiple issues creating a dynamic search bar(searching more than one field) that will allow me to search a table over 1000 records. I'm beginning to wonder if it is even possible or no matter what is Salesforce going to give me that error. This is what I have right now in my controller:
public with sharing class modemSearchController {
private String soql {get;set;}
public List<Modem__c> modemz {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to name
public String sortField {
get { if (sortField == null) {sortField = 'Name'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1500'; }
set;
}
// init the controller and display some sample data when the page loads
public modemSearchController() {
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
runQuery();
}
public PageReference create()
{
return Page.modemCreate;
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
modemz = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1000');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'I cant seem to find that record!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String name = Apexpages.currentPage().getParameters().get('name');
String IP = Apexpages.currentPage().getParameters().get('IP');
String ICCID = Apexpages.currentPage().getParameters().get('ICCID');
String carrier = Apexpages.currentPage().getParameters().get('carrier');
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
if (!name.equals(''))
soql += ' and Name LIKE \''+String.escapeSingleQuotes(name)+'%';
if (!IP.equals(''))
soql += ' and ModemIPEXT__c LIKE \''+String.escapeSingleQuotes(IP)+'%';
if (!ICCID.equals(''))
soql += ' and ModemICCID__c LIKE \''+String.escapeSingleQuotes(ICCID)+'%';
if (!carrier.equals(''))
soql += ' and ModemCarrier__c includes \"(+carrier+)';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> carriers {
get {
if (carriers == null) {
carriers = new List<String>();
Schema.DescribeFieldResult field = Modem__c.ModemCarrier__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
carriers.add(f.getLabel());
}
return carriers;
}
set;
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, ModemManufacturer__c, ModemModel__c, ModemICCID__c, ModemIPEXT__c, ModemCarrier__c, ModemActive__c FROM Modem__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Modem__c> getModem()
{
List<Modem__c> modemList = new List<Modem__c>();
for(Modem__c m : (List<Modem__c>)setCon.getRecords())
modemList.add(m);
return modemList;
}
public PageReference refresh() {
setCon = null;
getModem();
setCon.setPageNumber(1);
return null;
}
public Boolean hasNext
{
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious
{
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber
{
get {
return setCon.getPageNumber();
}
set;
}
public void first()
{
setCon.first();
}
public void last()
{
setCon.last();
}
public void previous()
{
setCon.previous();
}
public void next()
{
setCon.next();
}
}
My biggest issue here is 1. It will not allow me to display over 1000 records and I couldnt find a work around. and 2. It will not perform the search within the data, it comes up with an error and displays that it is finding Querying correct at the bottom but it will not actually display the records related to what is being searched.
public with sharing class modemSearchController {
private String soql {get;set;}
public List<Modem__c> modemz {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to name
public String sortField {
get { if (sortField == null) {sortField = 'Name'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1500'; }
set;
}
// init the controller and display some sample data when the page loads
public modemSearchController() {
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
runQuery();
}
public PageReference create()
{
return Page.modemCreate;
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
modemz = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 1000');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'I cant seem to find that record!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String name = Apexpages.currentPage().getParameters().get('name');
String IP = Apexpages.currentPage().getParameters().get('IP');
String ICCID = Apexpages.currentPage().getParameters().get('ICCID');
String carrier = Apexpages.currentPage().getParameters().get('carrier');
soql = 'select Name, ModemIPEXT__c, ModemICCID__c, ModemCarrier__c, ModemActive__c from Modem__c';
if (!name.equals(''))
soql += ' and Name LIKE \''+String.escapeSingleQuotes(name)+'%';
if (!IP.equals(''))
soql += ' and ModemIPEXT__c LIKE \''+String.escapeSingleQuotes(IP)+'%';
if (!ICCID.equals(''))
soql += ' and ModemICCID__c LIKE \''+String.escapeSingleQuotes(ICCID)+'%';
if (!carrier.equals(''))
soql += ' and ModemCarrier__c includes \"(+carrier+)';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> carriers {
get {
if (carriers == null) {
carriers = new List<String>();
Schema.DescribeFieldResult field = Modem__c.ModemCarrier__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
carriers.add(f.getLabel());
}
return carriers;
}
set;
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, ModemManufacturer__c, ModemModel__c, ModemICCID__c, ModemIPEXT__c, ModemCarrier__c, ModemActive__c FROM Modem__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Modem__c> getModem()
{
List<Modem__c> modemList = new List<Modem__c>();
for(Modem__c m : (List<Modem__c>)setCon.getRecords())
modemList.add(m);
return modemList;
}
public PageReference refresh() {
setCon = null;
getModem();
setCon.setPageNumber(1);
return null;
}
public Boolean hasNext
{
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious
{
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber
{
get {
return setCon.getPageNumber();
}
set;
}
public void first()
{
setCon.first();
}
public void last()
{
setCon.last();
}
public void previous()
{
setCon.previous();
}
public void next()
{
setCon.next();
}
}
My biggest issue here is 1. It will not allow me to display over 1000 records and I couldnt find a work around. and 2. It will not perform the search within the data, it comes up with an error and displays that it is finding Querying correct at the bottom but it will not actually display the records related to what is being searched.
- Brendan Dunham
- October 14, 2014
- Like
- 0
Connecting a hyperlink on a record to an edit VF page
I am working with a database and would like to be able to connect a hyperlink to a custom edit page. Currently my biggest issue is not connecting the hyperlink to an edit page, but having the controller filter through the data and only display the information related to the hyperlink when loading the edit page. To be more specific the hyperlink is just a Name field within the database I have on my main page, once you click on a certain name you would like to edit, it should direct you to the edit page displaying the information only related to the Name hyperlink in which you clicked on. And to restate my problem: I am confused on what to put in the controller or my VF pages to only show the information related to that Name. And to make this more complicated the edit page has to be a custom VF page because I need to be able to add buttons and what not. It cannot be the standard edit page given to you by Salesforce since that cannot be edited with Visualforce. Please help.
- Brendan Dunham
- October 01, 2014
- Like
- 0