You need to sign in to do that
Don't have an account?
its_raj
Multiple action for a single custom button.
Is it possible to perform multiple actions from a single custom button click? likewise, onclick of a button, the data gets saved as well as the page redirects to another link/page.
Yes you can perform multiple action on a single button click as you have mentioned.
HI Prakashb,
Can u help with the syntax.
You can use the below code to make an update and redirect toa different page.
Public Pagereference saveandredirect(){
Update yourobject;
Pagereference p = new Pagereference('your url');
p.setredirect(true);
return p;
}
Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Class.myProductController.saveandredirect: line 28, column 1
got the above error
Can you post the entire code in the method??
<apex:commandButton action="{!saveandredirect}" value="BUY NOW" />
public with sharing class myProductController {
public myProductController(ApexPages.standardController controller) {
String id = ((Product__c)controller.getRecord()).id;
this.product = [Select p.Name, p.Company__c, p.Model__c,p.Color__c,p.Price__c from Product__c p where p.id=:id];
}
public PageReference view() {
return null;
}
Product__c product;
Booking__c booking;
public Product__c getProduct() {
return product;
}
Public Pagereference saveandredirect(){
Update booking;
Pagereference p = new Pagereference('/apex/logipage');
p.setredirect(true);
return p;
}
public PageReference gotologinpage() {
return Page.loginpage;
}
}
Your Booking record is null and hence when you are trying to update it it is throwing a null pointer exception.
Do you really need to update booking object as there seems to be no record related to it??
i need to store the mentioned fields in a new object named as booking, upon save.
so the object will be null in the beginning and upon save should re direct to a new page.
i also used "insert" instead of "update" but still the error persists.
Are you using the booking fields on your page.
It seems the product obejct is the controller for your page.
Any way try replacing Booking__c booking with Booking__c booking = new Booking__c();
Hey Thanks. The record can now be created and even page navigation is working.
But 1 problem persists even now, New Booking record is created everytime but doesnot store the fields' values.
I m trying to store the fields' values from my Product object into the Booking Object.
Then you need to map your Booking and Product fields before doing an insert.
Like booking.Fieldname = product.Fieldname;
booking.Field = product.Field;
use this wn u click the button and then update the record....u'll get the fields stored
u need to think that wn u r creating a new record then u hv to map the fields also for storing the values.