function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Joseph BaroneJoseph Barone 

VisualForce Page and Controller work in sandbox, but fails in production

I've created a small VF Page and Controller that exports Events pertaining to a specific Account.  The detailed link is on the Account Page and when clicked, passes the account.id to the Controller.  The Controller then references the EventRelation table and queries all the EventIDs to get all the Event Information and lists this on the Visual Force Page.  The VF page is set to automatically export into Excel.  

In my partial sandbox, all of the coding and testing works great.  The results are exactly what I'm expecting to get. 

However, when I deploy into production, I run into an issue.  It deploys perfectly and when I click the the detailed link on the Accounts Page, I get an error saying there are Zero Rows to select.  

I put in system.debugs to trace and also exported all EventRelations using Data Loader.  In my debug, I can see the EventID being referenced existing in the EventRelations table.  I've event copied the EventID and pasted into the browser and it took me to the correct event.  Ultimately, I'm trying to figure out why the query is returning zero results only in production.  

Any help is greatly appreciated!

Here is the controller code:
 
public class ActivitiesbyAccountController {

    public string idCurrentEvent {get;set;}
    Public Event evententry;
    Public List <EventRelation> eventconnect;
    Public List <Event> selected {get;set;}
    
    
    public ActivitiesbyAccountController(ApexPages.StandardController Account)
    {
        
        idCurrentEvent = ApexPages.currentPage().getParameters().get('id');
        system.debug(idCurrentEvent);
        
        selected=new list<Event>();
        
        eventconnect = [Select ID, relationid, eventid FROM EventRelation Where accountid = :idCurrentEvent];
        system.debug(eventconnect.size());
        system.debug(eventconnect);
        for(integer i=0;i<eventconnect.size();i++)
        {
         	system.debug('inside for loop');
            system.debug(i);
            system.debug(eventconnect.get(i).relationid +' ' + idCurrentEvent);
            if(eventconnect.get(i).relationid != idCurrentEvent)
       			  {
             		system.debug('inside if statement');
                      Event newevent = new Event();
          			string tempeventid = eventconnect.get(i).eventid;
					system.debug(tempeventid);            
          			newevent = [Select ID, OwnerID, subject, purpose_of_meeting__c, ActivityDate,WhatID From Event WHERE id = :tempeventid];
          			newevent.whoid = eventconnect.get(i).relationid;  
      				system.debug(newevent);
        			selected.add(newevent);  
        		 }
            
         }
     }
}


 
Best Answer chosen by Joseph Barone
Abhishek BansalAbhishek Bansal
Hi Joseph,

Your code looks absolutely fine as you are not using any hard coded ids.
The only possible reason for this error is the EventRelation are not properly linked to the respective accounts.
As you are using where condtion in query as "Select ID, relationid, eventid FROM EventRelation Where accountid =:idCurrentEvent" 
So the reason that query does not return any row is Your EventRelation data is not correctly mapped to Account.

You also mentioned that you have imported EventRelation through data loader.
Do you also imported account data and if yes than Have you properly mapped it with EventRelation ?

Please cross verify your EventRelation data and map it properly to Accounts.

Let me know if you need more clarification on this or you need more help.

Thanks,
Abhishek

All Answers

Abhishek BansalAbhishek Bansal
Hi Joseph,

Your code looks absolutely fine as you are not using any hard coded ids.
The only possible reason for this error is the EventRelation are not properly linked to the respective accounts.
As you are using where condtion in query as "Select ID, relationid, eventid FROM EventRelation Where accountid =:idCurrentEvent" 
So the reason that query does not return any row is Your EventRelation data is not correctly mapped to Account.

You also mentioned that you have imported EventRelation through data loader.
Do you also imported account data and if yes than Have you properly mapped it with EventRelation ?

Please cross verify your EventRelation data and map it properly to Accounts.

Let me know if you need more clarification on this or you need more help.

Thanks,
Abhishek
This was selected as the best answer
Vishal Negandhi 16Vishal Negandhi 16
Looking at the error, I believe it is on this line

newevent = [Select ID, OwnerID, subject, purpose_of_meeting__c, ActivityDate,WhatID From Event WHERE id = :tempeventid];
 Can you check if there's a EventRelation record for which the event is either deleted or does not exist? 
Joseph BaroneJoseph Barone
The issue was caused by the events that were archived.  As soon as I adjusted my query to include ALL ROWS, it worked.