• aamDev
  • NEWBIE
  • 175 Points
  • Member since 2010

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 32
    Replies

Can anyone point me in the right direction.

 

Background

 

I am working with a non-profit who need to record sightings of animals using GPS coordinates.  I have created a sightings object and have integrated a google map on the page using visualforce which pulls through the GPS data and adds a marker, code below.

 

I now want to show a map of all of the sightings for a particular animal. So I have created a parent object called wildlife which is simply the name of the animal and some other meta data.

 

Problem

 

The sightings object has a lookup to wildlife.  So if you were to lookup an animal on the wildlife object you would see a number of sightings.  I would like a map on the wildlife object that would show all of the related sightings as markers.

 

Code

 

This is the code for the single sightings map on the sightings object.

 

 

<apex:page standardController="Sighting__c">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAARQVi0nDV8_SJqZY8mkksjBQW4dj6q0E-oPzXa2fArCvhLhZBwBSQtm6TiVKHbHEvo8Jcr3_JN01Ubg" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var address = "{!Sighting__c.Long__c}, {!Sighting__c.Lat__c}";
function initialize() {
if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map_canvas"));
  map.addControl(new GSmallMapControl());
  map.setMapType(G_HYBRID_MAP);
  geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        document.getElementById("map_canvas").innerHTML = address + " not found";
      } else {
        map.setCenter(point, 16);
        var marker = new GMarker(point);        
        map.addOverlay(marker);
        marker.bindInfoWindowHtml("{!Sighting__c.Wildlife__r.Name__c} the {!Sighting__c.Wildlife__r.Type__c}<br /> Sighting Number: {!Sighting__c.Name}<br />{!Sighting__c.Date__c}");
      }
    }
  );
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width:100%;height:300px"></div>
</body>
</html>
</apex:page>

 

 

 

 

hello,

 

i am new to visual force and apex and will appreciate the help on below.

 

i created a table in VF and retrieving the data like consultants , no of project and no of tasks from from the controller. its working fine but i need to click one of the consultants from the list above to get the detail report on the other page. i am trying to pass some parameters once "Onclick" function is performed but its returning null when i am clikcing on one of the consultant to get the reports on new page. below is my VF page.

 

Visual Force Page :

 

<apex:page controller="Consultant_Information">

<script type="text/javascript">
      function loadReports(Alias){
        if(typeof AF_LoadReports  == "function") {AF_LoadReports(Alias);}
      }
  </script>


  <apex:form >
  <apex:actionFunction name="AF_LoadReports" action="{!loadReports}" >
  <apex:param name="Alias" assignTo="{!Alias1}" value="" />    
  </apex:actionFunction>
  <apex:pageBlock title="Consultant Summary" >
  <apex:PageBlockSection columns="1" >
 <apex:pageBlockTable value="{!Items}" var="item">

 
<apex:column headerValue="Consultant" value="{!item.theUser.Name}" onclick="javascript&colon;AF_LoadReports('{!item.theUser.Alias}')"/>
<apex:column headerValue="Department" value="{!item.theUser.Division}"/>
<apex:column headerValue="Active Projects" value="{!item.noProjects}"/>
<apex:column headerValue="Active Tasks" value="{!item.noTasks}"/>
<apex:column headerValue="Last Login Date" value="{!item.theUser.LastLoginDate}"/>
</apex:pageBlockTable>
  </apex:PageBlockSection>
 
 
 
 
  
   
       
     </apex:pageBlock>

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

 

 

 

and below is my controler

 

public with sharing class Consultant_Information {
 public Consultant_Information(){
  loadConsultants();
 }
 
 public class userWrap{
                public User theUser{get;set;}
                public integer noProjects{get;set;}
                public integer noTasks{get;set;}
             
   }
public PageReference loadReports(){  
 String Alias1 =ApexPages.currentPage().getParameters().get('Alias');
 PageReference pageRef = new PageReference('https://c.na7.visual.force.com/apex/pConsultantSummary?Alias'+'='+Alias1);                    
  pageRef.setRedirect(true);
 
  return pageRef;
  }
 
public List<userWrap> listConsultant = new list<userWrap>();
  
public List<userWrap> getItems() {return listConsultant;}
 
 private void loadConsultants(){ 
 listConsultant.clear();
 List<User> users = new List<User>([Select u.Name, u.Id, u.Alias, u.Division, u.LastLoginDate From User u where u.IT_User__c = true and u.IsActive = true order by u.Name]);
 List<AggregateResult> Projects = new List<AggregateResult>([Select count(p.Id) noProjects, p.OwnerId from Project__c p where p.Project_Life_Cycle_Stages_2__c <> 'Closed' group by p.OwnerId]);
 List<AggregateResult> Tasks = new List<AggregateResult>([Select count(t.Id) noTasks, t.OwnerId from Task__c t where t.Task_Status__c <> 'Closed' group by t.OwnerId]);

 for(User u : users){
  userWrap wrap = new userWrap();
  wrap.theUser = u;
   for(AggregateResult r : projects){
   if(r.get('OwnerId') == u.Id){wrap.noProjects = (r.get('noProjects')==null?0: integer.valueOf(r.get('noProjects'))) ;}
  }
  for(AggregateResult r : tasks){
   if(r.get('OwnerId') == u.Id){wrap.noTasks = (r.get('noTasks')==null?0: integer.valueOf(r.get('noTasks')));}
  }
  listConsultant.add(wrap);
  }
  
 }
  
}

I have a visualforce page where the user enters a start date and end date to return a table that returns aggregate results over various groupings.

 

The object that is at the core of my data set is Trade__c. I've been able to return most of my aggregates without too much work, but I've run across a major issue when trying to retrieve what we call "Contacted Reps". Contacted Reps are Contacts that have an Activity tied to them.Trade__c is related to Contact through a field named Contact__c.

 

I need to be able to create an aggregate result like this:

 

for(AggregateResult ar : [SELECT Count(Id) repCount, Account.Name branchName, AccountId branchId FROM Contact WHERE Account.ParentId =: firm AND Account.Territory__c =: territory AND Id IN : contactSet GROUP BY Account.Name, AccountId ORDER BY Account.Name, AccountId]){
						contactedBranch.add((Id)ar.get('branchId'));
Contacted objContacted = new Contacted((String)ar.get('branchName'),(Integer)ar.get('repCount'));
Contacted.add(objContacted);
}

 

 

where contactSet is a list/set of all Contacts with an Activity. I've been creating this contactSet like this:

 

 

Set<Id> contactSet = new Set<Id>();
for (SObject cReps : [SELECT Id, (SELECT Id FROM Events WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate AND Who.Type = 'Contact'), (SELECT Id FROM Tasks WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate AND Who.Type = 'Contact') FROM Contact WHERE Active__c = True AND Account.RecordTypeId = '01230000000Q9p4AAC' AND Account.Parent.Broker_Number__c =:dist174]) {
	SObject[] cEvents = cReps.getSObjects('Events');
	SObject[] cTasks = cReps.getSObjects('Tasks');
	if(cEvents != null || cTasks != null) {
			contactSet.add(cReps.Id);
	}
}

 

The issue is that this list will always create a 'Too Many Rows' failure in our environment (lots of contacts).

 

This could be avoided in some part by creating the list through:

 

for(Contact c : [SELECT Id FROM Contact WHERE Id IN (SELECT WhoId FROM Task WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate AND Who.Type = 'Contact') OR Id IN (SELECT WhoId FROM Event WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate AND Who.Type = 'Contact')]) {  
contactSet.add(c.Id);
}

 

but Task and Event or not supported for semi join inner selects. Ultimately this wouldn't help all that much, considering my user could put a date range that could retrieve all Contacts.

 

With that said, is there a way for me to create this set at all?  I feel like I'm missing something very basic hear. I've seen 'batch apex' thrown around a lot, but all the examples I've seen are for making updates to existing data, not creating a list to be used in controllers.

 

Maybe I'm just thinking about this all wrong, but I can't help but think there's a workaround for this. Thanks for any help.

 

Adriel

  • October 25, 2010
  • Like
  • 0

I need to create a list of distinct Contact Ids from Contacts that have an Event or Task tied to them within a time period. I know one way to create a distinct list is to grab the WhoIds from Event and Task and add them to a Set<Id> like:

 

 

Set<Id> contactSet = new Set<Id>();
for (Event e : [SELECT WhoId FROM Event WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate]) {
	contactSet.add(e.WhoId);
}
for (Task t : [SELECT WhoId FROM Task WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate]) {
	contactSet.add(t.WhoId);
}

 

 

The problem with this is that either loop could retrieve 'Too many query rows'. I could group by WhoId in either one, making an AggregateResult, but with a large enough set of Contacts, I'd run across the queryMore() limitation with AggregateResult.

 

So, I figured I'd try to run a query on Contact with Event and Task subqueries like:

 

 

SELECT Id, (SELECT Id FROM Tasks WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate), (SELECT Id FROM Events WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate) FROM Contact

 

 

How would I populate my Set<Id> contactSet with the Contact Ids where the Task or Event subquery does not equal null?

 

Thanks, I appreciate the help.

 

A

  • October 18, 2010
  • Like
  • 0

I've got a VF page with some links to other VF pages. I'd like for a link to render only if that user's profile has been enabled to access the link's page. How do I do that?

 

Thanks in advance.

  • September 27, 2010
  • Like
  • 0

I need to use the value from an inputField to populate a variable in a wrapper class. How do I that?

 

Controller:

 

 

//Variable for input
public String duration { get; set; }

//Wrapper class needing variable

public class TotalTerr {
		
	public String TerritoryName { get; set; }
	
	//Class variable that needs input
	public String Duration { get; set; }

}

 

I could really use the help - thanks in advance!

 

  • September 17, 2010
  • Like
  • 0

I'm attempting to created a VF page that takes a zip (or series of zips) and create a paginated list of related Accounts. I'm having issues retrieving the data, namely receiving the Attempt to de-reference a null object error.

 

Here's my VF:

 

<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>

	<apex:pageBlock title="Nearby Company/Branch" rendered="{!zips != null}">
		<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>

	<apex:panelGrid columns="4" style="margin-bottom: 25px;" rendered="{!zips != null}">
		<apex:commandLink action="{!first}" rendered="{!(pages > 1) && (hasPrevious)}">First</apex:commandLink>
		<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
		<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
		<apex:commandLink action="{!last}" rendered="{!(pages > 1) && (hasNext)}">Last</apex:commandLink>
	</apex:panelGrid>
</apex:form>

 

Here's my controller class:

 

 

public with sharing class zipMap {
	
	public String zips { get; set; }
	
	public List<String> zList { get; set; }
	
	public ApexPages.StandardSetController accts { get; set; }
	
	public PageReference find() {

		zList = zips.split(',');

		String query = 'SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode =: ' + zList + ' ORDER BY BillingPostalCode, Name';
		
		accts = new ApexPages.StandardSetController(Database.getQueryLocator(query));
		accts.setPageSize(2);
		
		return null;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get {
			
			return accts.getHasNext();
			
		}
		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get {
			
			return accts.getHasPrevious();
			
		}
		
		set;
		
	}
	
	public Integer pageNumber {
		
		get {
			
			return accts.getPageNumber();
			
		}
		
		set;
		
	}

	public Integer pages {
		
		get {
		
			pages = accts.getResultSize()/accts.getPageSize();
			
			return pages;
			
		}
		
		set;
		
	}
	
	public void first() { accts.first(); }
	
	public void last() { accts.last(); }

	public void cancel() { accts.cancel(); }
		
	public PageReference previous() {
		
		Integer p = accts.getPageNumber();
		
		if(hasPrevious) {
		
			accts.setPageNumber(p-1);
		
		}
		
		return null;
		
	}
	
	public PageReference next() {
		
		Integer p = accts.getPageNumber();
		
		if(hasNext) {
		
			accts.setPageNumber(p+1);
		
		}
		
		return null;
		
	}

}

 

 

Can someone please help? Thanks

 

Adriel

  • September 09, 2010
  • Like
  • 0

I created a controller extension to replace the standard "New" record for a custom object. The save and all subsequent updates are working, however, my conditional statement is not working, saving regardless.

 

Here is my VF:

 

<apex:page standardController="Merged_Contact__c" extensions="mergeContact" tabStyle="Merged_Contact__c">
<apex:sectionHeader title="Merging Contacts" subtitle="Merge a Contact's Information to Another" />
<apex:form >
	<apex:pageMessages />
	<apex:pageBlock mode="edit">
		<apex:pageBlockButtons >
			<apex:commandButton action="{!mergeSave}" value="Save" />
		</apex:pageBlockButtons>
		<apex:pageBlockSection title="Select Contacts">
			<apex:inputField value="{!Merged_Contact__c.Merge_to_Contact__c}" required="true" />
			<apex:inputField value="{!Merged_Contact__c.Merge_from_Contact__c}" required="true" />
		</apex:pageBlockSection>
		<apex:pageBlockSection title="Select Optional Fields to Merge">
			<apex:inputField value="{!Merged_Contact__c.Title__c}" />
			<apex:inputField value="{!Merged_Contact__c.Phone__c}" />
			<apex:inputField value="{!Merged_Contact__c.Email__c}" />
			<apex:inputField value="{!Merged_Contact__c.Mobile__c}" />
			<apex:inputField value="{!Merged_Contact__c.Address__c}" />
			<apex:inputField value="{!Merged_Contact__c.Other_Phone__c}" />
			<apex:inputField value="{!Merged_Contact__c.Assistant__c}" />
			<apex:inputField value="{!Merged_Contact__c.Fax__c}" />
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:form>
</apex:page>

 

 Here's my extension:

 

public with sharing class mergeContact {
	
	public Merged_Contact__c mc;
	
	ApexPages.StandardController stdController;

	public mergeContact(ApexPages.StandardController controller) {
		
		stdController = controller;
		this.mc = (Merged_Contact__c)stdController.getRecord();
		
	}
	
	public PageReference mergeSave() {

		Id toId;
		Id fromId;
		Id toHomeId;
		Id fromHomeId;
	
		Boolean title;
		Boolean email;
		Boolean address;
		Boolean assistant;
		Boolean phone;
		Boolean mobile;
		Boolean otherPhone;
		Boolean fax;
		
		Merged_Contact__c newMC;
		Contact fromContact;
		Contact updateContact;
		Contact removeContact;
	
		Set<Id> newPN = new Set<Id>();
		
		List<Contact> toHome = new List<Contact>();
		List<Contact> fromHome = new List<Contact>();
		List<Production_Member__c> updatePM = new List<Production_Member__c>();
		List<Production_Member__c> removePM = new List<Production_Member__c>();
		List<Event> updateEvent = new List<Event>();
		List<Task> updateTask = new List<Task>();

		toId = mc.Merge_to_Contact__c;
		fromId = mc.Merge_from_Contact__c;
	
		toHome = [SELECT Account.ParentId FROM Contact WHERE Id =: toId];
		toHomeId = toHome[0].Account.ParentId;
		
		fromHome = [SELECT Account.ParentId FROM Contact WHERE Id =: fromId];
		fromHomeId = fromHome[0].Account.ParentId;
		
		if(toHomeId == fromHomeId) {
			
			newMC = new Merged_Contact__c(Merge_to_Contact__c = mc.Merge_to_Contact__c, Merge_from_Contact__c = mc.Merge_from_Contact__c, Title__c = mc.Title__c, Phone__c = mc.Phone__c, Email__c = mc.Email__c, Mobile__c = mc.Mobile__c, Address__c = mc.Address__c, Other_Phone__c = mc.Other_Phone__c, Assistant__c = mc.Assistant__c, Fax__c = mc.Fax__c);
			
			title = mc.Title__c;
			email = mc.Email__c;
			address = mc.Address__c;
			assistant = mc.Assistant__c;
			phone = mc.Phone__c;
			mobile = mc.Mobile__c;
			otherPhone = mc.Other_Phone__c;
			fax = mc.Fax__c;
			
			if(title || email || address || assistant || phone || mobile || otherPhone || fax) {
				
				fromContact = [SELECT Id, Title, Email, MailingStreet, MailingCity, MailingState, MailingPostalCode, AssistantName, Phone, MobilePhone, OtherPhone, Fax FROM Contact WHERE Id =: fromId];
				updateContact = [SELECT Id, Title, Email, MailingStreet, MailingCity, MailingState, MailingPostalCode, AssistantName, Phone, MobilePhone, OtherPhone, Fax FROM Contact WHERE Id =: toId];
				
				if(title) { updateContact.Title = fromContact.Title; }
				if(email) { updateContact.Email = fromContact.Email; }
				if(address) { updateContact.MailingStreet = fromContact.MailingStreet; }
				if(address) { updateContact.MailingCity = fromContact.MailingCity; }
				if(address) { updateContact.MailingState = fromContact.MailingState; }
				if(address) { updateContact.MailingPostalCode = fromContact.MailingPostalCode; }
				if(assistant) { updateContact.AssistantName = fromContact.AssistantName; }
				if(phone) { updateContact.Phone = fromContact.Phone; }
				if(mobile) { updateContact.MobilePhone = fromContact.MobilePhone; }
				if(otherPhone) { updateContact.OtherPhone = fromContact.OtherPhone; }
				if(fax) { updateContact.Fax = fromContact.Fax; }
				
			}
	
			removeContact = new Contact(Id = fromId, Active__c = False);
				
			for(Production_Member__c fpm : [SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: fromId]){
				
				newPN.add(fpm.Production_No__c);
				
			}
		
			for(Production_Member__c tpm : [SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: toId]){
				
				newPN.remove(tpm.Production_No__c);
				
			}
			
			for(Production_Member__c upm : [SELECT Id FROM Production_Member__c WHERE Contact__c =: fromId AND Production_No__c IN : newPN]){
				
				Production_Member__c pm = new Production_Member__c(Id = upm.Id, Contact__c = toId);
				updatePM.add(pm);
				
			}
		
			for(Production_Member__c rpm : [SELECT Id FROM Production_Member__c WHERE Contact__c =: fromId AND Production_No__c NOT IN : newPN]){
				
				Production_Member__c pm = new Production_Member__c(Id = rpm.Id);
				removePM.add(pm);
				
			}
		
			for (Event e : [SELECT Id FROM Event WHERE WhoId =: fromId]) {
				
				Event fe = new Event(Id = e.Id, WhoId = toId);
				updateEvent.add(fe);
				
			}
			
			for (Task t : [SELECT Id FROM Task WHERE WhoId =: fromId]) {
				
				Task te = new Task(Id = t.Id, WhoId = toId);
				updateTask.add(te);
				
			}

			if(newMC != null) {	insert newMC; }
			
			if(updatePM.size() > 0) { update updatePM; }
			
			if(removePM.size() > 0) { delete removePM; }
			
			if(updateEvent.size() > 0) { update updateEvent; }
		
			if(updateTask.size() > 0) { update updateTask; }

			if(removeContact != null) { update removeContact; }

			if(updateContact != null) { update updateContact; }
			
			PageReference curPage = ApexPages.currentPage();
			ApexPages.Message confirmMSG = new ApexPages.message(ApexPages.Severity.CONFIRM, 'The Merge was Successful');
			ApexPages.addMessage(confirmMSG);
			curPage.setRedirect(true);
			return curPage;
			
		} else {
			
			PageReference curPage = ApexPages.currentPage();
			ApexPages.Message errorMSG = new ApexPages.message(ApexPages.Severity.ERROR, 'The selected Merge from Contact is outside of the Merge to Contact Home Office');
			ApexPages.addMessage(errorMSG);
			return curPage;
			
		}
		
	}

}

 

My question is two fold:

 

  1. Why is it saving regardless of my conditional statement?
  2. I'm assuming question one answers this, but why are my messages not showing?'

 

Thanks!

  • August 31, 2010
  • Like
  • 0

I'm trying to slim down the number of SOQL queries I run in a trigger.

 

I currently have these two loops for retrieving Tasks and Events for a Contact:

 

 

for (Event e : [SELECT Id FROM Event WHERE WhoId =: fromId]) {
				
	Event fe = new Event(Id = e.Id, WhoId = toId);
	updateEvent.add(fe);
				
}
			
for (Task t : [SELECT Id FROM Task WHERE WhoId =: fromId]) {
				
	Task te = new Task(Id = t.Id, WhoId = toId);
	updateTask.add(te);
				
}

 

 

They work just fine. However, as mentioned, I would like to reduce my SOQL #. I'd like to be able to run these queries using something like this:

 

 

for (Contact c : [SELECT (SELECT Id FROM Events), (SELECT Id FROM Tasks) FROM Contact WHERE Id =: fromId]) {
				
	Event fe = new Event(Id = c.Events.Id, WhoId = toId);
	updateEvent.add(fe);
				
			
	Task te = new Task(Id = c.Tasks.Id, WhoId = toId);
	updateTask.add(te);
				
}

 

 

Is this possible, and if so, how do I reference the Id fields for both Events and Tasks? I think I've done this somewhere else, I just can't find the example.

 

Thanks in advance,

 

Adriel

  • August 30, 2010
  • Like
  • 0

I need to pass a string from a form to my StandardSetController. So far what I'm doing is not working. I would appreciate any help. Thanks.

 

VF:

 

 

<apex:sectionHeader title="Zip Map" subtitle="Map Company/Branch by Zip" />
<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>
	
	<apex:pageBlock rendered="{!(zips != null) && (pages == 0)}">
		<apex:outputText value="Your search returned no values" />
	</apex:pageBlock>

	<apex:pageBlock title="Nearby Company/Branch" rendered="{!pages > 0}">
		<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>

	<apex:panelGrid columns="4" style="margin-bottom: 25px;" rendered="{!pages > 0}">
		<apex:commandLink action="{!first}" rendered="{!pages > 1}">First</apex:commandLink>
		<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
		<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
		<apex:commandLink action="{!last}" rendered="{!pages > 1}">Last</apex:commandLink>
	</apex:panelGrid>
</apex:form>

 

 

Controller:

 

 

public with sharing class zipMap {
	
	public String zips { get; set; }
	
	public PageReference find() {
		
		return null;
	
	}
	
	public ApexPages.StandardSetController accts {
		
		get {
			
			if(accts == null) {
			
				//List<String> zList;
				
				//zList = zips.split(',');	
				
				accts = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode =: zips ORDER BY BillingPostalCode, Name]));
				
				accts.setPageSize(2);
				
			}
				
			return accts;
			
		}
		
		set;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get {
			
			return accts.getHasNext();
			
		}
		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get {
			
			return accts.getHasPrevious();
			
		}
		
		set;
		
	}
	
	public Integer pageNumber {
		
		get {
			
			return accts.getPageNumber();
			
		}
		
		set;
		
	}

	public Integer pages {
		
		get {
		
			pages = accts.getResultSize()/accts.getPageSize();
			
			return pages;
			
		}
		
		set;
		
	}
	
	public void first() {
		
		accts.first();
		
	}
	
	public void last() {
		
		accts.last();
		
	}
	
	public PageReference previous() {
		
		Integer p = accts.getPageNumber();
		
		if(hasPrevious) {
		
			accts.setPageNumber(p-1);
		
		}
		
		return null;
		
	}
	
	public PageReference next() {
		
		Integer p = accts.getPageNumber();
		
		if(hasNext) {
		
			accts.setPageNumber(p+1);
		
		}
		
		return null;
		
	}

	public void cancel() {
		
		accts.cancel();
		
	}
}

 

 

  • August 23, 2010
  • Like
  • 0

I created a list button that opens a popup VF page which contains a form. After the form is saved, I want the popup to close and for the parent window to be refreshed. The refresh works great on FireFox and Chrome, but IE8 is somehow opening the parent window in a new window, instead of just refreshing the existing window. I've gone through various methods of opening a new window (window.showModalDialog, window.open, etc) and have settled on window.open() in my list button. I also found a great piece of code on the forum that returns values from my controller, closes my pop up and refreshes the parent window. 

 

Why is IE8 opening a new window instead of just refreshing the existing one?

 

List button javascript&colon;

 

window.open('/apex/quickCreateProduction?id={!Contact.Id}',"window","width=460, height=375");

 Javascript in VF page (popup):

 

<script language="javascript" type="text/javascript">
if("{!$Request.success}" == "true") {
	parent.window.close();
	parent.window.opener.location.href = "/{!$Request.id}";          
}
</script>

 

Save in custom controller (after success):

 

		PageReference curPage = ApexPages.currentPage();
		curPage.getParameters().put('success','true');
		curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
		curPage.setRedirect(true);
		return curPage;

 

I could definitely use some help. Thanks in advance.

 

Adriel

  • August 20, 2010
  • Like
  • 0

I can't seem to get the pagination to work. I've looked over various examples and my code looks good to me. I'm sure I'm missing something very obvious (at least to someone else) - please help.

 

Here's my controller class:

 

 

public with sharing class zipMap {

public String zips { get; set; }

public PageReference find() {

return null;

}

public ApexPages.StandardSetController accts {

get {

//List<String> zList = new List<String>();

//zList = zips.split(',');

accts = new ApexPages.StandardSetController(

Database.getQueryLocator(

[SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode = '10022' ORDER BY BillingPostalCode, Name]

)

);

accts.setPageSize(2);

return accts;

}

set;

}

public List<Account> getAccounts() {

return (List<Account>) accts.getRecords();

}

public Integer pages {

get {

pages = accts.getResultSize()/accts.getPageSize();

return pages;

}

set;

}

public Boolean hasNext {

get {

return accts.getHasNext();

}

set;

}

public Boolean hasPrevious {

get {

return accts.getHasPrevious();

}

set;

}

public Integer pageNumber {

get {

return accts.getPageNumber();

}

set;

}

public void first() {

accts.first();

}

public void last() {

accts.last();

}

public void previous() {

accts.previous();

}

public void next() {

accts.next();

}

public void cancel() {

accts.cancel();

}
}

 

 

VF:

 

 

<apex:page controller="zipMap" showHeader="false" sidebar="false" tabStyle="Account">
<apex:form >

<apex:pageBlock title="Search by Zip">
<apex:inputText value="{!zips}" />
<apex:commandButton value="Search" action="{!find}" />
</apex:pageBlock>

<apex:pageBlock title="Nearby Company/Branch">
<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
<apex:column headerValue="Company/Branch">
<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Address" colspan="2">
<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
</apex:column>
<apex:column >
<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:panelGrid columns="4">
<apex:commandLink action="{!first}" rendered="{!pages > 1}">First</apex:commandLink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
<apex:commandLink action="{!last}" rendered="{!pages > 1}">Last</apex:commandLink>
</apex:panelGrid>

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

 

 

Thanks!

 

Adriel

  • August 17, 2010
  • Like
  • 0

I have a page with a field for zip codes, that once submitted, will return a pageBlockTable with info. I'm having trouble returning a list once I submit. I'm new to StandardSetController and pagination. Any help would be much appreciated.

 

Here's my VF:

 

<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>
	<apex:pageBlock title="Nearby Company/Branch" rendered="{!zips != null}">
		<apex:pageBlockTable id="accountTable" value="{!accounts}" var="acct">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>
</apex:form>

 

Here's my controller class:

 

public with sharing class zipMap {

	public String zips { get; set; }
	
	public PageReference find() {
		
		return ApexPages.currentPage();
	
	}
	
	public ApexPages.StandardSetController accts {
		
		get {
			
			if(accts == null) {
				
				List<String> zList = zips.split(',');
				
				accts = new ApexPages.StandardSetController(
				
					Database.getQueryLocator(
					
						[SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode IN : zList ORDER BY BillingPostalCode, Name]
					
					)
				
				);
				
				accts.setPageSize(10);
				
			}
			
			return accts;
			
		}
		
		set;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get { return accts.getHasNext(); }		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get { return accts.getHasPrevious(); }
		set;
		
	}
	
	public Integer pageNumber {
		
		get { return accts.getPageNumber(); }
		set;
		
	}
	
	public void first() { accts.first(); }
	
	public void last() { accts.last(); }
	
	public void previous() { accts.previous(); }
	
	public void next() { accts.next(); }

}

 

 

Thanks in advance for your help.

 

Adriel

  • August 14, 2010
  • Like
  • 0

I have two multi select lists that I pass values back and forth using jQuery. When testing the values that are being passed from both lists, I receive "Conversion Error setting value" with the values from the select lists with spaces in between:

 

Conversion Error setting value 'a0BQ0000000y4KRMAY a0BQ0000000y4LAMAY' for '#{productionNumbers}'.
Conversion Error setting value 'a0BQ0000000y4LFMAY' for '#{selectedNumbers}'.

 

I need these values to run some SOQL queries and subsequent updates.   More specifically, these values (ids) will be used in:

 

Set<Id> newAvailable = new Set<Id>();
		
for (Production_No__c submitAvailable : [SELECT Id FROM Production_No__c WHERE Id IN : productionNumbers]) {
			
	newAvailable.add(submitAvailable.Id);
			
}


Set<Id> newSelected = new Set<Id>();
		
for (Production_No__c submitSelected : [SELECT Id FROM Production_No__c WHERE Id IN : selectedNumbers]) {
			
	newSelected.add(submitSelected.Id);
			
}

 

 

Here's their properties in the class:

 

public String[] productionNumbers {
		
	get; set;
		
}

public String[] selectedNumbers {
		
	get; set;
		
}

 

 

In the VF page, they're represented by:

 

<apex:selectList id="productionNumbers" styleClass="firstSelect" value="{!productionNumbers}" multiselect="true" size="4">
	<apex:selectOptions value="{!productionOptions}" />
</apex:selectList>


<apex:selectList id="selectedNumbers" styleClass="secondSelect" value="{!selectedNumbers}" multiselect="true" size="4">
	<apex:selectOptions value="{!selectedOptions}" />
</apex:selectList>

 

 

How do I go about retrieving this values for use in my loops? Thanks.

I've created a VF page that is integrated into our standard Contact layout. I have two multi select list boxes that are passed values back and forth using jquery. Passing a value from one to the other causes an error when I try to retrieve the value(s) of either list box.

 

The error shows the id of the list box in with the new passed values e.g. Error: j_id0:productionAdd:j_id3:productionSection:productionNumbers: Validation Error: Value is not valid

 

All the documentation I've seen to this point refers to multi select lists and Strings but the select options have Ids as values. Here is my extension class:

 

public with sharing class quickCreateProduction {
	
	private ApexPages.StandardController controller;
	
	public quickCreateProduction(ApexPages.StandardController controller) {
		
		this.controller = controller;
		
	}
	
	Id id = ApexPages.currentPage().getParameters().get('id');

	String[] productionNumbers = new String[]{};
	
	List<SelectOption> productionOptions = new List<SelectOption>();
	List<SelectOption> selectedOptions = new List<SelectOption>();

	ApexPages.Standardsetcontroller accBranch = new ApexPages.Standardsetcontroller(Database.getQueryLocator([SELECT Id FROM Contact WHERE Id =: id AND Account.RecordTypeId = '01230000000Q9p4AAC']));

	public Integer i {

		get { return accBranch.getResultSize(); }
		set { this.i = i; }
		
	}
	
	ApexPages.Standardsetcontroller ap = new ApexPages.Standardsetcontroller(Database.getQueryLocator([SELECT Id FROM Production_No__c WHERE Branch__c IN (SELECT AccountId FROM Contact WHERE Id =: id) AND Id NOT IN (SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: id)]));
	
	public Integer j {

		get { return ap.getResultSize(); }
		set { this.j = j; }
		
	}
	
	public List<SelectOption> getProductionOptions() {
		
		List<SelectOption> options = new List<SelectOption>();
		
		for (Production_No__c productionNo : [SELECT Id, Name, Branch__c FROM Production_No__c WHERE Branch__c IN (SELECT AccountId FROM Contact WHERE Id =: id) AND Id NOT IN (SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: id)]) {
			
			options.add(new SelectOption(productionNo.Id, productionNo.Name));
			
		}

		return options;
		
	}
	
	public void setProductionOptions(List<SelectOption> productionOptions) {
		
		this.productionOptions = productionOptions;
		
	}

	public String[] getProductionNumbers() {
		
		return productionNumbers;
	}
	
	public void setProductionNumbers(String[] productionNumbers) {
		
		this.productionNumbers = productionNumbers;
		
	}
	
	public List<SelectOption> getSelectedOptions() {
		
		List<SelectOption> options = new List<SelectOption>();
		
		for (Production_Member__c productionNo : [SELECT Production_No__c, Production_No__r.Name FROM Production_Member__c WHERE Contact__c =: id]) {
			
			options.add(new SelectOption(productionNo.Production_No__c, productionNo.Production_No__r.Name));
			
		}
		
		return options;
		
	}

	public void setSelectedOptions(List<SelectOption> selectedOptions) {
		
		this.selectedOptions = selectedOptions;
		
	}
	
	List<Id> selectedNumbers = new List<Id>();
	
	public List<Id> getSelectedNumbers() {
		
		return selectedNumbers;
	}
	
	public void setSelectedNumbers(List<Id> selectedNumbers) {
		
		this.selectedNumbers = selectedNumbers;
		
	}
	
	public String newProdNo {
		
		get { return newProdNo; }
		set { this.newProdNo = value; } 
		
	}
	
	public PageReference save() {
		
		ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO , 'Available: ' + productionNumbers + ' Selected: ' + selectedNumbers);
		ApexPages.addMessage(msg);

		return ApexPages.currentPage();
		
	}

}

 

VF:

 

<apex:page standardController="Contact" extensions="quickCreateProduction" showHeader="false" sidebar="false" tabStyle="Production_No__c">
<apex:includeScript value="{!$Resource.jQuery}" />
<script language="javascript" type="text/javascript">
$(document).ready(function(){

	$('#add').click(function () {
 		
 		$('.firstSelect :selected').appendTo('.secondSelect');
  			return false;


	});

	$('#remove').click(function () {
 		
 		$('.secondSelect :selected').appendTo('.firstSelect');
  			return false;


	});
	
	$('form').submit(function () {
	
		$('.firstSelect').each(function () { $('.firstSelect option').attr('selected', 'selected'); });
		
		$('.secondSelect').each(function () { $('.secondSelect option').attr('selected', 'selected'); });
	
	});

});
</script>
	<apex:form id="productionAdd" rendered="{!(i > 0)}">
		<apex:pageBlock >
			<apex:pageMessages />
			<apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:actionSupport event="onclick" rerender="productionNumbers" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="productionSection" title="Select Production Number(s) for Membership" rendered="{!(j > 0)}">
				<apex:outputLabel for="productionNumbers" value="Available Production No(s):" /><br />
				<apex:selectList id="productionNumbers" styleClass="firstSelect" value="{!productionNumbers}" multiselect="true" size="4">
					<apex:selectOptions value="{!productionOptions}" />
				</apex:selectList>
				<button id="add" class="btn" type="button">&#62;</button><br />
				<button id="remove" class="btn" type="button">&#60;</button><br />
				<apex:outputLabel for="selectedNumbers" value="Selected Production No(s):" /><br />
				<apex:selectList id="selectedNumbers" styleClass="secondSelect" value="{!selectedNumbers}" multiselect="true" size="4">
					<apex:selectOptions value="{!selectedOptions}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection id="productionNew" title="Create Production Number for Membership">
				<apex:outputLabel for="newProdNo" value="New Production No*:" title="" /><br />
				<apex:inputText value="{!newProdNo}" /><br />
				<apex:outputText style="font-style: italic; font-size: 10px;" value="*Enter a new Production Number to this Contact and associated Branch. This will also create a Production Membership" /><br />
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

 I have tried to define selectedNumbers just like productionNumbers without any success.

 

The only other thing I can think of is that the jquery isn't passing the correct values, but when I change the get/set for either the productionNumbers or selectedNumbers variable using automatic properties e.g. get; set; I get a similar error, like:

 

Error: Conversion Error setting value 'a0BQ0000000y4KRMAY a0BQ0000000y4LAMAY a0BQ0000000y4LFMAY' for '#{productionNumbers}'.

 

I may be wrong, but that shows that the jquery is passing the correct Id values. I know they're not comma separated, but is that really the problem?

 

Thanks in advance for your help

I'm receiving the message "Content cannot be displayed: List index out of bounds: 0" .

 

I have a selectlist whose List<SelectOption> is coming up empty. In the event it does come up empty, I would like to pass my own message through the VF page, something to the effect of "No Production Numbers currently available". How do I do that?

 

Piece of form in question:

<apex:selectList id="productionNumbers" value="{!productionNumbers}" multiselect="true" size="4">
    <apex:selectOptions value="{!productionOptions}" />
</apex:selectList>

 Controller:

String[] productionNumbers = new String[]{};

List<Production_No__c> availableProd = [SELECT Id, Name, Branch__c FROM Production_No__c WHERE Branch__c IN : accId AND Id NOT IN : selectedProd];

public List<SelectOption> getProductionOptions() {
		
    List<SelectOption> options = new List<SelectOption>();
		
    for (Production_No__c productionNo : availableProd) {
			
	options.add(new SelectOption(productionNo.Id, productionNo.Name));
			
    }
		
    return options;
		
}
	
public String[] getProductionNumbers() {
		
    return productionNumbers;

}
	
public void setProductionNumbers(String[] productionNumbers) {
		
    this.productionNumbers = productionNumbers;
		
}

 

Thank you!

Through some customizations, we have modified the Account object to either have a recordtype of Company or Branch. In the event that an Account has a recordtype of Branch, we populate a custom field named Home_Office__c with the Company's ID (Account ID). As part of a larger contact validation trigger, I am trying to grab the IDs of all the Branches whose Home_Office__c falls within a certain Set. 

 

Here's the excerpt of my trigger where I create a Set of Home_Office__c from the Triggers Account:

 

Set<ID> homeID = new Set<ID>();
				
for (Account a : [SELECT Home_Office__c FROM Account WHERE Id =: accID AND Home_Office__c != null]) {
					
homeID.add(a.Home_Office__c);
					
}

 

Here's the excerpt where I create a Set of Account IDs that fall within the Home_Office__c set:

 

Set<ID> branchID = new Set<ID>();
				
for (Account a : [SELECT Id FROM Account WHERE Home_Office__c IN : homeID]) {
					
branchID.add(a.Id);

}

 

FYI - I split these values over two sets becausing I'm mapping contact names first from the parent company and then from all the branches. 

 

The first set will rarely ever be larger than 1 row, with the branch set reaching a size of around 600. However, it is the branch set that is causing the System.Exception: Too many query rows: 1001.

 

I thought I had thoroughly tested this in our Sandbox, but only when I deployed the trigger to production did I run across this error. I have since updated our Sandbox to reflect records similar to production, and through testing, the only conclusion I can come to is that the second query is grabbing all Account IDs; not just ones with a valid Home_Office__c value.

 

Any idea of why this may be happening? I've avoided including the entire trigger since it all had worked fine before, but if necessary I'll post it. Thanks in advance.

 

Adriel

I've attempted to create a before delete trigger on the Contact object that will disallow deletion if an Activity (Event or Task) exists for that Contact. If there are no Activities, the Contact will be deleted, along with any associated Production Memberships (custom object). The trigger works on an individual basis using the UI, but I'm not returning the expected amount of rows after deletion in my test class. Unfortunately, I'm too green to know if the error lies in my trigger or my test. Any help would be appreciated. Thanks!

 

Here's my trigger:

 

trigger beforeContactDelete on Contact (before delete) {

	//Create Set of Contacts from trigger
	
	Set<ID> contactIDs = new Set<ID>();
	
	for (Contact c : Trigger.old) {
		
		contactIDs.add(c.ID);

	}

	//All activities tied to a Contact in the trigger
	
	Set<ID> allActivities = new Set<ID>();
	
	for (Event e : [SELECT WhoId FROM Event WHERE WhoId IN : contactIDs]) {
		
		allActivities.add(e.WhoId);
		
	}
	
	for (Task t : [SELECT WhoId FROM Task WHERE WhoId IN : contactIDs]) {
		
		allActivities.add(t.WhoId);
		
	}
	
	//All Contacts with activities
	
	Set<ID> dirtyContacts = new Set<ID>();

	for (Contact c : [SELECT ID FROM Contact WHERE ID IN : allActivities]) {
		
		dirtyContacts.add(c.ID);
			
	}
	
	//Create set of Contacts from trigger without activities
	
	Set<ID> cleanContacts = new Set<ID>();
	
	cleanContacts.addAll(contactIDs);
	cleanContacts.removeAll(dirtyContacts);
	
	//Create List of Production Memberships tied to a clean Contact
	
	List<Production_Member__c> productionMemberships = [SELECT ID FROM Production_Member__c WHERE Contact__c IN : cleanContacts];
	
	//Delete the contact and the Production Member
	
 	for (Contact c : Trigger.old) {
 		
 		if(Trigger.isBefore) {
 		
	 		if(Trigger.isDelete) {
	 			
	 			if(dirtyContacts.containsAll(Trigger.oldMap.keySet())) {
	 				
	 				c.addError('This contact has an activity and therefore cannot be deleted');
	 				
	 			} else if(cleanContacts.containsAll(Trigger.oldMap.keySet())) {
	 				
	 				if(productionMemberships != null) {
	 					
	 					delete productionMemberships;
	 					
	 				}
	 				
	 			}

	 		}
 		
 		}
 		
 	}

}

 

Here's the test class:

 

@isTest
private class testBeforeContactDelete {

    static testMethod void bulkContactDeleteTest() {

		//Create the list of contacts to test delete
		
		List<Contact> testContacts = [SELECT ID FROM Contact WHERE Account.Name = 'contactTest'];
		
		//Start Contact Delete Trigger
		
		Test.startTest();
		
		delete testContacts;
		
		Test.stopTest();
		
		//Check for desired results
		
		List<Contact> deletedContacts = [SELECT ID FROM Contact WHERE Account.Name = 'contactTest'];

		List<Production_Member__c> deletedPMs = [SELECT ID FROM Production_Member__c WHERE Contact__r.Account.Name = 'contactTest'];

    }
}

 

  • April 12, 2010
  • Like
  • 0

I need to create a list of distinct Contact Ids from Contacts that have an Event or Task tied to them within a time period. I know one way to create a distinct list is to grab the WhoIds from Event and Task and add them to a Set<Id> like:

 

 

Set<Id> contactSet = new Set<Id>();
for (Event e : [SELECT WhoId FROM Event WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate]) {
	contactSet.add(e.WhoId);
}
for (Task t : [SELECT WhoId FROM Task WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate]) {
	contactSet.add(t.WhoId);
}

 

 

The problem with this is that either loop could retrieve 'Too many query rows'. I could group by WhoId in either one, making an AggregateResult, but with a large enough set of Contacts, I'd run across the queryMore() limitation with AggregateResult.

 

So, I figured I'd try to run a query on Contact with Event and Task subqueries like:

 

 

SELECT Id, (SELECT Id FROM Tasks WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate), (SELECT Id FROM Events WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate) FROM Contact

 

 

How would I populate my Set<Id> contactSet with the Contact Ids where the Task or Event subquery does not equal null?

 

Thanks, I appreciate the help.

 

A

  • October 18, 2010
  • Like
  • 0

I've got a VF page with some links to other VF pages. I'd like for a link to render only if that user's profile has been enabled to access the link's page. How do I do that?

 

Thanks in advance.

  • September 27, 2010
  • Like
  • 0

I need to use the value from an inputField to populate a variable in a wrapper class. How do I that?

 

Controller:

 

 

//Variable for input
public String duration { get; set; }

//Wrapper class needing variable

public class TotalTerr {
		
	public String TerritoryName { get; set; }
	
	//Class variable that needs input
	public String Duration { get; set; }

}

 

I could really use the help - thanks in advance!

 

  • September 17, 2010
  • Like
  • 0

I'm attempting to created a VF page that takes a zip (or series of zips) and create a paginated list of related Accounts. I'm having issues retrieving the data, namely receiving the Attempt to de-reference a null object error.

 

Here's my VF:

 

<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>

	<apex:pageBlock title="Nearby Company/Branch" rendered="{!zips != null}">
		<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>

	<apex:panelGrid columns="4" style="margin-bottom: 25px;" rendered="{!zips != null}">
		<apex:commandLink action="{!first}" rendered="{!(pages > 1) && (hasPrevious)}">First</apex:commandLink>
		<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
		<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
		<apex:commandLink action="{!last}" rendered="{!(pages > 1) && (hasNext)}">Last</apex:commandLink>
	</apex:panelGrid>
</apex:form>

 

Here's my controller class:

 

 

public with sharing class zipMap {
	
	public String zips { get; set; }
	
	public List<String> zList { get; set; }
	
	public ApexPages.StandardSetController accts { get; set; }
	
	public PageReference find() {

		zList = zips.split(',');

		String query = 'SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode =: ' + zList + ' ORDER BY BillingPostalCode, Name';
		
		accts = new ApexPages.StandardSetController(Database.getQueryLocator(query));
		accts.setPageSize(2);
		
		return null;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get {
			
			return accts.getHasNext();
			
		}
		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get {
			
			return accts.getHasPrevious();
			
		}
		
		set;
		
	}
	
	public Integer pageNumber {
		
		get {
			
			return accts.getPageNumber();
			
		}
		
		set;
		
	}

	public Integer pages {
		
		get {
		
			pages = accts.getResultSize()/accts.getPageSize();
			
			return pages;
			
		}
		
		set;
		
	}
	
	public void first() { accts.first(); }
	
	public void last() { accts.last(); }

	public void cancel() { accts.cancel(); }
		
	public PageReference previous() {
		
		Integer p = accts.getPageNumber();
		
		if(hasPrevious) {
		
			accts.setPageNumber(p-1);
		
		}
		
		return null;
		
	}
	
	public PageReference next() {
		
		Integer p = accts.getPageNumber();
		
		if(hasNext) {
		
			accts.setPageNumber(p+1);
		
		}
		
		return null;
		
	}

}

 

 

Can someone please help? Thanks

 

Adriel

  • September 09, 2010
  • Like
  • 0

I created a controller extension to replace the standard "New" record for a custom object. The save and all subsequent updates are working, however, my conditional statement is not working, saving regardless.

 

Here is my VF:

 

<apex:page standardController="Merged_Contact__c" extensions="mergeContact" tabStyle="Merged_Contact__c">
<apex:sectionHeader title="Merging Contacts" subtitle="Merge a Contact's Information to Another" />
<apex:form >
	<apex:pageMessages />
	<apex:pageBlock mode="edit">
		<apex:pageBlockButtons >
			<apex:commandButton action="{!mergeSave}" value="Save" />
		</apex:pageBlockButtons>
		<apex:pageBlockSection title="Select Contacts">
			<apex:inputField value="{!Merged_Contact__c.Merge_to_Contact__c}" required="true" />
			<apex:inputField value="{!Merged_Contact__c.Merge_from_Contact__c}" required="true" />
		</apex:pageBlockSection>
		<apex:pageBlockSection title="Select Optional Fields to Merge">
			<apex:inputField value="{!Merged_Contact__c.Title__c}" />
			<apex:inputField value="{!Merged_Contact__c.Phone__c}" />
			<apex:inputField value="{!Merged_Contact__c.Email__c}" />
			<apex:inputField value="{!Merged_Contact__c.Mobile__c}" />
			<apex:inputField value="{!Merged_Contact__c.Address__c}" />
			<apex:inputField value="{!Merged_Contact__c.Other_Phone__c}" />
			<apex:inputField value="{!Merged_Contact__c.Assistant__c}" />
			<apex:inputField value="{!Merged_Contact__c.Fax__c}" />
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:form>
</apex:page>

 

 Here's my extension:

 

public with sharing class mergeContact {
	
	public Merged_Contact__c mc;
	
	ApexPages.StandardController stdController;

	public mergeContact(ApexPages.StandardController controller) {
		
		stdController = controller;
		this.mc = (Merged_Contact__c)stdController.getRecord();
		
	}
	
	public PageReference mergeSave() {

		Id toId;
		Id fromId;
		Id toHomeId;
		Id fromHomeId;
	
		Boolean title;
		Boolean email;
		Boolean address;
		Boolean assistant;
		Boolean phone;
		Boolean mobile;
		Boolean otherPhone;
		Boolean fax;
		
		Merged_Contact__c newMC;
		Contact fromContact;
		Contact updateContact;
		Contact removeContact;
	
		Set<Id> newPN = new Set<Id>();
		
		List<Contact> toHome = new List<Contact>();
		List<Contact> fromHome = new List<Contact>();
		List<Production_Member__c> updatePM = new List<Production_Member__c>();
		List<Production_Member__c> removePM = new List<Production_Member__c>();
		List<Event> updateEvent = new List<Event>();
		List<Task> updateTask = new List<Task>();

		toId = mc.Merge_to_Contact__c;
		fromId = mc.Merge_from_Contact__c;
	
		toHome = [SELECT Account.ParentId FROM Contact WHERE Id =: toId];
		toHomeId = toHome[0].Account.ParentId;
		
		fromHome = [SELECT Account.ParentId FROM Contact WHERE Id =: fromId];
		fromHomeId = fromHome[0].Account.ParentId;
		
		if(toHomeId == fromHomeId) {
			
			newMC = new Merged_Contact__c(Merge_to_Contact__c = mc.Merge_to_Contact__c, Merge_from_Contact__c = mc.Merge_from_Contact__c, Title__c = mc.Title__c, Phone__c = mc.Phone__c, Email__c = mc.Email__c, Mobile__c = mc.Mobile__c, Address__c = mc.Address__c, Other_Phone__c = mc.Other_Phone__c, Assistant__c = mc.Assistant__c, Fax__c = mc.Fax__c);
			
			title = mc.Title__c;
			email = mc.Email__c;
			address = mc.Address__c;
			assistant = mc.Assistant__c;
			phone = mc.Phone__c;
			mobile = mc.Mobile__c;
			otherPhone = mc.Other_Phone__c;
			fax = mc.Fax__c;
			
			if(title || email || address || assistant || phone || mobile || otherPhone || fax) {
				
				fromContact = [SELECT Id, Title, Email, MailingStreet, MailingCity, MailingState, MailingPostalCode, AssistantName, Phone, MobilePhone, OtherPhone, Fax FROM Contact WHERE Id =: fromId];
				updateContact = [SELECT Id, Title, Email, MailingStreet, MailingCity, MailingState, MailingPostalCode, AssistantName, Phone, MobilePhone, OtherPhone, Fax FROM Contact WHERE Id =: toId];
				
				if(title) { updateContact.Title = fromContact.Title; }
				if(email) { updateContact.Email = fromContact.Email; }
				if(address) { updateContact.MailingStreet = fromContact.MailingStreet; }
				if(address) { updateContact.MailingCity = fromContact.MailingCity; }
				if(address) { updateContact.MailingState = fromContact.MailingState; }
				if(address) { updateContact.MailingPostalCode = fromContact.MailingPostalCode; }
				if(assistant) { updateContact.AssistantName = fromContact.AssistantName; }
				if(phone) { updateContact.Phone = fromContact.Phone; }
				if(mobile) { updateContact.MobilePhone = fromContact.MobilePhone; }
				if(otherPhone) { updateContact.OtherPhone = fromContact.OtherPhone; }
				if(fax) { updateContact.Fax = fromContact.Fax; }
				
			}
	
			removeContact = new Contact(Id = fromId, Active__c = False);
				
			for(Production_Member__c fpm : [SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: fromId]){
				
				newPN.add(fpm.Production_No__c);
				
			}
		
			for(Production_Member__c tpm : [SELECT Production_No__c FROM Production_Member__c WHERE Contact__c =: toId]){
				
				newPN.remove(tpm.Production_No__c);
				
			}
			
			for(Production_Member__c upm : [SELECT Id FROM Production_Member__c WHERE Contact__c =: fromId AND Production_No__c IN : newPN]){
				
				Production_Member__c pm = new Production_Member__c(Id = upm.Id, Contact__c = toId);
				updatePM.add(pm);
				
			}
		
			for(Production_Member__c rpm : [SELECT Id FROM Production_Member__c WHERE Contact__c =: fromId AND Production_No__c NOT IN : newPN]){
				
				Production_Member__c pm = new Production_Member__c(Id = rpm.Id);
				removePM.add(pm);
				
			}
		
			for (Event e : [SELECT Id FROM Event WHERE WhoId =: fromId]) {
				
				Event fe = new Event(Id = e.Id, WhoId = toId);
				updateEvent.add(fe);
				
			}
			
			for (Task t : [SELECT Id FROM Task WHERE WhoId =: fromId]) {
				
				Task te = new Task(Id = t.Id, WhoId = toId);
				updateTask.add(te);
				
			}

			if(newMC != null) {	insert newMC; }
			
			if(updatePM.size() > 0) { update updatePM; }
			
			if(removePM.size() > 0) { delete removePM; }
			
			if(updateEvent.size() > 0) { update updateEvent; }
		
			if(updateTask.size() > 0) { update updateTask; }

			if(removeContact != null) { update removeContact; }

			if(updateContact != null) { update updateContact; }
			
			PageReference curPage = ApexPages.currentPage();
			ApexPages.Message confirmMSG = new ApexPages.message(ApexPages.Severity.CONFIRM, 'The Merge was Successful');
			ApexPages.addMessage(confirmMSG);
			curPage.setRedirect(true);
			return curPage;
			
		} else {
			
			PageReference curPage = ApexPages.currentPage();
			ApexPages.Message errorMSG = new ApexPages.message(ApexPages.Severity.ERROR, 'The selected Merge from Contact is outside of the Merge to Contact Home Office');
			ApexPages.addMessage(errorMSG);
			return curPage;
			
		}
		
	}

}

 

My question is two fold:

 

  1. Why is it saving regardless of my conditional statement?
  2. I'm assuming question one answers this, but why are my messages not showing?'

 

Thanks!

  • August 31, 2010
  • Like
  • 0

I'm trying to slim down the number of SOQL queries I run in a trigger.

 

I currently have these two loops for retrieving Tasks and Events for a Contact:

 

 

for (Event e : [SELECT Id FROM Event WHERE WhoId =: fromId]) {
				
	Event fe = new Event(Id = e.Id, WhoId = toId);
	updateEvent.add(fe);
				
}
			
for (Task t : [SELECT Id FROM Task WHERE WhoId =: fromId]) {
				
	Task te = new Task(Id = t.Id, WhoId = toId);
	updateTask.add(te);
				
}

 

 

They work just fine. However, as mentioned, I would like to reduce my SOQL #. I'd like to be able to run these queries using something like this:

 

 

for (Contact c : [SELECT (SELECT Id FROM Events), (SELECT Id FROM Tasks) FROM Contact WHERE Id =: fromId]) {
				
	Event fe = new Event(Id = c.Events.Id, WhoId = toId);
	updateEvent.add(fe);
				
			
	Task te = new Task(Id = c.Tasks.Id, WhoId = toId);
	updateTask.add(te);
				
}

 

 

Is this possible, and if so, how do I reference the Id fields for both Events and Tasks? I think I've done this somewhere else, I just can't find the example.

 

Thanks in advance,

 

Adriel

  • August 30, 2010
  • Like
  • 0

I need to pass a string from a form to my StandardSetController. So far what I'm doing is not working. I would appreciate any help. Thanks.

 

VF:

 

 

<apex:sectionHeader title="Zip Map" subtitle="Map Company/Branch by Zip" />
<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>
	
	<apex:pageBlock rendered="{!(zips != null) && (pages == 0)}">
		<apex:outputText value="Your search returned no values" />
	</apex:pageBlock>

	<apex:pageBlock title="Nearby Company/Branch" rendered="{!pages > 0}">
		<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>

	<apex:panelGrid columns="4" style="margin-bottom: 25px;" rendered="{!pages > 0}">
		<apex:commandLink action="{!first}" rendered="{!pages > 1}">First</apex:commandLink>
		<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
		<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
		<apex:commandLink action="{!last}" rendered="{!pages > 1}">Last</apex:commandLink>
	</apex:panelGrid>
</apex:form>

 

 

Controller:

 

 

public with sharing class zipMap {
	
	public String zips { get; set; }
	
	public PageReference find() {
		
		return null;
	
	}
	
	public ApexPages.StandardSetController accts {
		
		get {
			
			if(accts == null) {
			
				//List<String> zList;
				
				//zList = zips.split(',');	
				
				accts = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode =: zips ORDER BY BillingPostalCode, Name]));
				
				accts.setPageSize(2);
				
			}
				
			return accts;
			
		}
		
		set;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get {
			
			return accts.getHasNext();
			
		}
		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get {
			
			return accts.getHasPrevious();
			
		}
		
		set;
		
	}
	
	public Integer pageNumber {
		
		get {
			
			return accts.getPageNumber();
			
		}
		
		set;
		
	}

	public Integer pages {
		
		get {
		
			pages = accts.getResultSize()/accts.getPageSize();
			
			return pages;
			
		}
		
		set;
		
	}
	
	public void first() {
		
		accts.first();
		
	}
	
	public void last() {
		
		accts.last();
		
	}
	
	public PageReference previous() {
		
		Integer p = accts.getPageNumber();
		
		if(hasPrevious) {
		
			accts.setPageNumber(p-1);
		
		}
		
		return null;
		
	}
	
	public PageReference next() {
		
		Integer p = accts.getPageNumber();
		
		if(hasNext) {
		
			accts.setPageNumber(p+1);
		
		}
		
		return null;
		
	}

	public void cancel() {
		
		accts.cancel();
		
	}
}

 

 

  • August 23, 2010
  • Like
  • 0

I created a list button that opens a popup VF page which contains a form. After the form is saved, I want the popup to close and for the parent window to be refreshed. The refresh works great on FireFox and Chrome, but IE8 is somehow opening the parent window in a new window, instead of just refreshing the existing window. I've gone through various methods of opening a new window (window.showModalDialog, window.open, etc) and have settled on window.open() in my list button. I also found a great piece of code on the forum that returns values from my controller, closes my pop up and refreshes the parent window. 

 

Why is IE8 opening a new window instead of just refreshing the existing one?

 

List button javascript&colon;

 

window.open('/apex/quickCreateProduction?id={!Contact.Id}',"window","width=460, height=375");

 Javascript in VF page (popup):

 

<script language="javascript" type="text/javascript">
if("{!$Request.success}" == "true") {
	parent.window.close();
	parent.window.opener.location.href = "/{!$Request.id}";          
}
</script>

 

Save in custom controller (after success):

 

		PageReference curPage = ApexPages.currentPage();
		curPage.getParameters().put('success','true');
		curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
		curPage.setRedirect(true);
		return curPage;

 

I could definitely use some help. Thanks in advance.

 

Adriel

  • August 20, 2010
  • Like
  • 0

Can anyone point me in the right direction.

 

Background

 

I am working with a non-profit who need to record sightings of animals using GPS coordinates.  I have created a sightings object and have integrated a google map on the page using visualforce which pulls through the GPS data and adds a marker, code below.

 

I now want to show a map of all of the sightings for a particular animal. So I have created a parent object called wildlife which is simply the name of the animal and some other meta data.

 

Problem

 

The sightings object has a lookup to wildlife.  So if you were to lookup an animal on the wildlife object you would see a number of sightings.  I would like a map on the wildlife object that would show all of the related sightings as markers.

 

Code

 

This is the code for the single sightings map on the sightings object.

 

 

<apex:page standardController="Sighting__c">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAARQVi0nDV8_SJqZY8mkksjBQW4dj6q0E-oPzXa2fArCvhLhZBwBSQtm6TiVKHbHEvo8Jcr3_JN01Ubg" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var address = "{!Sighting__c.Long__c}, {!Sighting__c.Lat__c}";
function initialize() {
if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map_canvas"));
  map.addControl(new GSmallMapControl());
  map.setMapType(G_HYBRID_MAP);
  geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        document.getElementById("map_canvas").innerHTML = address + " not found";
      } else {
        map.setCenter(point, 16);
        var marker = new GMarker(point);        
        map.addOverlay(marker);
        marker.bindInfoWindowHtml("{!Sighting__c.Wildlife__r.Name__c} the {!Sighting__c.Wildlife__r.Type__c}<br /> Sighting Number: {!Sighting__c.Name}<br />{!Sighting__c.Date__c}");
      }
    }
  );
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width:100%;height:300px"></div>
</body>
</html>
</apex:page>

 

 

 

 

I can't seem to get the pagination to work. I've looked over various examples and my code looks good to me. I'm sure I'm missing something very obvious (at least to someone else) - please help.

 

Here's my controller class:

 

 

public with sharing class zipMap {

public String zips { get; set; }

public PageReference find() {

return null;

}

public ApexPages.StandardSetController accts {

get {

//List<String> zList = new List<String>();

//zList = zips.split(',');

accts = new ApexPages.StandardSetController(

Database.getQueryLocator(

[SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode = '10022' ORDER BY BillingPostalCode, Name]

)

);

accts.setPageSize(2);

return accts;

}

set;

}

public List<Account> getAccounts() {

return (List<Account>) accts.getRecords();

}

public Integer pages {

get {

pages = accts.getResultSize()/accts.getPageSize();

return pages;

}

set;

}

public Boolean hasNext {

get {

return accts.getHasNext();

}

set;

}

public Boolean hasPrevious {

get {

return accts.getHasPrevious();

}

set;

}

public Integer pageNumber {

get {

return accts.getPageNumber();

}

set;

}

public void first() {

accts.first();

}

public void last() {

accts.last();

}

public void previous() {

accts.previous();

}

public void next() {

accts.next();

}

public void cancel() {

accts.cancel();

}
}

 

 

VF:

 

 

<apex:page controller="zipMap" showHeader="false" sidebar="false" tabStyle="Account">
<apex:form >

<apex:pageBlock title="Search by Zip">
<apex:inputText value="{!zips}" />
<apex:commandButton value="Search" action="{!find}" />
</apex:pageBlock>

<apex:pageBlock title="Nearby Company/Branch">
<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
<apex:column headerValue="Company/Branch">
<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Address" colspan="2">
<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
</apex:column>
<apex:column >
<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:panelGrid columns="4">
<apex:commandLink action="{!first}" rendered="{!pages > 1}">First</apex:commandLink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
<apex:commandLink action="{!last}" rendered="{!pages > 1}">Last</apex:commandLink>
</apex:panelGrid>

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

 

 

Thanks!

 

Adriel

  • August 17, 2010
  • Like
  • 0

I tried my best searching for something like this. Sorry if this is a respost.

 

I've got this inline visualforce page embedded in my Opportunity Page. Does anyone know how to get rid of the border that's produced when using this code below. The pageblock adds the a border that the title would typically sit inside. I want to be able to use the pageblock tag without having any borders. Can I get rid of those yellow borders ? Thanks in adv

 

<apex:page standardController="opportunity" extensions="OppSearchExt" >

<apex:form>
        <apex:pageBlock mode="edit"  >

        </apex:pageBlock>

</apex:form >

</page>

 

I am using hte example from the developer guide below:

 

<apex:page standardController="Account" recordSetvar="accounts">
  <apex:pageBlock title="Viewing Accounts">
  <apex:form id="theForm">
    <apex:panelGrid columns="2">
      <apex:outputLabel value="View:"/>
      <apex:selectList value="{!filterId}" size="1">
        <apex:actionSupport event="onchange" rerender="list"/>
        <apex:selectOptions value="{!listviewoptions}"/>
      </apex:selectList>
    </apex:panelGrid>
    <apex:pageBlockSection >
      <apex:dataList var="a" value="{!accounts}" id="list">
        {!a.name}
      </apex:dataList>
    </apex:pageBlockSection>
  </apex:form> 
  </apex:pageBlock>
</apex:page>

 I have a list view defined that use the criteria "Partner Account is not empty". When I select this list view in my visual force page I get the following error:

 

LastName FROM Account WHERE (((ACCOUNT.IS_PARNTER != FALSE))) ^ ERROR at Row:1:Column:106 No such column 'IS_PARNTER' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

 

hello,

 

i am new to visual force and apex and will appreciate the help on below.

 

i created a table in VF and retrieving the data like consultants , no of project and no of tasks from from the controller. its working fine but i need to click one of the consultants from the list above to get the detail report on the other page. i am trying to pass some parameters once "Onclick" function is performed but its returning null when i am clikcing on one of the consultant to get the reports on new page. below is my VF page.

 

Visual Force Page :

 

<apex:page controller="Consultant_Information">

<script type="text/javascript">
      function loadReports(Alias){
        if(typeof AF_LoadReports  == "function") {AF_LoadReports(Alias);}
      }
  </script>


  <apex:form >
  <apex:actionFunction name="AF_LoadReports" action="{!loadReports}" >
  <apex:param name="Alias" assignTo="{!Alias1}" value="" />    
  </apex:actionFunction>
  <apex:pageBlock title="Consultant Summary" >
  <apex:PageBlockSection columns="1" >
 <apex:pageBlockTable value="{!Items}" var="item">

 
<apex:column headerValue="Consultant" value="{!item.theUser.Name}" onclick="javascript&colon;AF_LoadReports('{!item.theUser.Alias}')"/>
<apex:column headerValue="Department" value="{!item.theUser.Division}"/>
<apex:column headerValue="Active Projects" value="{!item.noProjects}"/>
<apex:column headerValue="Active Tasks" value="{!item.noTasks}"/>
<apex:column headerValue="Last Login Date" value="{!item.theUser.LastLoginDate}"/>
</apex:pageBlockTable>
  </apex:PageBlockSection>
 
 
 
 
  
   
       
     </apex:pageBlock>

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

 

 

 

and below is my controler

 

public with sharing class Consultant_Information {
 public Consultant_Information(){
  loadConsultants();
 }
 
 public class userWrap{
                public User theUser{get;set;}
                public integer noProjects{get;set;}
                public integer noTasks{get;set;}
             
   }
public PageReference loadReports(){  
 String Alias1 =ApexPages.currentPage().getParameters().get('Alias');
 PageReference pageRef = new PageReference('https://c.na7.visual.force.com/apex/pConsultantSummary?Alias'+'='+Alias1);                    
  pageRef.setRedirect(true);
 
  return pageRef;
  }
 
public List<userWrap> listConsultant = new list<userWrap>();
  
public List<userWrap> getItems() {return listConsultant;}
 
 private void loadConsultants(){ 
 listConsultant.clear();
 List<User> users = new List<User>([Select u.Name, u.Id, u.Alias, u.Division, u.LastLoginDate From User u where u.IT_User__c = true and u.IsActive = true order by u.Name]);
 List<AggregateResult> Projects = new List<AggregateResult>([Select count(p.Id) noProjects, p.OwnerId from Project__c p where p.Project_Life_Cycle_Stages_2__c <> 'Closed' group by p.OwnerId]);
 List<AggregateResult> Tasks = new List<AggregateResult>([Select count(t.Id) noTasks, t.OwnerId from Task__c t where t.Task_Status__c <> 'Closed' group by t.OwnerId]);

 for(User u : users){
  userWrap wrap = new userWrap();
  wrap.theUser = u;
   for(AggregateResult r : projects){
   if(r.get('OwnerId') == u.Id){wrap.noProjects = (r.get('noProjects')==null?0: integer.valueOf(r.get('noProjects'))) ;}
  }
  for(AggregateResult r : tasks){
   if(r.get('OwnerId') == u.Id){wrap.noTasks = (r.get('noTasks')==null?0: integer.valueOf(r.get('noTasks')));}
  }
  listConsultant.add(wrap);
  }
  
 }
  
}