0

UPDATE

In the developer's console, I have input the following:

public class Intake {
    public PageReference saveAndRedirect() {

  Intake__c.save(); // This takes care of the details for you.

  PageReference newPage = Page.Congratulations; // This will be the visualforce page or Url that we want to redirect to

  newPage.setRedirect(true);

  return newPage;
}

}

I am met with this error: Method does not exist or incorrect signature: void save() from the type Intake__c

It's my understanding this is supposed to act on the save action - What am I doing wrong?


I know this is an easy question, but I need help with the syntax.

I'm adding a controller to redirect. This is what I have.

enter image description here

I'm getting an error at Intake.Intake__c and am not sure why. I know this should be PageReference, but I'm not sure how to call it. Please help! My standard controller is Intake__c and my page is Intake.

If I change to PageRefernece, I still get an error.

enter image description here

6
  • 1
    Quick note: it's much preferred to use text instead of images when code is involved. Code in an image can't be copy/pasted if your issue is something that people need to try to reproduce to understand/solve, and long horizontal or vertical stretches would make it hard to read without clicking through to the image itself (extra clicks will reduce the number of people willing to help).
    – Derek F
    Oct 23 '20 at 14:24
  • Thanks - I'll keep that in mind - Any info on helping me solve this? Read through David's suggestion and am still confused. Would like some help referencing this particular situation Oct 23 '20 at 14:59
  • As for your new error, the best practice for stackexchange sites would probably be for you to make a new question for it. The short answer to that, though, is that your class doesn't contain a method called "save", hence your error. You have to be precise and verbose in programming. If you're trying to call a method, you either need to define it yourself (inside your class), or get it from somewhere else (like from an instance of the ApexPage.StandardController class). Also, the __c thing is only for custom SObjects (which are different from a "class" in Apex) and its custom fields.
    – Derek F
    Oct 23 '20 at 15:33
  • In short, I think you might be looking to create a controller extension rather than a controller. Trailhead has many trails and modules to help you learn about new (to you) features and concepts. It also helps to include an abundance of detail in your questions on this site. A controller extension might not be the way to go here, but it's really difficult to give you a push in the right direction if we don't know what your end goal is (i.e. Are you making a visualforce page? looking to use this in a LWC? want to use it to add a button to the detail page for an SObject?).
    – Derek F
    Oct 23 '20 at 15:39
  • Hey, Derek - What I'm looking to do is a simple redirect when a user form is submitted. I have created a VF page that collects and submits user-input to create a new record on my object (Intake) with no issue. However, when the user clicks submit, they are then directed to SalesForce, and I'd like to direct to a 'submitted successfully' page. This doesn't seem like it'd be difficult, but everything I've read says to create a controller extension. Oct 23 '20 at 18:09
2

You've written a method without an enclosing class, which is not legal in Apex. Your method needs to be contained in a controller class.

Returning PageReference is correct.

Create and Use Custom Controllers on Trailhead introduces how to build these classes.

Note also that you're using the oldest and worst available UI to write this code. I would strongly recommend switching to Visual Studio Code instead (also introduced on Trailhead), or at minimum use the Developer Console instead of editing Apex in Setup.

3
  • David - I have tried in the developer's console, and am met with this... "Method does not exist or incorrect signature: void save() from the type Intake__c".. Here is what I have in the console. public class Intake { public PageReference saveAndRedirect() { Intake__c.save(); // This takes care of the details for you. PageReference newPage = Page.Congratulations; // This will be the visualforce page or Url that we want to redirect to newPage.setRedirect(true); return newPage; } } Oct 23 '20 at 14:41
  • 2
    That's correct, there is no such method. I'd strongly recommend you go through the linked Trailhead module to learn how to write controllers.
    – David Reed
    Oct 23 '20 at 14:41
  • ok. thanks for the help. Oct 23 '20 at 14:43
0

I created a controller extension and called it within my VF page.

The header became :

<apex:page standardController="Intake__c" extensions="IntakeExtension" standardStyleSheets="false" showHeader="false" sidebar="false">

and I created an Apex Class to be an extension of Intake that looks like this:

public with sharing class IntakeExtension {
    public IntakeExtension(ApexPages.StandardController Intake) {
    }
    public PageReference save() {
        return Page.Congratulations;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.