You need to sign in to do that
Don't have an account?
krishnag
not able to insert the data on custom object using sites
hi i was trying to insert a set of data to a custom object i was able to do it in normal visual force page but when i checked it on sites i was not able to this is the code i used.
controller
public class conedits { public guestuser__c guest{get;set;} public PageReference cancel() { return null; } string conid; public contact led{get;set;} public conedits() { this.conid=ApexPages.currentPage().getParameters().get('paramID'); if(conid!=null||conid!='') { getdetails(conid); } } //public preference(ApexPages.StandardController controller) //{ // get the id of the quote and store it in quoteid // this.leadid=ApexPages.currentPage().getParameters().get('paramID'); // if(leadid!=null||leadid!='') // { //getdetails(leadid); // } // } public void getdetails(string conid) { List<contact> cons=[select id,Email,Phone,Title,HasOptedOutOfEmail,A_H_Interest__c,Aftermarket_Interest__c,Construction_Interest__c,D_O_Interest__c,Energy_Interest__c,Environmental_Interest__c,Financial_Enterprises_Interest__c,Healthcare_Interest__c,Manufacturing_Interest__c,Property_Interest__c,Real_Estate_Interest__c,Technology_Interest__c,Windstorm_Notification__c from contact where Id=: conid]; if(cons.size()>0) { led=cons[0]; } else { } } public void save() { guest = new guestuser__c(); guest.Email__c= led.email; guest.Title__c = led.title; guest.Email_Optout__c = led.HasOptedOutOfEmail; guest.Phone__c = led.Phone; guest.Healthcare_interests__c = led.Healthcare_Interest__c; guest.Environmental_interests__c = led.Environmental_Interest__c; guest.Energy_interests__c = led.Energy_Interest__c; guest.Technology_interests__c = led.Technology_Interest__c; guest.RealEstate_interests__c= led.Real_Estate_Interest__c; guest.A_H_interests__c = led.A_H_Interest__c; guest.D_O_interests__c = led.D_O_Interest__c; guest.After_Markets_interests__c = led.Aftermarket_Interest__c; guest.Construction_interests__c = led.Construction_Interest__c; guest.Windstorm_notification_interests__c = led.Windstorm_Notification__c; guest.Property_interests__c = led.Property_Interest__c; guest.Financial_Enterprises_interests__c = led.Financial_Enterprises_Interest__c; guest.Manufacturing_interests__c = led.Manufacturing_Interest__c; insert (guest); } }
VF page
<apex:page showHeader="false" controller="conedits"> <apex:form > <apex:pageBlock title="My Preferences" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="submit"/> <apex:commandButton action="{!cancel}" value="cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Personal Information" columns="2"> <apex:pageBlockSectionItem > <apex:outputText >Email <apex:inputText value="{!led.email}" title="email"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Phone <apex:inputText value="{!led.phone}" title="Phone"/></apex:outputText></apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Title <apex:inputText value="{!led.title}" title="Title"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Email Optout <apex:inputCheckbox value="{!led.HasOptedOutOfEmail}" title="Emailoptout"/></apex:outputText> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection title="My Interests" columns="3"> <apex:pageBlockSectionItem > <apex:outputText >Real Estate <apex:inputCheckbox value="{!led.Real_Estate_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Property <apex:inputCheckbox value="{!led.Property_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Manufacturing <apex:inputCheckbox value="{!led.Manufacturing_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Healthcare <apex:inputCheckbox value="{!led.Healthcare_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Technology <apex:inputCheckbox value="{!led.Technology_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Environemntal <apex:inputCheckbox value="{!led.Environmental_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Energy <apex:inputCheckbox value="{!led.Energy_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Construction <apex:inputCheckbox value="{!led.Construction_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >After Market <apex:inputCheckbox value="{!led.Aftermarket_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Windstorm <apex:inputCheckbox value="{!led.Windstorm_Notification__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >A&H <apex:inputCheckbox value="{!led.A_H_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >D&O <apex:inputCheckbox value="{!led.D_O_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputText >Financial <apex:inputCheckbox value="{!led.Financial_Enterprises_Interest__c}"/></apex:outputText> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
can anybody suggest me how to make it work on sites.
finally solved this issue by populating the data from custom object instead of standard object.
All Answers
Make sure the Profile associated with the Site has the proper CRUD permissions enabled.
You can find those settings under Setup | Develop | Sites| click the hyperlink of the site you want to configure | click button 'Public Access Settings'. Verify the object permissions are set properly.
i have checked all the CRUD permissions i have enabled all the permissions but still i am having the problem.
What is the error message?
Have you enabled Debug Logs to see what error message is being generated?
there is no error message at all i cannot see a new record created on custom object. i am not getting errors. its working fine as normal VF page its creating a record.
In the apex I recommend adding System.debug statements to get a clearer understanding of the where the code is failing.
In the visualforce, I recommend adding the tag
to output the error messages to the page.
the error is its not inserting the record. so the save function is not working on sites.
I understand. But we need to make sure the apex code is executing the save() method and failing on insert. And assuming it is, we need to output the salesforce.com error to get a better understanding of why. Have you added the <apex:pageMessages/> to the page? Have you enabled debug logs to see if you can get more information?
i have enabled the debug logs but the debug log is showing some operations on contact its not showing any operations on cutom object i have created
can u suggest me where should i use system.debug in the controller
I would add System.debug() statements throughout the code. Not just one spot.
The save() method needs to return a PageReference object to be called from the command button. You did that with the cancel method in the controller, but not the save().The signature of an action method needs to return a PageReference:
hi thanks for your help i have modified the code but still i dont see any entries in debug log.
after clicking on save according to my code if it is successfully inserted it should redirect to other page or else should display an error message. its not doing eeither.
finally solved this issue by populating the data from custom object instead of standard object.
I am facing the same issue.. krishnag, Will you please help me to solve this?
My code is working fine when executed from within the account. But it is not working on my website. I checked all the object and field permissions. Everything is right. But don't know where I am going wrong.
Any Kind of help will be greatly appreciated..
I am attaching my code here
Visualforce page
Controller class code