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
Btuitasi1Btuitasi1 

Insert record from custom object

I am trying to insert a record on a child object (Idea_Comments__c) of the standard controller object (Idea_Lobby__c). After insertion, I would also like it forward to a VF page. So far, I have not had any success with my page. After clicking submit, the page tries to send me to login. 

Here's my extension so far:
public with sharing class detExt {

private ApexPages.StandardController theController; 
public Idea_Comments__c ideaCom {get; set;}
public Idea_Comments__c setideaCom(Idea_Comments__c op){
this.ideaCom=op;
return ideaCom;
}

public detExt(ApexPages.StandardController acon) {

   theController = acon;
   ideaCom=new Idea_Comments__c();

 }
  public List<Idea_Comments__c> getdetExt()
    {

        ID masterID = theController.getID();

        return [SELECT Id, CreatedDate, CreatedBy.Name, Comment__c
        FROM Idea_Comments__c
        WHERE Idea_Lobby__c = :masterID
        order by CreatedDate DESC ];
    }
 public pagereference saveComments(){

Idea_Comments__c cd = new Idea_Comments__c();
cd.Comment__c=ideaCom.Comment__c;
insert cd;
PageReference congratsPage = Page.Congrats_Page;
  congratsPage.setRedirect(true);
  return congratsPage;

}
}

Any ideas on how I can get this to work?
Best Answer chosen by Btuitasi1
BalajiRanganathanBalajiRanganathan
it might work if you remove congratsPage.setRedirect(true);

 

All Answers

BalajiRanganathanBalajiRanganathan
it might work if you remove congratsPage.setRedirect(true);

 
This was selected as the best answer
BalajiRanganathanBalajiRanganathan
Also check if you have "Require CSRF protection on GET requests" is checked (Setup-> Develop -> Pages ->  Congrats_Page) for the VF Page Congrats_Page. if checked then uncheck it.
Btuitasi1Btuitasi1
Removing 
congratsPage.setRedirect(true);

worked! Thanks!!