whateveryourscriptis

How To Create An Opportunity Using A Visualforce Page In Salesforce

By admin January 20, 2014
Blog, Salesforce Development 1

Another question has been asked to our expert Salesforce developers which we thought would be useful to share on our blog. The question was how you can create an opportunity using a Visualforce page within the Salesforce CRM. If you follow these step by step instructions provided by our expert Salesforce development team, you can do it yourself in no time.

Step 1 –

In Salesforce, go to Setup → Build → Develop → Apex Classes

Click on the “New Button” to create an Apex Class

Step-1

Step 2 –  Paste this code in your Salesforce Apex Class editor

public class OpportunityInformationPage {public opportunity oppstring{get; set;}public OpportunityInformationPage(){oppstring= new opportunity();}public void Saveto(){opportunity opp= new opportunity();opp.Accountid= oppstring.Accountid;opp.name= oppstring.name;

opp.closedate= oppstring.closedate;

opp.StageName= oppstring.StageName;

opp.leadSource= oppstring.LeadSource;

opp.Ownerid= oppstring.Ownerid;

opp.Amount= oppstring.Amount;

opp.IsPrivate= oppstring.IsPrivate;

opp.NextStep= oppstring.NextStep;

opp.Type= oppstring.Type;

opp.Probability= oppstring.Probability;

opp.Campaignid= oppstring.Campaignid;

opp.OrderNumber__c= oppstring.OrderNumber__c;

opp.MainCompetitors__c= oppstring.MainCompetitors__c;

opp.CurrentGenerators__c= oppstring.CurrentGenerators__c;

opp.DeliveryInstallationStatus__c= oppstring.DeliveryInstallationStatus__c;

opp.TrackingNumber__c= oppstring.TrackingNumber__c;

insert opp;

}

}

Step 3 –

In Salesforce, Go to Setup → Build → Develop → Pages

Click on the “New Button” to create a new page

Step 3

Step 4 – Create a Visualforce page with the name Opportunity Information Page, in the field type Opportunity Information Page, In the name field type Opportunity Information Page

Step 4

Step 5 –  Paste this code in the Visualforce editor in Salesforce

<apex:page controller=”OpportunityInformationPage1″><apex:sectionHeader title=”Opportunity Edit” subtitle=”New Opportunity”/><apex:form ><apex:pageBlock title=”Opportunity Edit” mode=”edit”><apex:pageBlockButtons ><apex:commandButton value=”Save” action=”{!Saveto}”/><!– <apex:commandButton value=”Cancel” action=”{!Cancel}”/> –></apex:pageBlockButtons><apex:pageBlockSection columns=”2″ title=”Opportunity Information”><apex:inputField value=”{!oppstring.Ownerid}”/>

<apex:inputField value=”{!oppstring.Amount}”/>

<apex:inputField value=”{!oppstring.IsPrivate}”/>

<apex:inputField value=”{!oppstring.CloseDate}”/>

<apex:inputField value=”{!oppstring.name}”/>

<apex:inputField value=”{!oppstring.NextStep}”/>

<apex:inputField value=”{!oppstring.Accountid}”/>

<apex:inputField value=”{!oppstring.StageName}”/>

<apex:inputField value=”{!oppstring.Type}”/>

<apex:inputField value=”{!oppstring.Probability}”/>

<apex:inputField value=”{!oppstring.LeadSource}”/>

<apex:inputField value=”{!oppstring.Campaignid}”/>

</apex:pageBlockSection>

<apex:pageBlockSection title=”Additional Information”>

<apex:inputField value=”{!oppstring.OrderNumber__c}”/>

<apex:inputField value=”{!oppstring.MainCompetitors__c}”/>

<apex:inputField value=”{!oppstring.CurrentGenerators__c}”/>

<apex:inputField value=”{!oppstring.DeliveryInstallationStatus__c}”/>

<apex:inputField value=”{!oppstring.TrackingNumber__c}”/>

</apex:pageBlockSection>

<apex:pageBlockSection title=”Description Information”>

<apex:inputField value=”{!oppstring.Description}”/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

Step 6 – Open this Visualforce page in your browser which should display like the following screenshot

Step 6

Step 7 – Enjoy

We hope these step by step directions on how to create an opportunity using a Visualfroce page within Salesforce have been helpful. As always any Salesforce development questions or problems you have, please feel free to reach out to the team at Mind Digital as our Salesforce developers would be more than happy to help!

Related Posts