- Home
- Technical Library
- Boards
- Cookbook
- Code Share
- Blogs
- Partners
-
More
-
Services
- Training & Certification
- Support
-
Galleries
- Force.com Sites Gallery
- Chatter Challenge Entries
-
Other Web Sites
- Salesforce.com
- Database.com
- AppExchange
- CRM Community
-
Discussions
- Announcements
- General Development
- Schema Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Mobile
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- REST API Integration
- Streaming API
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Site.com
- Jobs Board - Administrators
- Jobs Board - Developers
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Force.com Sites
- :
- Simple Insert Not Working for Public Site
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Simple Insert Not Working for Public Site
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-09-2011 06:05 AM
I have an issue that I cant seem to resolve. I have a Force.com Free Edition org an I am building some Pages in the Sandbox. I have a simple custom object that is acting sort of like a Hit counter. It's just got a couple of text fields and a timestamp field right now.
My controller is working fine. The page is rendered and pulls/displays data from another custom object just fine. The problem occurs when I try to insert a record to this Hit Counter object. I am routed to the "Required Login" screen. If I comment out the insert statement, the page is fine. I am well aware of the permissions that need to be available to the guest user under Sites -> Public Access Settings. Here is what I know so far...
- The object in question has read, create, and edit checked for the guest user
- The field level security is set to visible for everything and nothing is checked to be read only for the guest user (except for the system fields that you cant change)
- The guest user has access to all VF Pages
- The guest user has access to all Apex classes
- There are no triggers on the custom object
- There are no validation rules on the custom object.
- There are no relationship fields on the custom object
- Sharing rules on the object are public R/W
- The Controller is not using "with sharing" modifier
public class LandingPageController {
private String pid;
public Landing_Page__c page {get; private set;}
public String errormsg {get; private set;}
private PageReference pageRef = ApexPages.currentPage();
private Map<String, String> headers = pageRef.getHeaders();
private Map<String, String> getParams =PageRef.getParameters();
public LandingPageController() {
pid = getParams.get('pid');
if(pid != null) {
page = [SELECT Id, Name FROM Landing_Page__c WHERE LPN__c = :pid];
}
if(page == null) {
errormsg = 'No page returned!';
} else {
Hit__c hit = new Hit__c();
hit.IP_Address__c = headers.get('True-Client-IP');
hit.LPN__c = getParams.get('pid');
hit.Timestamp__c = System.now();
insert hit; // <- THIS IS THE PROBLEM
}
}
}
Solved! Go to Solution.
Re: Simple Insert Not Working for Public Site
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-09-2011 06:37 AM
Hey Kevin,
Did you try taking the insert method out of the constructor and putting it in an action (PageReference) method?
then you can call the action method from the apex:page tag.
I'm pretty sure DML isn't allowed in a controller's constructor.
--Kevin
Re: Simple Insert Not Working for Public Site
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-09-2011 08:22 AM

