+ Start a Discussion
admintrmpadmintrmp 

Cannot debug this problem - any clue?

I can't seem to debug this problem because it's on Force.com sites and I just get redirected to a page saying, Error: Error occurred while loading a Visualforce page.

 

I don't any emails telling me what the problem is, so I have to go through and find it myself and went through line by line to find the problem. It seems the problem is using DML to execute and update query on multiple rows.

 

Any clue?

 

 

// if user is logged in:
tbi = [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM Basket__c WHERE User__c=:UserInfo.getUserId()];

// ...
// URL always has gid parameter (guest id)

gbi = [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM Basket__c WHERE GuestIP__c=:AppGlobal.getParam('gid')];

List<Basket__c> deleteRec = new List<Basket__c>();
List<Basket__c> updateRec = new List<Basket__c>();

for ( i=0; i<gbi.size(); i++ )
{
deleted = false;

for ( x=0; x<tbi.size(); x++ )
{
if ( tbi[x].Event__c == gbi[i].Event__c )
{
deleteRec.add(gbi[i]);
deleted = true;
break;
}
}

if ( !deleted )
{
gbi[i].User__c = UserInfo.getUserId();
gbi[i].GuestIP__c = '';
updateRec.add(gbi[i]); // fails here (but not when testing!!!)

}
}

if ( updateRec.size() > 0 ) update updateRec; // fails here (but not when testing!!!)
if ( deleteRec.size() > 0 ) delete deleteRec;

 

Thanks in advance if you can find the problem!

 

 

Message Edited by admintrmp on 10-05-2009 08:22 AM
Best Answer chosen by Admin (Salesforce Developers) 
admintrmpadmintrmp

After several hours of pulling my hair out I found the problem! Not being able to use DML from a data-request tag in Visualforce!

 

I was using DML within a method I was using to grab data from. The <datatable></datatable> tag!

 

I wish this was made more clear.

 

Thanks for your help.

All Answers

BritishBoyinDCBritishBoyinDC
Try monitoring via the debug log, that should still give a more detailed error report even if the page is rendered via sites.
admintrmpadmintrmp

When I run a debug log on the user, it all works fine up until the update DML command. I've tried using the try statement using both DMLException and Exception by itself and it doesn't come up with anything.

 

When I say it works fine up until the update command, the script stops at that point. It goes no further. Here is the bit it stops at:

 

 

...

20091006092948.164:Class.Booking.getBasketItemsMethod: line 215, column 17: (Basket__c:{Name=000000029, Event__c=a0080000000xxxxxT, GuestIP__c=null, User__c=00580000003DxxxxxK, Id=a0F80000002jxxxxxE})
20091006092948.164:Class.Booking.getBasketItemsMethod: line 219, column 51: Update: LIST:SOBJECT:Basket__c
Cumulative profiling information:

...

 

 That bit of the log has a try statement on it, but it returned no information. I'm running out of road here.

 Queries, commands and everything else are all well within their limits.

 

Message Edited by admintrmp on 10-06-2009 02:52 AM
admintrmpadmintrmp

Also, this controller is not being used from a component, however there are components on the page but I should not think they affect this. I've tried switching around the allowDML attribute, but nothing worked.

 

The correct security permissions are given to the user/guest.

 


Here is a little info on what I'm trying to achieve. The record is created by a site guest. The record contains a unique guest id made by Javascript. When that guest logs in at any point, the guest id disappears and the user id is submitted into the record.

 

The thing I'm confused about is that I tried updating the record(s) with no changes to the field data and it still remains to fail.

 

For the moment, I can only assume this is a bug and not my fault because I cannot debug this and there seems to be no other

way around it.

 

Has anyone got any information on this as this is important to us.

 

Thankyou

Message Edited by admintrmp on 10-06-2009 04:19 AM
BritishBoyinDCBritishBoyinDC

I think you'd need to post all the code - if that statement isn't producing the error, it is likely an error somewhere else,but this is the last code that is logged.

 

Also, as a more general comment, I think you could use a map to more efficiently compare tbi with gbi... 

admintrmpadmintrmp

Here is the code relevant:

 

 

public List<TEvent> getBasketItemsMethod()
{
// If items have already been retrieved, return them instead
if ( basketItems != null )
{
return basketItems;
}

basketItems = new List<TEvent>();
TEvent ev;
Integer i, x = 0;
Boolean deleted = true;
List<Id> eventIds = new List<Id>();
List<TrainingBasket__c> tbi = new List<TrainingBasket__c>();
List<TrainingBasket__c> gbi = new List<TrainingBasket__c>();

// Get user items
if ( !AppGlobal.isGuest() )
{
tbi = [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM TrainingBasket__c WHERE User__c=:UserInfo.getUserId()];
}

// Get guest items (gid is a url paramater always set for this page)
if ( AppGlobal.getParam('gid') != null )
{
gbi = [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM TrainingBasket__c WHERE GuestIP__c=:AppGlobal.getParam('gid')];

// If user is logged in and there are items from when user was a guest...
if ( !AppGlobal.isGuest() && gbi.size() > 0 )
{
List<TrainingBasket__c> deleteRec = new List<TrainingBasket__c>();
List<TrainingBasket__c> updateRec = new List<TrainingBasket__c>();

for ( i=0; i<gbi.size(); i++ )
{
deleted = false;

for ( x=0; x<tbi.size(); x++ )
{
// If there is a duplicate guest/user item,
// put the guest record in the delete pile
if ( tbi[x].Event__c == gbi[i].Event__c )
{
deleteRec.add(gbi[i]);
deleted = true;
break;
}
}

// If the record isn't in the delete pile,
// update record and put in the update pile
if ( !deleted )
{
gbi[i].User__c = UserInfo.getUserId();
gbi[i].GuestIP__c = '';
updateRec.add(gbi[i]);
}
}

// If there are records to update, update them!
if ( updateRec.size() > 0 )
{
try
{
// Debug log messages are shown correctly
System.debug('Updating... ' + updateRec.size() + ' records');
System.debug(updateRec);
update updateRec; // APEX COMES TO A HALT
}
catch (System.DmlException ex) {
// Debug log message not shown
System.debug(String.valueOf(ex));
}
}

// CODE FROM HERE ON IN CANNOT BE TESTED BECAUSE APEX HAS BEEN
// HALTED BY THE UPDATE DML STATEMENT ABOVE

// If there are records to delete, delete them!
if ( deleteRec.size() > 0 ) { delete deleteRec; }

}
}
// If user is not logged in, then just set
else if ( AppGlobal.isGuest() && gbi.size() > 0 )
{
for ( i=0; i<gbi.size(); i++ )
{
tbi.add(gbi[i]);
}
}
else
{
// continue...
}

// Call again for all records
if ( !AppGlobal.isGuest() )
{
tbi = [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM TrainingBasket__c WHERE User__c=:UserInfo.getUserId()];
}

// The following debug log message does not show
System.debug('LOOKING AT ' + tbi.size() + ' RECORDS');

//...
}

 

 And here is the log:

 

 

***Begining Page Log for /apex/myBasket 20091006121926.515:Class.TrainingGlobal.getAppSettings: line 47, column 50: SOQL query with 1 row finished in 42 ms 20091006121926.515:Class.TrainingGlobal.getAppSettings: line 49, column 10: SelectLoop:LIST:SOBJECT:TrainingSettings__c 20091006121926.515:Class.TrainingGlobal.getAppSettings: line 49, column 10: Number of iterations: 1 20091006121926.515:Class.TrainingGlobal.<init>: line 34, column 9: returning from end of method public void getAppSettings() in 43 ms 20091006121926.515:Class.TrainingBooking.<init>: line 18, column 21: returning from end of method public TrainingGlobal<Constructor>() in 44 ms 20091006121926.515:External entry point: returning from end of method public TrainingBooking<Constructor>() in 44 ms 20091006121926.515:Class.TrainingBooking.getBasketItem: line 95, column 14: returning String from method public String getParam(String) in 0 ms 20091006121926.515:Class.TrainingBooking.getBasketItem: line 101, column 14: returning String from method public String getParam(String) in 0 ms 20091006121926.515:External entry point: returning from end of method public void getBasketItem() in 1 ms Element j_id0 called method {!getBasketItem} returned type PageReference: none20091006121926.515:Class.TrainingGlobal.getAppSettings: line 47, column 50: SOQL query with 1 row finished in 5 ms 20091006121926.515:Class.TrainingGlobal.getAppSettings: line 49, column 10: SelectLoop:LIST:SOBJECT:TrainingSettings__c 20091006121926.515:Class.TrainingGlobal.getAppSettings: line 49, column 10: Number of iterations: 1 20091006121926.515:Class.TrainingGlobal.<init>: line 34, column 9: returning from end of method public void getAppSettings() in 6 ms 20091006121926.515:External entry point: returning from end of method public TrainingGlobal<Constructor>() in 7 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 177, column 15: returning Boolean from method public Boolean isGuest() in 0 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 179, column 19: SOQL query with 0 rows finished in 46 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 182, column 14: returning String from method public String getParam(String) in 0 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 184, column 108: returning String from method public String getParam(String) in 0 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 184, column 19: SOQL query with 1 row finished in 8 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 186, column 19: returning Boolean from method public Boolean isGuest() in 0 ms 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 219, column 25: Updating... 1 records 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 220, column 25: (TrainingBasket__c:{Name=000000029, Event__c=a008000000DSxxxxxT, GuestIP__c=null, User__c=00580000003DxxxxxK, Id=a0F80000002jxxxxxE}) 20091006121926.515:Class.TrainingBooking.getBasketItemsMethod: line 221, column 25: Update: LIST:SOBJECT:TrainingBasket__c Cumulative profiling information: 3 most expensive SOQL operations: Class.TrainingGlobal.getAppSettings: line 47, column 50: [SELECT Id, name, Value__c FROM TrainingSettings__c]: executed 2 times in 47 ms Class.TrainingBooking.getBasketItemsMethod: line 179, column 19: [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM TrainingBasket__c WHERE User__c=:UserInfo.getUserId()]: executed 1 time in 46 ms Class.TrainingBooking.getBasketItemsMethod: line 184, column 19: [SELECT Id, Name, GuestIP__c, User__c, Event__c FROM TrainingBasket__c WHERE GuestIP__c=:AppGlobal.getParam('gid')]: executed 1 time in 8 ms No profiling information for SOSL operations. 1 most expensive DML operations: Class.TrainingBooking.getBasketItemsMethod: line 221, column 25: Update: LIST:SOBJECT:TrainingBasket__c: executed 1 time in 0 ms 7 most expensive method invocations: Class.TrainingBooking: line 162, column 25: public LIST:TrainingBooking.TEvent getBasketItemsMethod(): executed 1 time in 56 ms Class.TrainingGlobal: line 32, column 12: public TrainingGlobal<Constructor>(): executed 2 times in 51 ms Class.TrainingGlobal: line 44, column 18: public void getAppSettings(): executed 2 times in 49 ms Class.TrainingBooking: line 16, column 12: public TrainingBooking<Constructor>(): executed 1 time in 44 ms Class.TrainingBooking: line 92, column 17: public void getBasketItem(): executed 1 time in 1 ms Class.TrainingGlobal: line 61, column 20: public Boolean isGuest(): executed 2 times in 0 ms Class.TrainingGlobal: line 131, column 19: public String getParam(String): executed 4 times in 0 ms ***Ending Page Log for /apex/myBasket?gid=TWpBd09UazJNVEkxTkRneE9EWXpOakEzTXc9PTU0My43NzQ4MDE3MDM1MDg2

 

 

 

 

BritishBoyinDCBritishBoyinDC
I'm afraid I can't see anything wrong either - just out of interest - have you confirmed the update isn't happening - the log doesn't show any errors?
admintrmpadmintrmp

I'm absolutely certain it's the update. If I comment out the update, the script continues successfully and the page loads but then the actions I want it to take are not taken (the update!).

 

So it's nothing other than the update.

This is why I can only assume it's a bug of some sort.

 

I cannot insert either and I can't update with any record changes. So DML seems to be completely broken for me here.

Message Edited by admintrmp on 10-06-2009 05:53 AM
admintrmpadmintrmp

After several hours of pulling my hair out I found the problem! Not being able to use DML from a data-request tag in Visualforce!

 

I was using DML within a method I was using to grab data from. The <datatable></datatable> tag!

 

I wish this was made more clear.

 

Thanks for your help.

This was selected as the best answer
BritishBoyinDCBritishBoyinDC
That is frustrating, but good to know for the future. Well done for figuring that one out!
cvm_asishcvm_asish

hello,

I am new to this. I am also facing same problem. When i tries to login I am getting the error message "Error occurred while loading a Visualforce page".

 

I didnt understand the solution that u hv provided. "I was using DML within a method I was using to grab data from. The <datatable></datatable> tag!" 

 

Could you please explain it?

 

Thanks in advance

 

Asish