1

I'm just trying to create a simple form to save an Opportunity. For some reason, the page isn't saving and not giving me any console errors. Here is the code:

<apex:page showHeader="false" controller="NewWeb2Opportunity">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"/>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>


<div id="Wrapper">
    <div id="Header"/>
    <div id="theBody">

        <div id="CaseForm">

            <form>
            <apex:form >

                <table cellpadding="10" class="form-group">
                    <tr>
                    <h1>Contact Us</h1>
                    <p>Please enter your information below and we will follow up with you as soon as we can.</p>
                    </tr>
                    <tr id="theaccount">
                        <td><label class="col-lg-12 control-label" for="">Contact Name</label></td>
                        <td><apex:inputField styleClass="form-control" id="account" value="{!opp.AccountId}"/></td> 
                    </tr>
                    <tr>
                        <td><label  class="col-lg-12 control-label" for="">Stage</label></td>
                        <td><apex:inputField styleClass="form-control" id="stage" value="{!opp.StageName}"/></td> 
                    </tr>
                    <tr>
                        <td><label class="col-lg-12 control-label" for="">Amount</label></td>
                        <td><apex:inputField styleClass="form-control" id="amount" value="{!opp.Amount}"/></td> 
                    </tr>
                     <tr>
                        <td><label class="col-lg-12 control-label" for="">Probability</label></td>
                        <td><apex:inputField styleClass="form-control" id="prob" value="{!opp.Probability}"/></td> 
                    </tr>
                     <tr>
                        <td><label class="col-lg-12 control-label" for="">Close Date</label></td>
                        <td><apex:inputField styleClass="form-control" id="date" value="{!opp.CloseDate}"/></td> 
                    </tr>
                    <tr>
                        <td><label class="col-lg-12 control-label" for="subject">Subject</label></td>
                       <td><apex:inputField styleClass="form-control" id="name" value="{!opp.Name}" /></td> 
                    </tr>
                    <tr>
                        <td><label class="col-lg-12 control-label" for="description">Description</label></td>
                        <td><apex:inputTextarea styleClass="form-control" id="newDesc" value="{!opp.description}"/></td>
                    </tr>
                    <tr>
                        <div id="button">
                            <apex:commandButton styleclass="btn btn-default" id="next" action="{!saveOpp}" value="Submit"/>
                       </div> 
                    </tr>
                </table>
                </apex:form>
            </form>
        </div>

And the controller:

public class NewWeb2Opportunity{

public Opportunity opp {get;set;}


public NewWeb2Opportunity(){
    opp = new Opportunity(); 
    opp.AccountId = '001o0000005uBxaAAE';
    opp.StageName = 'Prospect';
    opp.Amount = 100000;
    opp.Probability = 50;
    opp.Name = 'Home Mortgage';
    opp.Description = 'Looking for a new Home Loan.';
    opp.RecordTypeId = '012o0000000auAL';
}


public PageReference saveOpp() {
    insert opp;
    PageReference pageRef = new PageReference('/'+ opp.Id);
    return pageRef;
}

}

  </apex:page>
2
  • What about the apex:page tag that sets which controller to use?
    – Jagular
    Aug 21, 2014 at 17:27
  • its there I just didn't add it to this post. I'll edit my post.
    – user5428
    Aug 21, 2014 at 17:30

2 Answers 2

3

try adding error handling to your code add <apex:pagemessages /> to the second line of your VF page

update the saveOpp method in your controller public PageReference saveOpp() { try { insert opp; PageReference pageRef = new PageReference('/'+ opp.Id); return pageRef; } catch(Exception e) { String error = e.getMessage(); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,error)); } } See if this produces and error message for you.

1

You have form inside another form - this is what causing your issue: remove tags <form> and </form> from you page and it should fix it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .