Advertisement
martyychang

TransactionSiteController

Feb 6th, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Controller supporting the TransactionRecordTypeDemo page that demonstrates
  3.  * how to allow a user to select a Transaction record type from a dynamically
  4.  * generated list.
  5.  *
  6.  * @version 0.3
  7.  * @see     https://developer.salesforce.com/forums/ForumsMain?id=906F00000009F1M
  8.  * @author  Marty Chang (Slalom Consulting)
  9.  */
  10. public class TransactionSiteController {
  11.  
  12.     /*
  13.      * A Transaction record template to facilitate Salesforce-native user input.
  14.      */
  15.     public Transaction__c proxy { get; set; }
  16.  
  17.     /*
  18.      * Default constructor that initializes member variables
  19.      */
  20.     public TransactionSiteController() {
  21.         proxy = new Transaction__c();
  22.     }
  23.    
  24.     /*
  25.      * @return The custom edit page for Transactions, with the specified
  26.      *         record type ID
  27.      */
  28.     public PageReference editWithRecordType() {
  29.  
  30.         // Define some parameters for the edit page.
  31.         // There must be a better way to do this, because hardcoding the
  32.         // relative URL means it's not robust and will not work in
  33.         // Communities.
  34.  
  35.         String transactionObjectPrefix =
  36.             Schema.SObjectType.Transaction__c.getKeyPrefix();
  37.  
  38.         PageReference nextPage =
  39.             new PageReference('/' + transactionObjectPrefix + '/e');
  40.  
  41.         // Add parameters to pre-populate known values for the new record
  42.  
  43.         nextPage.getParameters().put('RecordType', proxy.RecordTypeId);
  44.  
  45.         String transactionAccountFieldName =
  46.             'CF00N90000006CdMG';  
  47.                 // Hardcoding is bad. There must be a better way!
  48.         String accountName = 'sForce';  // Hardcoded for demo purposes
  49.         nextPage.getParameters().put(transactionAccountFieldName, accountName);
  50.  
  51.         return nextPage;
  52.     }
  53. }   // public class TransactionSiteController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement