• gazazello
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 8
    Replies

hi

 

Here is my visualforce page:

 

 

<apex:page standardController="Contact" extensions="CreditTransactions" >
<apex:form >
 <apex:pageBlock title="Payment Methods" >
<apex:pagemessages />
<apex:pageBlockTable value="{!Results}" var="transaction" title="Payment Methods" >
<apex:inputhidden value="{!transaction.tranId}" id="transactid"/>
  <apex:column headerValue="Date Last Used" value="{!transaction.tDate2}"/> 
    <apex:column headerValue="Last 4 digits" value="{!transaction.cardnum}"/> 
    <apex:column headerValue="Expiration Date" value="{!transaction.cardexp}" id="expired"/> 
  <apex:column >
    <apex:commandButton action="{!Vterminal}" value="Virtual Terminal" reRender="hiddenblock">
               <apex:param name="para" value="{!transaction.tranId}" assignTo="{!para}"></apex:param>
               <apex:param name="expired" value="{!transaction.cardexp}" assignTo="{!expired}"></apex:param>                               </apex:commandButton>
    </apex:column>
   
</apex:pageBlockTable>
 <apex:outputPanel id="hiddenblock">
 </apex:outputPanel>
  </apex:pageBlock>
  </apex:form>
 <apex:detail />
</apex:page>
I have added <apex:pageMessages/> to the page. and here is my code when I click the button.
 public PageReference Vterminal() 
    {
            
    System.debug('expired param valueeee'+expired);
    expmonth = Integer.valueOf(expired.substring(0,2));
    expyear = Integer.valueOf(expired.substring(3,7));
    expmonthdate = Date.newInstance(expyear, expmonth,01 );
    System.debug('expired monthdate valueeee'+expmonthdate);
      p=new PageReference('/apex/VirtualTerminal?id='+para);
    if(expmonthdate>System.Today()){
      
        return p;
        }else{
   
       ApexPages.Message errMsg= new ApexPages.Message(ApexPages.severity.ERROR, 'Card Expired');  
         ApexPages.addMessage(errMsg);
        }
        return null;
    }
In the debug logs error message is displaying but in the visual force page it is not showing.
Please help.

 

Hi All,

 

I want to select records where the any of the values of two multi-selects match.

 

I am using includes which I think is the only way, but unless both multi-selects match, it doesn't return any values.

 

Any ideas?

 

Thanks

 

 

 

 

List<Account> fromLead = [select Id, Name, BillingCity, Country_ISO_Code__c, Type, Accreditations__c from Account where 
 	 			
 	 				Type = 'Dealer' 
 	 				
 	 				AND Country_ISO_Code__c =: lead.Country_ISO__c
 	 				
 	 			
 	 				
 	 				AND Accreditations__c includes (: lead.All_Accreditation_Endorsements__c ) 
 	 				
 	 				AND Accreditations__c != null
 	 				
 	 				LIMIT 1000];
 	 				
 	 				accs = fromLead;

 

 

Does anyone know how to get the currentpage name as in the Visualforce Name in Apex?

 

PageReference pageRef = ApexPages.currentPage(); doesn't give me the name without writing code to pull it out.

 

I simple need a way to grab the name so I can set the title and content dynamically through an object.

 

My only work around would be writing the pageref to the object but when I write to the field I get and error:  Invalid bind expression type of System.PageReference for column of type String.

 

Please help asap.

 

Gracias

Hi

 

I have a method in the controller to delete a record when i click on a apex:outputLink   ,but before i delete a record i have to ask for a confirmation using javascript ,How can i call a apex method from a javascript using the user in put if the user says yes it should execute otherwise it should not execute at all .

 

Regards

Vinayak sharma

I am creating visual force pages for to override New, Edit, and Detail view for a custom object. I am using ActionSupport event On Change for a checkbox. Why is it that when I check the checkbox the even that would be considered "on change" the section of the page that should be rendered on this action does not display. It displays if I click outside of the checkbox after the checkbox has been checked.

 

There is a lot more to add to this extension but I wanted to test that it functioned properly before I coded anymore.

 

Here is the Controller extension:

public with sharing class GoLiveController { public Go_Live_Process__c glp; public apexpages.standardController controller {get; set;} public GoLiveController(ApexPages.StandardController stdController) { // constructor controller = stdController; this.glp= (Go_Live_Process__c)stdController.getRecord(); Go_Live_Process__c goLives = (Go_Live_Process__c)stdController.getRecord(); goLives = [SELECT Account__c FROM Go_Live_Process__c WHERE id=:system.currentpageReference().getparameters().get('id')]; } //Property for Credentialing checkbox public Boolean showCredentialing{ get{ if(showCredentialing == null){ showCredentialing = false; } return showCredentialing; } set; } //Property for client agreement checkbox public Boolean showClientAgreement{ get{ if(showClientAgreement == null){ showClientAgreement = false; } return showClientAgreement; } set; } }

Here is part of the visual force page:

 

... <apex:pageBlockSectionitem > <apex:outputLabel value="Client Agreement"/> <apex:inputCheckBox value="{!showClientAgreement}"> <apex:actionSupport event="onchange" rerender="EditForm" status="showClientAgreement" /> </apex:inputCheckBox> </apex:pageBlockSectionitem> <apex:actionStatus startText="(rendering Client Agreement Go Live...)" id="showClientAgreement"/> </apex:pageBlockSection> <apex:actionRegion > <apex:pageBlockSection title="Client Agreement" rendered="{!showClientAgreement}" id="closeoutBlock" columns="2"> <apex:inputField value="{!Go_Live_Process__c.Privileges_issued__c}"/> </apex:pageBlockSection> </apex:actionRegion> ...

Any Ideas? I know how it works and I think it would be okay but I think that users would complain about having to click outside of the checkbox even after they have already checked the box.

 

Thanks!

Message Edited by MSVRad on 10-16-2009 11:10 AM
  • October 16, 2009
  • Like
  • 0

Dear salesforce.com users,

 

I want to share with you one Appex class that sorts a List<sObject> by any field in ascending or descending order. The List<sObject> is generated by any SOQL statement, so it can be made of custom and/or standard objects. 

 

Using this class is quite simple, and because I have written unit tests that validates 100% of the code you can easily use it in production sytems.

 

The class performs quite well because the sorting is done in memory (using Maps, Sets and Lists). It also detects if the sort has been done for this field so it does not need to resort (even if it is in reverse order).

 

Before going into details of the Appex class, let me show you how the class is used...

 

The VisualForce page:

Nothing fancy here... Just a page building a datatable with three columns and command buttons on the table headers to sort the data.

<apex:page controller="aaSorterContact">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="1" ID="AjaxTable">
<apex:datatable value="{!List}" var="acc" Border="1" cellspacing="1" cellpadding="5">
<apex:column >
<apex:facet name="header">
<apex:commandButton action="{!SortByName}"

value="Sort By Name" rerender="AjaxTable" />
</apex:facet>
<apex:outputText value="{!acc.Name}" />
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandButton action="{!SortByPhone}"

value="Sort By Phone" rerender="AjaxTable" />
</apex:facet>
<apex:outputText value="{!acc.Phone}" />

</apex:column>
<apex:column >
<apex:facet name="header">

<apex:commandButton action="{!SortByAccount}"

value="Sort By Account" rerender="AjaxTable" />
</apex:facet>
<apex:outputText value="{!acc.Account.Name}" />

</apex:column>
</apex:datatable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

The controller:

Couple things going in here, but that is just to make the page look nice... Nothing really to do with the sorting.

public class aaSorterContact {
private String sortedBy = null;
private Boolean sortAscending = null;
private AP_SortHelper sorter = new AP_SortHelper();
private List<Contact> sortedList = null;

public aaSorterContact() {
sorter.originalList = [SELECT Name, Phone, Account.Name FROM Contact];
}
public PageReference SortByName() {
setSortedBy('NAME');
sortedList = (List<Contact>) sorter.getSortedList('Name', sortAscending);
return null;
}
public PageReference SortByAccount() {
setSortedBy('ACCOUNT');
sortedList = (List<Contact>) sorter.getSortedList('Account.Name', sortAscending);
return null;
}
public PageReference SortByPhone() {
setSortedBy('PHONE');
sortedList = (List<Contact>) sorter.getSortedList('Phone', sortAscending);
return null;
}
public List<Contact> getList() {
if (sortedList == null) {
SortByName();
}
return sortedList;
}
private void setSortedBy(String value) {
if (sortedBy == value) {
sortAscending = !sortAscending;
} else {
sortAscending = true;
}
sortedBy = value;
}
}

 

Let me talk about the easy part first...

 

There are methods that answer the calls from the commandbuttons on the page:

 

  • SortByName
  • SortByAccount
  • SortByPhone

 

These methods follow the same structure:

setSortedBy('NAME');
sortedList = (List<Contact>) sorter.getSortedList('Name', sortAscending);
return null;

First, it calls a method setSortedBy() to find out the ascending or descending order. If the user clicks on a different button, the table is sorted ascending by that column, ortherwise the order is inverted from Ascending to descending and viceversa.

 

Second, it calls the method in the Appex class that does the sorting. (I will explain on detail how to use the Appex class, keep reading) :smileywink:

 

Finally, the controller's method returns a null value to the page.

 

The controller's constructor gets the list from the database.

public aaSorterContact() {
sorter.originalList = [SELECT Name, Phone, Account.Name FROM Contact];
}

Since the buttons use the rerendered propery (using AJAX), the class constructor is only called at the initial page load rather than every time the buttons are clicked, therefore the SOQL gets called only once regardless of how many times the data table gets sorted.

 

Finally, the more interesting part...

 

The Appex class that sorts:

You don't really need to understand how this class works to use it, but those of you who are interested...

public class AP_SortHelper {     // <ID, Position>
private Map<String, Integer> listPosition = null; // <FieldName, <FieldValues>>
private Map<String, List<String>> sortedFieldValuesPerFieldName = null; // <FieldName, <FieldValue, <IDs>>>
private Map<String, Map<String, List<String>>> sObjectIDsPerFieldNames = null;

// Properties
public List<sObject> originalList {get; set;}

// Constructor
public AP_SortHelper() {
originalList = null;
}// Public Method
public List<sObject> getSortedList(String fieldName, Boolean ascending) {
if (originalList == null) {
// Assume that originalList has a not NULL value.
// If the class who uses this method has not assigned a value it will get an Exception which
// needs to be handled by the calling class. // Force the exception...
originalList.clear();
} // Make field name uppercase
fieldName = fieldName.toUpperCase(); // Get sorted list
return makeSortedList(fieldName, ascending);
}
public List<sObject> getSortedList(List<sObject> originalList, String fieldName, Boolean ascending) {
this.originalList = originalList;
sortedFieldValuesPerFieldName = null;
return getSortedList(fieldName, ascending);
}

// Private Methods
private void InitializeFieldName(String fieldName) {
String sObjectID;
Integer position;
String fieldValue;
List<String> sObjectIDs = null;
Set<String> valuesForFieldSet = null; // Sets automatically omit duplicate values
List<String> valuesForFieldList = null;
Map<String, List<String>> sObjectIDsPerFieldValues = null;

// Make sortedFieldValuesPerFieldName
if (sortedFieldValuesPerFieldName == null) {
listPosition = new Map<String, Integer>();
sortedFieldValuesPerFieldName = new Map<String, List<String>>();
sObjectIDsPerFieldNames = new Map<String, Map<String, List<String>>>();
}

// Get (or create) map of sObjectIDsPerFieldValues
sObjectIDsPerFieldValues = sObjectIDsPerFieldNames.get(fieldName);
if (sObjectIDsPerFieldValues == null) {
sObjectIDsPerFieldValues = new Map<String, List<String>>();
sObjectIDsPerFieldNames.put(fieldName, sObjectIDsPerFieldValues);
}
if (!sortedFieldValuesPerFieldName.keySet().contains(fieldName)) {
// Objects need to be initialized
position = 0;
valuesForFieldSet = new Set<String>();
listPosition = new Map<String, Integer>();

for (sObject sObj : originalList) {
sObjectID = sObj.ID;
fieldValue = getValue(sObj, fieldName);

// Add position to list
listPosition.put(sObjectID, position++);

// Add the value to the set (sets rather than lists to prevent duplicates)
valuesForFieldSet.add(fieldValue);

// Get (or create) map of sObjectIDs
sObjectIDs = sObjectIDsPerFieldValues.get(fieldValue);
if (sObjectIDs == null) {
sObjectIDs = new List<String>();
sObjectIDsPerFieldValues.put(fieldValue, sObjectIDs);
}

// Add ID to sObjectIDs
sObjectIDs.add(sObjectID);
}

// Sort set items (Need to convert to list)
valuesForFieldList = new List<String>();
valuesForFieldList.addAll(valuesForFieldSet);
valuesForFieldList.sort();

// Now add it to the map.
sortedFieldValuesPerFieldName.put(fieldName, valuesForFieldList);
}
}
private List<sObject> makeSortedList(String fieldName, Boolean ascending) {
Integer position;
List<String> sObjectIDs = null;
List<String> valuesForFieldList = null; // Initialize objects
InitializeFieldName(fieldName); // Get a list of the same type as the "originalList"
List<sObject> outputList = originalList.clone();
outputList.clear(); // Get a list of sorted values
valuesForFieldList = sortedFieldValuesPerFieldName.get(fieldName);

// for each sorted value
for (String fieldValue : valuesForFieldList) {
// Get lisft of IDs
sObjectIDs = sObjectIDsPerFieldNames.get(fieldName).get(fieldValue);

// for each ID
for (String ID : sObjectIDs) {
// Get position in originalList
position = listPosition.get(ID); // Add each sObject to the list.
if ((ascending) || (outputList.size()==0)) {
outputList.add(originalList[position]);
} else {
outputList.add(0, originalList[position]);
}
}
}
return outputList;
}
private static String getValue(sObject sObj, String fieldName) {
// This returns the sObject desired in case the fieldName refers to a linked object.
Integer pieceCount;
String[] fieldNamePieces;

fieldNamePieces = fieldName.split('\\.');
pieceCount = fieldNamePieces.size();
for (Integer i = 0; i < (pieceCount-1); i++) {
sObj = sObj.getSObject(fieldNamePieces[i]);
}
return String.valueOf(sObj.get(fieldNamePieces[pieceCount-1]));
}

// Unit testing
/*
static testMethod void testSortCustomObject() {
List<TPValue__c> TPValues;
AP_SortHelper sorter = new AP_SortHelper();
String fieldName;

TPValues = [SELECT TPName__r.TPName__c, Value__c FROM TPValue__c LIMIT 50];
fieldName = 'Value__c';
testOrderedList(sorter.getSortedList(TPValues, fieldName, true), fieldName, true);

fieldName = 'TPName__r.TPName__c';
testOrderedList(sorter.getSortedList(TPValues, fieldName, true), fieldName, true);
}
*/
static testMethod void testSimpleField_Ascending() {
testSortingContacts('Name', true);
}
static testMethod void testSimpleField_Descending() {
testSortingContacts('Name', False);
}
static testMethod void testLookupField_Ascending() {
testSortingContacts('Account.Name', True);
}
static testMethod void testLookupField_Decending() {
testSortingContacts('Account.Name', False);
}
static testMethod void testMultipleCalls() {
AP_SortHelper sorter;
sorter = testSortingContacts(null, 'Name', true);
testSortingContacts(sorter, 'Name', False);
testSortingContacts(sorter, 'Account.Name', True);
testSortingContacts(sorter, 'Account.Name', False);
}
static testMethod void testForgotOriginalList() {
Boolean exceptionDetected = false;
AP_SortHelper sorter = new AP_SortHelper();
try {
sorter.getSortedList('Name', true);
} catch (NullPointerException e) {
exceptionDetected = true;
}
System.assert(exceptionDetected);
}
static testMethod void testPassingList() {
AP_SortHelper sorter = new AP_SortHelper();
List<Contact> contacts = [SELECT Name, Phone, Account.Name FROM Contact LIMIT 50];
List<Contact> sortedList = (List<Contact>) sorter.getSortedList(contacts, 'Name', true);
testOrderedList(sortedList, 'Name', true);
}
private static void testSortingContacts(string fieldName, Boolean isAscending) {
testSortingContacts(null, fieldName, isAscending);
}
private static AP_SortHelper testSortingContacts(AP_SortHelper sorter, string fieldName, Boolean isAscending) {
// If sorted is null,create it.
if (sorter == null) {
sorter = new AP_SortHelper();
sorter.originalList = [SELECT Name, Phone, Account.Name FROM Contact LIMIT 50];
}

// Sort list
List<Contact> sortedList = (List<Contact>) sorter.getSortedList(fieldName, isAscending); // Test sort order
testOrderedList(sortedList, fieldName, isAscending);

return sorter;
}
private static void testOrderedList(List<sObject> sortedList, string fieldName, Boolean isAscending) {
String lastValue = null;
String currentValue = null; for (sObject sObj : sortedList) {
currentValue = getValue(sObj, fieldName);
if ((lastValue != null) && (currentValue != null)) { String strDebug = '';
strDebug += '\n--------------------------------------------------------------';
strDebug += '\nSTART';
strDebug += '\n--------------------------------------------------------------';
strDebug += '\n[Ascending:'+isAscending+']';
strDebug += '\n[Previous:'+lastValue+'] [IsNull():'+(lastValue==null)+']';
strDebug += '\n[Current:'+currentValue+'] [IsNull():'+(currentValue==null)+']';
strDebug += '\n[CompareTo:'+(currentValue.compareTo(lastValue))+']';
strDebug += '\n--------------------------------------------------------------';
strDebug += '\nEND';
strDebug += '\n--------------------------------------------------------------';
System.debug(strDebug); if (isAscending) {
System.assertEquals(currentValue.compareTo(lastValue)>=0, true);
} else {
System.assertEquals(currentValue.compareTo(lastValue)<=0, true);
}
}
lastValue = currentValue;
}
}
}

 

How to use this class?

  1. Create an instance of this class AP_SortHelper()
  2. Assign the list to sort. Get this list using SOQL.
  3. Call the getSortedList() method which takes two fields:
    1. The name of the field as it was used in the SOQL
    2. The order (true for ascending, false for descending

 


For now, I have one question to the group...

 

This message is getting long... Is there a better place to post it? The way I see it, AppeXchange is applications not for independent utility classes.

Message Edited by andresperez on 01-28-2009 10:45 AM
Hi,
 
I want to use the Apex Data Loader ( version 9.0 ) command line interface to get information from a SQL server 2000 db and import it into salesforce.  So far I've managed to successfully import from a csv using the command line ( and the process-conf.xml ).  But to connect to my SQL server database I need to know which driver to use ( I'm not a java programmer ).  I've looked about and the driver seems to be
 com.sun.sql.jdbc.sqlserver.SQLServerDriver
 
But when I use this I get the error 
 
ERROR com.salesforce.lexiloader.dao.database.DatabaseContext  - Database error encountered during connecting for database configuration: queryNewCustomers.  Sql error: Cannot load JDBC
driver class 'com.sun.sql.jdbc.sqlserver.SQLServerDriver'.
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.sun.sql.jdbc.sqlserver.SQLServerDriver'
 at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:766)
 at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
 at com.salesforce.lexiloader.dao.database.DatabaseContext.initConnection(DatabaseContext.java:89)
 at com.salesforce.lexiloader.dao.database.DatabaseContext.checkConnection(DatabaseContext.java:81)
 at com.salesforce.lexiloader.dao.database.DatabaseReader.checkConnection(DatabaseReader.java:231)
 at com.salesforce.lexiloader.process.ProcessRunner.run(ProcessRunner.java:121)
 at com.salesforce.lexiloader.process.ProcessRunner.main(ProcessRunner.java:228)
 
Is there something I'm missing - a driver, installation, location of class file etc?  I
downloaded the Microsoft SQL Server 2005 JDBC Driver 1.1, a Type 4 JDBC driver that provides database connectivity through the standard JDBC application program interfaces (APIs) available in J2EE (Java2 Enterprise Edition), but don't know if I have to do something further to use this??
 
Any help would be great!
 
Sandra