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
PaulDysonPaulDyson 

DML insert halting Apex script in Sites Controller

I have a very odd problem with some dml code. I have a form on a Sites site which creates Leads. The submit action of the form is just halting when I come to insert the new Lead; no exception is thrown and no further processing takes place. A code snippet:

 

try {

Lead l = new Lead(LastName = 'foo', Company = 'bar', Status = 'Open - Not Contacted'); 

Database.insert(l,false);

System.debug('Lead saved'); 

} catch (Exception e) {

System.debug('Exception caught');

  System.debug(e);

} 

 

Neither 'Lead saved' nor 'Exception caught' appears in the debug log, the log just ends:

 

 

20090822071712.927:Class.SitesLoopBlog.WebFormController.saveObject: line 96, column 14: Insert: SOBJECT:LeadCumulative profiling information:

 

And I get the dreaded Authorization Required page. Any ideas?
Best Answer chosen by Admin (Salesforce Developers) 
BulentBulent

Addition to crud and fls checks, aso check if you are performing this dml via a component. If yes then you need to enable DML for your component

 

 

All Answers

BrianWKBrianWK
Does the site user have permission to Create Leads? Not only that but do they have the field-object permission required?
BulentBulent

Addition to crud and fls checks, aso check if you are performing this dml via a component. If yes then you need to enable DML for your component

 

 

This was selected as the best answer
PaulDysonPaulDyson
Thanks Bulent, that was the problem although I have no idea why there was no exception being reported (I've fallen foul of this before and got an error message).
ErikTheTinkererErikTheTinkerer

Hello Bulent,

 

I have the same issue when attempting to insert leads.

But how do I "enable DML via a component"?

Do I add a special keyword to the class definition?

 

Thanks!

Erik

Message Edited by ErikTheTinkerer on 11-24-2009 08:15 AM
BulentBulent

<apex:component allowDML="true">

 

ErikTheTinkererErikTheTinkerer

Thanks Bulent,

 

Pretty elementary, sorry to waste your time on that, but it is appreciated.

 

Still working on this issue, more comments later.

 

Something I did find was that, while I can edit Field Level Security (FLS) from the Sites page, via the Public Access Settings button (which takes you to a profile screen of the guest user specifically for this site), when I went to the Field Accessibility settings under the Administration Setup menu, and checked out the FLS for the "Standard Guest User" profile, I found most of my fields were marked as hidden... changing these to editable did not fix my issue, but I found it interesting....

 

Erik

ssinssin

Hi Bulent,

 

For me its stillnot working. I have a visual workflow which insert Leads and this flow is being called from vf page. I have created a site and when this page launches it works well but when it reaches to Flow step where Leads are inserted, it gives error Authentication required. Please guide.

 

Thanks in advanc,

san