You need to sign in to do that
Don't have an account?
Rung41
Save and Create Opportunity button?
I created a custom VF page called Renters, that is used to capture information similar to Contacts. When a user clicks on the "Save" button I want the record to save and then automatically create a new Opportunity with some of the information captured in the VF page. I can get the record to save but how do I also get it to create a new Opportunity?
I'm not sure where to start.
I had a custom object Merchandise__c in my instance. I am providing you the class and page code below
when you try to save the merchandise object, the Save Action method runs and it helps in creating a opportunity as well.
It will also redirect you to the opportunity created.
All Answers
Creating an Opportunity with the help of given information is farely simple. You must have defined the the Action method for the Save button. WIthin that Function you can define the new Opportunity and assign all the respective values. And simply insert that.
Are able to provide an example?
I had a custom object Merchandise__c in my instance. I am providing you the class and page code below
when you try to save the merchandise object, the Save Action method runs and it helps in creating a opportunity as well.
It will also redirect you to the opportunity created.
Works great. One question though, is there any way to when the user is brought over to the Opportunity page, that its still in edit mode? Currently the user is brought over to the Opportunity page that has been saved.
In the class definition, only change the page reference you want when you return from the Save action method. Here is what you need to replace.
REPLACE
WITH
This will redirect you to Opportunity Edit page.
I just want to Thank you for your help. Its been a great learning experience. I am starting to write the test class and was wondering if I am a doing this correctly.
This is what I have so far. I would continue to add the data to test each field.
As you are writing the test class for a particular Apex class, you must have used that class as a controller or extension. Therefore in the test class you must define the linkage to the particular Visualforce page. This is how it is done.
@isTest
private class <className>{
static testMethod void <methodName>(){
Test.setCurrentPage(Page.<yourPageName>);
ApexPages.StandardController sc = new ApexPages.StandardController(new <sObjectName>);
<sObjectName> sController = new <sObjectName>(sc);
*/
the code can be written to access the functions defined within the class method. for e.g. sController.Save();
make sure to provide all the information that the particular function needs.
/*
}
}