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
krishnagkrishnag 

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 &nbsp;
  <apex:inputText value="{!led.email}" title="email"/></apex:outputText> </apex:pageBlockSectionItem>
 
 <apex:pageBlockSectionItem > 
 <apex:outputText >Phone &nbsp;<apex:inputText value="{!led.phone}" title="Phone"/></apex:outputText></apex:pageBlockSectionItem>
 
 <apex:pageBlockSectionItem >
 <apex:outputText >Title &nbsp;&nbsp;&nbsp; <apex:inputText value="{!led.title}" title="Title"/></apex:outputText>
 </apex:pageBlockSectionItem>
 
 <apex:pageBlockSectionItem >
 <apex:outputText >Email Optout &nbsp;<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 &nbsp;<apex:inputCheckbox value="{!led.Real_Estate_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Property &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputCheckbox value="{!led.Property_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Manufacturing &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputCheckbox value="{!led.Manufacturing_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Healthcare &nbsp;&nbsp;<apex:inputCheckbox value="{!led.Healthcare_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Technology &nbsp;<apex:inputCheckbox value="{!led.Technology_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Environemntal &nbsp;&nbsp;&nbsp;&nbsp;<apex:inputCheckbox value="{!led.Environmental_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Energy &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputCheckbox value="{!led.Aftermarket_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Windstorm &nbsp;&nbsp;<apex:inputCheckbox value="{!led.Windstorm_Notification__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  <apex:pageBlockSectionItem >
  <apex:outputText >A&amp;H &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputCheckbox value="{!led.A_H_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
   <apex:pageBlockSectionItem >
  <apex:outputText >D&amp;O &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputCheckbox value="{!led.D_O_Interest__c}"/></apex:outputText>
  </apex:pageBlockSectionItem>
  
  
  <apex:pageBlockSectionItem >
  <apex:outputText >Financial &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
krishnagkrishnag

finally solved this issue by populating the data from custom object instead of standard object.

All Answers

aalbertaalbert

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.

krishnagkrishnag

i have checked all the CRUD permissions i have enabled all the permissions but still i am having the problem.

aalbertaalbert

What is the error message?

Have you enabled Debug Logs to see what error message is being generated?

krishnagkrishnag

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.

aalbertaalbert

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 

<apex:pageMessages/>

 to output the error messages to the page. 

 

 

 

krishnagkrishnag

the error is its not inserting the record. so the save function is not working on sites.

aalbertaalbert

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?

 

 

krishnagkrishnag

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

krishnagkrishnag

can u suggest me where should i use system.debug in the controller

aalbertaalbert

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:

 

public PageReference doSave(){


...

...

return null;

}

 

 

 

krishnagkrishnag

hi thanks for your help i have modified the code but still i dont see any entries in debug log.

 

public class conedits 
{

    public PageReference gsave() {
        
        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;
        
        
        try {
          insert (guest);
         } catch(System.DMLException e) {
           ApexPages.addMessages(e);
        return null;
            }
        PageReference p = Page.thanks;
         p.setRedirect(true);
          return p;
          }

    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()
    {
       
    }
    
}

 

 

krishnagkrishnag

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.

krishnagkrishnag

finally solved this issue by populating the data from custom object instead of standard object.

This was selected as the best answer
abhaabha

I am facing the same issue.. , 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

<apex:page controller="MyController8" tabStyle="Account" >
    <apex:form >
        <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:inputField value="{!Details.name}"/>
                <apex:inputField value="{!Details.Branch__c}"/>
                <apex:inputField value="{!Details.Subjects__c}"/>
                <apex:inputField value="{!Details.Aggregate__c}"/>
            
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 Controller class code

public class MyController8 {

    public Student__c stud { get; set; }
    public MyController8() {
     stud = new Student__c();
    }
        public Student__c getDetails() {
        return stud;
    }
    public PageReference save() {
        try {
            insert(stud);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
      PageReference pageRef = new PageReference('http://myappmbb-developer-edition.ap1.force.com/RegiSuccess');
      return pageRef;
    }
}