• Skwal
  • NEWBIE
  • 0 Points
  • Member since 2009

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

1) I am trying again to get selected rows (with getSelected() on the controller) from an Enhanced list view in a VF page. Am I doing something wrong or is it just not possible to pass the EnhancedList records to a custom controller? It seems that the Enhanced list recordset should be bound to the controller records but I cannot figure out where this should happen.

 

2) BTW, I also try to change the FilterID in the EnhancedList but it does not refresh properly. Is this a known issue?

 

Here is the code. Any help would be great.

<apex:page standardController="Contact" extensions="pgContactHomeController" showHeader="true" tabStyle="Contact" recordSetVar="myContacts">

	<apex:form >
        <apex:selectList value="{!FilterID}" size="1">
            <apex:actionSupport event="onchange" rerender="listPanel"/>
            <apex:selectOptions value="{!listviewoptions}"/>
        </apex:selectList>
    </apex:form>
    
	<apex:outputPanel layout="block" id="listPanel">
		<apex:enhancedList height="300" ListId="{!FilterID}" rowsPerPage="10" id="ContactList" customizable="True"  reRender="debugPanel"/>
	</apex:outputPanel>    

	<apex:outputPanel layout="block" id="debugPanel">
    	<apex:pageblock id="myBlock">
	  		<apex:outputText value="Records={!recordCount}" /> <br/>
			<apex:outputText value="Selected={!selectedCount}" /> <br/>
			<apex:outputText value="FilterID={!FilterID}" /> <br/>
		</apex:pageblock>
	</apex:outputPanel>
	
</apex:page>
public with sharing class pgContactHomeController {
    private ApexPages.StandardSetController myController;
    public pgContactHomeController(ApexPages.StandardSetController stdController) {
     this.myController = stdController;
    }
public Integer getRecordCount(){
return ((List<Contact>)myController.getRecords()).size();
}
public Integer getSelectedCount(){
return ((List<Contact>)myController.getSelected()).size();
}
public Id getFilterID(){
return (myController.getFilterID());
}
public void setFilterID(ID newID){
myController.setFilterID(newID);
return;
}
}

 

 

 

  • March 04, 2011
  • Like
  • 0

I have exactly the same issue as in MD Chen post on ideas. How do you get selected records from a enhancedList? Here is the code:

 

Page

 

<apex:page standardController="ProfileHierarchy__c" recordSetvar="profiles" extensions="testController">
  <apex:enhancedlist type="ProfileHierarchy__c" height="200" rerender="c1,c2" />
  <apex:outputText id="c1" value="c1={!c1}" /> <br>
  <apex:outputText id="c2" value="c2={!c2}" /> <br>
</apex:page>

 Controller

 

public class testController {

  public testController (ApexPages.StandardSetController controller){
    li=controller;
  }

  public ApexPages.StandardSetController li{get;set;}

  public Integer getC1(){
    return ((List<ProfileHierarchy__c>)li.getRecords()).size();
  }

  public Integer getC2(){
    return ((List<ProfileHierarchy__c>)li.getSelected()).size();
  }
}

Thank you.

 

 

 

  • March 01, 2011
  • Like
  • 0

To provide localization support, I need to get the Label for recordTypes just as we can do for Objects (see sample code that works for getting the label of an object below). I tried to use the getRecordTypeInfos() method but that will not return a result that can be described. Am I missing somethingor is there no describe API on recordTypes to do that? This code is used in a visualForce component to render the label in the language locale selected by the user.

 

string objectName = 'kdsProject__c'; string plural = 'true'; Schema.DescribeSObjectResult myObject = Schema.getGlobalDescribe().get(objectName).getDescribe(); if(plural=='true') retVal = myObject.getLabelPlural(); else retVal = myObject.getLabel();

 


 

  • January 16, 2010
  • Like
  • 0

I have exactly the same issue as in MD Chen post on ideas. How do you get selected records from a enhancedList? Here is the code:

 

Page

 

<apex:page standardController="ProfileHierarchy__c" recordSetvar="profiles" extensions="testController">
  <apex:enhancedlist type="ProfileHierarchy__c" height="200" rerender="c1,c2" />
  <apex:outputText id="c1" value="c1={!c1}" /> <br>
  <apex:outputText id="c2" value="c2={!c2}" /> <br>
</apex:page>

 Controller

 

public class testController {

  public testController (ApexPages.StandardSetController controller){
    li=controller;
  }

  public ApexPages.StandardSetController li{get;set;}

  public Integer getC1(){
    return ((List<ProfileHierarchy__c>)li.getRecords()).size();
  }

  public Integer getC2(){
    return ((List<ProfileHierarchy__c>)li.getSelected()).size();
  }
}

Thank you.

 

 

 

  • March 01, 2011
  • Like
  • 0

I created a send email class that accepts a bunch of parameters. It's currently used by two visualforce pages and 1 trigger/class.

 

The trigger/class setup is currently failing when I deploy to production. However, when I run the tests in the sandbox it comes back completely fine. The trigger is fired on an update of a case. When I update the case to fire the trigger - I get the expected result (an email).

 

I am creating my objects in the test class - except my Email Template and SF user (which are in both sandbox and production). All other objects - Account, Contact, and Case are created in the test class directly.

 

I added a system.debug('THIS IS THE MAIL:" + mail); to my send email class and this is what I see in the debug log when I deploy.

 

20090417151127.818:Class.Send_Single_Email_Class.SendEmail: line 111, column 9: THIS IS THE MAIL:Messaging.SingleEmailMessage[getBccAddresses=();getCcAddresses=();getCharset=null;getDocumentAttachments=null;getFileAttachments=null;getHtmlBody=null;getPlainTextBody=null;getTargetObjectId=005700000017EbwAAE;getTemplateId=00X70000001F7ESEA0;getToAddresses=(support@pharmacyonesource.com);getWhatId=50070000008R2QFAA0;isUserMail=false;] System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null

 

 

You can see it stats Unknown_Exception - then tells me a parmaeters is null. I've compared these lines to a successful test that's run (using the same class but on different objects) - and with the exception of the TemplateID (not used) and the specific Email Address/WhatID it looks 100% the same.

 

I thought it might be my template problem - but I'm setting it like this

***Trigger's Class*** EmailTemplate ThisTemplate = [Select e.Id From EmailTemplate e where e.developerName= 'Case_Notification_of_New_Task_or_Comment']; ID TemplateID = ThisTemplate.Id; ***Send Email Class*** mail.setTemplateId(TemplateID); system.debug('Template is Valid: ' + TemplateID);

 

I'm really scratching my head on this one. I figured I must be missing something when I pass things over. But the SendEmail class works with my visualforce pages - just not this Trigger/Class. The main difference is I'm using a template ID and not setting the mail.setToAddresses to anything other than null.

 

Current UnitTest - The Trigger loops through trigger.new and assigns to variables the items passed over to each send email.

 

static testMethod void testTriggerCase_Interface_Before_Insert_Before_Update() 
{
	RecordType CaseRecordType = [Select r.SobjectType, r.Id, r.DeveloperName From RecordType r where r.DeveloperName='Standard' and sObjectType = 'Case'];
	User CSRQueue = [Select u.Username, u.UserRoleId, u.ProfileId, u.ManagerId, u.LastName, u.IsActive, u.Id, u.FirstName, u.Name,u.Email, u.CommunityNickname, u.Alias From User u where u.Id = '005700000017Ebw' and u.IsActive = True limit 1];
			
		Account NewAccount1 = new Account(name='Test Code Account',
			Hospital_Bed_Size__c = -1,
			BillingStreet = '7780 Elmwood Ave',
			BillingCity = 'Middleton', 
			BillingState = 'WI', 
			BillingPostalCode = '5356'
	   	);
	        insert NewAccount1;
		Contact NewContact = new Contact(
	   		LastName='Test',
	   		firstname='Contact',
	   		Email=CSRQueue.Email,
	   		AccountId = NewAccount1.id
	   	);	
	   	insert NewContact;	    
		Implementation__c NewS7IF = new Implementation__c 
	   	(
	   		RecordTypeId = '012500000009EQZ',
	   		Name = 'Test Code Implementation',
	   		Account__c = NewAccount1.id,
	   		//i.Product__c = 'Unit Stock',
	   		Sale_Date__c = date.Today(),
	   		Implementer__c = '005700000017Ebw', //CSR Queue   			
	   		Action_Requirement__c = 'POS',
	   		Stage__c = 'Initiation',
	   		Status__c = 'Moving Along',
	   		Status_Reason__c = 'N/A',
	   		Product__c = 'Sentri7 Interfaces',
	   		Interface_Products__c = 'Quantifi',
	   		Feed_Status__c = 'No Data Received Yet'
	   	);	
	   	insert NewS7IF;	   	
		Case NewStandardCase = new Case
		(
		  OwnerId = '005700000017Ebw', //CSR Queue 
		  //Implementation_Issue__c = ImpIssueTestUnit().id, //Issue to be used 
		  Type = 'Interfaces', 
		  Project_Type__c = 'Hold',
		  Implementation__c = NewS7IF.Id,
		  Products__c = 'Interfaces',		  
		  ContactId = NewContact.Id,
		  Origin = 'Internal',
		  Subject = 'This is a test subject used to test trigger',
		  RecordTypeId = CaseRecordType.Id		
		);
		Case NewStandardCase2 = new Case
		(
		  OwnerId = CSRQueue.ID, //'005700000017Ebw', //CSR Queue 
		  //Implementation_Issue__c = ImpIssueTestUnit().id, //Issue to be used 
		  Type = 'Interfaces', 
		  Project_Type__c = 'Hold',
		  Implementation__c = NewS7IF.Id,
		  Products__c = 'Interfaces',		  
		  ContactId = NewContact.Id, 
		  Origin = 'Internal',
		  Subject = 'This is a test subject used to test trigger2',
		  RecordTypeId = CaseRecordType.Id		
		);
		list<case> InsertCases = new list<case>();
		
		InsertCases.add(NewStandardCase);
		InsertCases.add(NewStandardCase2);			
		insert InsertCases;
		
        NewStandardCase.Notification_to_Owner__c = 1;
        NewStandardCase2.Notification_to_Owner__c = 0;
        list<case> UpdateCases = new list<case>();
        UpdateCases.add(NewStandardCase);
        UpdateCases.add(NewStandardCase2);        
        update UpdateCases;	
				
	} 

 

The Class that calls the SendEmail Class - this is done on a before update. Trigger is fired before update of case, and only cases with Notification_To_Owner__c set to 1 are sent to the NotificationToOwner class method below. The class loops through the list pulling the information and sending the e-mail and also returns the value to Notification_To_Owner__c to 0.

There's a lot of "empty" variables here since they get passed in other classes that use the SendEmail class. When I tested it doesn't appear that anything goes wrong if these are null as long as the required items are also present. (Example either a TemplateID or a HTMl/Plain body)

 

public static void NotificationToOwner(list<case> TheseCases) { set<id> OwnerID = new set<id>(); for(case c: TheseCases) { OwnerID.add(c.OwnerID); } map<id, User> MapUsers = new map<id,user>([Select u.Title, u.ManagerId, u.Id, u.Email From User u where u.id in :OwnerID]); /*Required SendEmail Variables */ list<string> ToEmail = new list<string>(); Contact eContact; list<string> CC = new list<string>(); list<string> BCC = new list<string>(); Boolean eAttach = False; Blob eAttachment; string eName; Boolean Activity = False; ID WhatID; Boolean Attach = False; String aName; String eSubject; String eBody; list<ID> DocAttach = new list<ID>(); EmailTemplate ThisTemplate = [Select e.Id From EmailTemplate e where e.developerName= 'Case_Notification_of_New_Task_or_Comment']; /*This template is present in both Sandbox and Production with the SAME developername */ ID TemplateID = ThisTemplate.Id; ID TargetObjectId; //list<case> UpdateCases = new list<case>(); /*Loop through cases and send Email */ for(case c: thesecases) { ToEmail.Clear(); //ToEmail.add(MapUsers.get(c.OwnerID).Email); WhatID = c.id; TargetObjectID = c.OwnerID; c.Notification_to_Owner__c=0; system.debug('Case Number, Case ID: ' + c.CaseNumber +' ID: '+ c.ID); system.debug('Email Variable OwnerID: ' + c.OwnerID); system.debug('Email Variable Email: ' + ToEmail); system.debug('Email Variable Case WhatID: ' + WhatID); Send_Single_Email_Class.SendEmail(ToEmail,eContact, CC,BCC, eAttach, eAttachment,eName, Activity,WhatId,Attach, aName,eSubject,eBody,DocAttach,TemplateID,TargetObjectID); } }