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
Deepak PansariDeepak Pansari 

How do I create a new Opportunity with specific record types in Visualforce page ?

Hi All,

I want to develop a custom Opportunity Visualforce page to create a new Opportunity with Specific Record type.

// sample code
Opportunity opp  = new Opportunity();

But the problem is above code is created a standard opportunity rather then specific record type Opportunity

I have also try this code
//  Opportunity opp   = new Opportunity(Recordtypeid=’0123000000001O6’);
Still Its not working…

Please let me know if anyone has any idea.

Thanks in advance
Deepak


JimRaeJimRae
That method:
Opportunity opp   = new Opportunity(Recordtypeid='0123000000001O6')

Works for me.  Are you sure the running user of the VF page has a profile that allows the use of the record type you are setting?



Deepak PansariDeepak Pansari
Hi Jim,

Thanks for your quick response.

after your reply , i was try to access directly record type , but i got error saying that "Insufficient privilege" .

Kindly guide me how do i get this permissions or what are the setting that's needs to be modified for me as a user to this VF page.

Thanks once again.
Deepak

JimRaeJimRae
Since you are looking at Opportunity, you need to look at the configuration of the Opportunity object in the Setup.
If you go to Setup, select Manage Users from the menu, then select the profile of the user you need to have access to the record type.  You will see a section called record types, and for the Opportunity object, an edit link that will provide you a list of available and selected record types for that user profile.  You should also look at the page layouts available for the user, and make sure they support the record type you are interested in.
Deepak PansariDeepak Pansari
Hi Jim,

I have checked all the settings that you have mentioed below  but, i have all the rights like i see that campaign in my profile and page layout also. ie my profile support that record type.

I have sys-admin rights.

but still the problem is remain same , i am not able to get specific Record Type opportunity. 

The basic problem is for "STAGE" field i have around 8 options that is for Standard Opportunity. But for that specific Record type Opportunity i have only 4 option.

while creating VF page with specific record type i still  get 8 option for " STAGE " instead of 4 option.

i hope you get my points.

let me know your thoughts.

Thanks,
Deepak



Message Edited by Deepak Pansari on 12-28-2008 11:12 PM
JimRaeJimRae
Not sure about that, but, I know that VF pages currently don't support dependent picklists (they show all of the possible values), you may be experiencing the same limitation.  Even though you are creating an object with the specific record type, you are not getting a filtered picklist of possible values.
One option you might consider would be to create the picklist (selectOption) yourself using the limited available responses, and supply that back to the object at creation time.


pschifflipschiffli

Hello Jim,

I am having the same issue as Deepak.  I have a certain set of stages associated with each record type on opportunities.  I have built a VF page for a quickview of your latest opportunities and as I added the column for the current stage, the drop-down gives you a list about a mile long with every stage associated with the opportunity object.  Coul you shed some light on the selectObject and maybe a guideline for setting up my own picklist in the code? 

Thanks for your support.

pschiffli@bokf.com

JimRaeJimRae
There is some good examples for how to create your own customized select lists in the documentation.  I would recommend that you check that out as well.  In the mean time....

Basically, you have 2 options for select lists, you can either hard code the values to the list, or you could extract them from the system with a SOQL statement.  Since you are trying to emulate a picklist, I would recommend hardcoding, since there likely would not be a good way to select values to match your dependent picklist filters.

You first create a SelectList element, then you create SelectOption items and place them in a selectOptions array.
Here is a code snippet that might help (right from the help, includes both the page code and the controller code):

Code:
<apex:page controller="sampleCon">
        <apex:form>
                <apex:selectList value="{!countries}" multiselect="true">
                        <apex:selectOptions value="{!items}"/>
                </apex:selectList><p/>
                <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
        </apex:form>
        <apex:outputPanel id="out">
                <apex:actionstatus id="status" startText="testing...">
                        <apex:facet name="stop">
                                <apex:outputPanel>
                                        <p>You have selected:</p>
                                        <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
                                </apex:outputPanel>
                        </apex:facet>
                </apex:actionstatus>
        </apex:outputPanel>
  </apex:page>
                        
   /*** Controller: ***/
  public class sampleCon {
  
        String[] countries = new String[]{};
  
        public PageReference test() {
                return null;
        }
  
        public List<SelectOption> getItems() {
                List<SelectOption> options = new List<SelectOption>();
                options.add(new SelectOption('US','US'));
                options.add(new SelectOption('CANADA','Canada'));
                options.add(new SelectOption('MEXICO','Mexico'));
                return options;
        }
  
        public String[] getCountries() {
                return countries;
        }
  
        public void setCountries(String[] countries) {
                this.countries = countries;
        }
  
  }

 

pschifflipschiffli
Jim,

Thank you for the guidance and options. I will look into the select Option array and see what I can make of it. It looks as though I have a few more hours of hard coding as I have 12 record types and about the same amount of options for each. Ha-ha! All in a weeks work, right?

Thanks again for your assistance. I will try this out and see what I can make happen.

Patrick
JimRaeJimRae
Vote for this idea on the Idea exchange, I did:

http://ideas.salesforce.com/article/show/10092833/Support_Dependent_Picklists_in_Visualforce#skin=adn
Link
pschifflipschiffli
It's a done deal, I made the 500th recommendation.

Thanks Jim!
pschifflipschiffli

Hello again Jim,

Are those two code blocks supposed to be together in the same editor with the VF page apex code?

Forgive my ignorance, I am new to the development aspect.

Thanks again and have a happy new year!

Patrick

JimRaeJimRae
No problem.  There are 2 separate objects in the code, the first is the VF Page (which is enclosed in the page tags) and the other is the controller (which starts after the /*** Controller: ***/ )

pschifflipschiffli

Jim, sorry I am such a knucklehead,

Does this source code look anything like it should for the selectOption function?:smileysad:

Basically when you click "New" on Opportunities, there are 16 different record types to choose from in the list, if you pick one, each has a filtered stage list of the "sales process" associated with that particular group.  BBG is our Business Banking Group ie: Prospecting, Closed/Won, Closed/Lost, etc.

I am just not sure if I am approaching this in the most efficient manner.

Code:
<apex:page standardController="Opportunity"
           recordSetVar="opportunities"
           tabStyle="Opportunity" sidebar="false">      
           
<apex:form >      
<apex:pageBlock >
    <apex:pageMessages />
    <apex:pageBlockButtons >    
        <apex:commandButton value="Save"
                            action="{!save}"/>
    </apex:pageBlockButtons>  
                   
    <apex:pageBlockTable value="{!opportunities}"
                         var="opp">
    <apex:column value="{!opp.name}"/>
    
    <apex:column headerValue="Stage">
      <apex:inputField value="{!opp.stageName}"/>
    </apex:column>
      
    <apex:column headerValue="Close Date">
      <apex:inputField value="{!opp.closeDate}"/>      
    </apex:column>  
      
                    <apex:selectList value="{!recordType}" multiselect="true">
                        <apex:selectOptions value="{!stage}"/>
                    </apex:selectList>
                
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>           
</apex:page>


 /*** Controller: ***/
  public class oppStage {
  
        String[] stage = new String[]{};
  
        public PageReference test() {
                return null;
        }
  
        public List<SelectOption> getStage() {
                List<SelectOption> stage = new List<SelectOption>();
                options.add(new SelectOption('BBG','Prospecting'));
                options.add(new SelectOption('BBG','Discovering Needs'));
                options.add(new SelectOption('BBG','Qualification'));
                options.add(new SelectOption('BBG','Proposal'));
                options.add(new SelectOption('BBG','Negotiation'));
                options.add(new SelectOption('BBG','Acceptance'));
                options.add(new SelectOption('BBG','Won'));
                return options;
        }
  
        public String[] getStage() {
                return stage;
        }
  
        public void setStage(String[] stage) {
                this.stage = stage;
        }
  
  }

 
JimRaeJimRae
Patrick,
You should also look at the documentation for the SelectOption functionality, in the salesforce_pages_developers_guide.
Each of the options you are creating (with the options.add method) is creating a new selectoption object.  This needs to have value and a label.
The way you have it configured, no matter which option the user selected, the value would always get returned as "BBG".  You would likely want to have it set up more like this:

Code:
public List<SelectOption> getStage() {
                List<SelectOption> stage = new List<SelectOption>();
                options.add(new SelectOption('Prospecting','Prospecting'));
                options.add(new SelectOption('Discovering Needs','Discovering Needs'));
                options.add(new SelectOption('Qualification','Qualification'));
                options.add(new SelectOption('Proposal','Proposal'));
                options.add(new SelectOption('Negotiation','Negotiation'));
                options.add(new SelectOption('Acceptance','Acceptance'));
                options.add(new SelectOption('Won','Won'));
                return options;
        }

 So that when you go to create or update your Opportunity, you are setting the Stage with an appropriate value.
The limitation caused by no support for dependent picklists will likely cause you to have to write a lot of code to simulate the functionality.
You may need to create a map that contains all of the dependent lists, by record type, and then dynamically generates the stagelist based on the recordtype selected.  Honestly, I have been working on this issue for a while, and we have not implemented a VF version of our Opportunity page because of this issue.  I am hopeful that the functionality is supported before I absolutly need to have a custom page.

pschifflipschiffli

Jim,

I definitely appreciate your feedback.  That was the general thought on my end as well.  The custom page I created gives the entire list, but for now, that might have to suffice.  I have gotten several others on the dependant picklist bandwagon and had them vote on this functionality as well, so hopefully there is some strength in numbers there.

Thank you for your quick responses.  That is the best feedback I have received since joining in on the community fun.  I really appreciate it once again. 

I look forward to speaking with you soon!

Have a Happy New Year!

pschiffli@bokf.com

Deepak PansariDeepak Pansari
Hi,

It’s me again,

Can we says that "Stage" filed is a dependent pick list or is there any other definition of dependent pick list ( In My Case ).

My case: I am getting all possible option values for field “Stage “in Opportunity, even after creating for specific Record type.

Thanks
Deepak
JimRaeJimRae
Unfortunately, dependent picklists are not supported directly in VF at this time, another frequently requested enhancements.
The only thing you can do is create custom selectlists for your stagefield on the VF page, and populate it based on the recordtype selected.

All manual, unfortunately.
pschifflipschiffli

Jim,

You will let me know when this feature becomes a reality in VF, right?  Ha-ha!

I am trying to stall this project until it becomes supported for sake of time and money spent on coding.

Have a good one!

JimRaeJimRae
Now, it sounds like you are right where I am!
Good Luck!
pschifflipschiffli
Same to you, and thanks!
Deepak PansariDeepak Pansari
Hi,

It’s me again,

I am able to create “Stage” pick-list manually, but still I wanted to do it from standard way.
We can customize the Options of Stage pick-list by "Sales Process".
Opportunity Sales Process - found in: Setup -> Customize -> Opportunities -> Sales Processes,

Can any one have any idea, how we can call Sales Process while creating Opportunity in Visualforce page.

Thanks
Deepak
JimRaeJimRae
There is no way to get the dependent picklist values today from the system.
You could create a map of the stage values for each Sales Process (Business Process), then generate the list from the Map, based on the Business Process ID of the Record type.  It would still be very much manual, and I don't think it would really provide any value over a completely manual method.