Visualforce page not performing action - salesforce

I'm very new to visualforce/salesforce, I'm a horrible beginner with this so please pardon my probably easy problem.
I'm creating a page to keep track of conference budgets. Basically the user enters how much was set as a budget in one field, in the next the put the actual cost, and then in the third field SF/VF should calculate the 2 numbers and display the difference. I set up the fields(correctly I believe as this was easy) and set up a page. Right now when you enter information into the fields and click save nothing happens.
This is all above my head and I'm trying to find the answers in literature but not having a lot of luck.
Here is the code:
<apex:page standardController="Conference__c" sidebar="true">
<apex:sectionHeader title="Conference Budget" subtitle="{!Conference__c.name}"/>
<apex:form >
<apex:pageBlock title="Conference Budget" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlocksection title="Conference Budget">
<apex:panelGrid columns="4" width="400px" cellspacing="5px">
<apex:outputText value="Item" id="Item"/>
<apex:outputText value="Budgeted" id="Budgeted"/>
<apex:outputText value="Actual" id="Actual"/>
<apex:outputText value="Difference" id="Difference"/>
<apex:outputText value="Advertising" id="advertising"/>
<apex:inputField value="{!Conference__c.Advertising_b__c}"/>
<apex:inputField value="{!Conference__c.Advertising_a__c}"/>
<apex:inputField value="{!Conference__c.Advertising_d__c}"/>
<apex:outputText value="Totals" id="totals"/>
<apex:inputField value="{!Conference__c.Total_Cost_b__c}"/>
<apex:inputField value="{!Conference__c.Total_Cost_a__c}"/>
<apex:inputField value="{!Conference__c.Total_Cost_d__c}"/>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:panelGrid>
</apex:pageBlocksection>
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>

The main thing to realize is that Salesforce (unless you have some type of workflow set up) isn't going to calculate those fields automatically. In addition, simply saving a record inside of an action region won't save the record, reload it, and display the page again. Saving, as far as I know, redirects the user to the record detail page.
For this simple calculation, if you want ti calculated prior to saving the record, I would just use some simple javascript:
<apex:page standardController="Conference__c" sidebar="true">
<!-- I use JQUERY because Salesforce IDs are very difficult to utilize in standard JS -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript">
var $j = jQuery.noConflict(); // SFDC uses $ so we need to assign jQuery to something else
function recalcAd() {
try{
var budget = parseFloat( $j("input[id$='ad-b']").val() );
var actual = parseFloat( $j("input[id$='ad-a']").val() );
$j("input[id$='ad-d']").val(budget - actual);
} catch (e) {
$j("input[id$='ad-d']").val("");
}
}
function recalcTot() {
try{
var budget = parseFloat( $j("input[id$='tot-b']").val() );
var actual = parseFloat( $j("input[id$='tot-a']").val() );
$j("input[id$='tot-d']").val(budget - actual);
} catch (e) {
$j("input[id$='tot-d']").val("");
}
}
</script>
<apex:sectionHeader title="Conference Budget" subtitle="{!Conference__c.name}"/>
<apex:form >
<apex:pageBlock title="Conference Budget" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlocksection title="Conference Budget">
<apex:panelGrid columns="4" width="400px" cellspacing="5px">
<apex:outputText value="Item" id="Item"/>
<apex:outputText value="Budgeted" id="Budgeted"/>
<apex:outputText value="Actual" id="Actual"/>
<apex:outputText value="Difference" id="Difference"/>
<apex:outputText value="Advertising" id="advertising"/>
<apex:inputField id="ad-b" value="{!Conference__c.Advertising_b__c}" onChange="recalcAd(); return true;"/>
<apex:inputField id="ad-a" value="{!Conference__c.Advertising_a__c}" onChange="recalcAd(); return true;"/>
<apex:inputField id="ad-d" value="{!Conference__c.Advertising_d__c}"/>
<apex:outputText value="Totals" id="totals"/>
<apex:inputField id="tot-b" value="{!Conference__c.Total_Cost_b__c}" onChange="recalcTot(); return true;"/>
<apex:inputField id="tot-a" value="{!Conference__c.Total_Cost_a__c}" onChange="recalcTot(); return true;"/>
<apex:inputField id="tot-d" value="{!Conference__c.Total_Cost_d__c}"/>
</apex:panelGrid>
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
In the code I've added some some script that will recalculate the totals as well as removed the action region which seemed unnecessary. I wasn't able to test it (since I don't have that object set up in an account of mine) but I think it should work for you.

Related

Trying to add output link on redirect page to newly created Opportunity from another VF page

SF Admin trying to make steps into Dev. Trying to create some web-to-opportunity functionality using combination of Force.com Sites, Apex & VF. It works and the opportunities are created. When the Opp is saved on the VF page, it redirects to another VF page saying Congrats! new Opp created etc. I would like to add an link or button on this redirect page to give the user an option to navigate to the newly created Opp if they want however I'm not having much luck.
Controller:
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
PageReference reRend = new PageReference('/apex/Opportunity_Created');
reRend.setRedirect(true);
return reRend;
}
}
VF Page to input Opp details:
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information">
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Congrats Page where I would like the link/button to route to SF:
<apex:page controller="OpportunityInformationPage" showheader="false" sidebar="false">
<apex:PageBlock >
<apex:pageBlockSection >
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:page>
Any advise, help appreciated.
I'm not sure why you are redirecting to a new page after creating the opportunity. Why not just show the success message on your current page and add a link to the new
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public Boolean bOppCreated{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
bOppCreated = false;
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
bOppCreated = true;
return null;
}
}
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}" rerender="mainBlock" />
</apex:pageBlockButtons>
<apex:outputpanel id="mainBlock">
<apex:pageBlockSection title="Opportunity Information" rendered="{!NOT(bOppCreated)>
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!bOppCreated}">
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
<apex:outputlink value="/{!oppString.id}">{!oppString.Name}</apex:outputlink>
</apex:pageBlockSection>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>
First of all modify reRend.setRedirect(true) to reRend.setRedirect(false) in your controller
Second thing is that when you want to display messages after cretaion of new opournity ,
Why we need another controller ?..
just after inserting new oppournity in Saveto() method
Add
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'New oppournity is created'));
Call this message in visual force page by simply mentioning apex:pagemessages/
Now in apex:outputlink mention the newly createtd oppournity </apex:outputlink>
Thanks to Psymn for pointing me in the right direction. The output link was landing me on the Home Tab due to a null Record ID (think this may be because I wasn't using the standard controller - Dev n00b sorry). Created a String variable to take the value of the ID and referenced this in the output link which did the trick.
Controller:
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public Boolean bOppCreated{get;set;}
public String opp_sfid{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
bOppCreated = false;
opp_sfid = null;
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
bOppCreated = true;
opp_sfid = opp.id;
return null;
}
}
VF Page:
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}" rerender="mainBlock"/>
</apex:pageBlockButtons>
<apex:outputPanel id="mainBlock">
<apex:pageBlockSection title="Opportunity Information" rendered="{!NOT(bOppCreated)}">
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!bOppCreated}">
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
<apex:outputlink value="/{!opp_sfid}">{!oppString.Name}</apex:outputlink>
</apex:pageBlockSection>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>

Opening a VF Page in new tab/window

I am new to Salesforce Lightning and trying to convert a classic button that opens a VF page in a new pop up window (Detail page button) into a Lightning component doing the same. Below is what I tried, created a New Action in Lightning and linked it to tho the below lightning component
selectCampignContainer.cmp (iframe to open the VF page in a new window)
<aura:component implements="force:lightningQuickAction" access="global">
<aura:attribute name='vfpName' type='String'/>
<iframe src="https://abc.lightning.force.com/apex/ +v.vfpName" width="100%" height="500px;" frameBorder="0"/>
</aura:component>
selectCampignContainerController.cmp
({
handleClick : function (cmp, event, helper) {
var evt = $A.get("e.force:navigateToComponent");
evt.setParams({
componentDef : "c:selectCampignContainer",
componentAttributes: {
vfpName : 'Campaign_Selection_Page'
}
});
evt.fire();
}
});
And the VF page is like
<apex:page standardController="Opportunity" extensions="Campaign_Selection_Page_Ext" id="page" showHeader="false" sidebar="false" lightningStylesheets="true" >
<apex:form id="form">
<apex:pageBlock title="Campaign Attribution" id="pageBlock">
<apex:pageblockSection >
<apex:outputField value="{!currentRecord.CampaignId}" label="Primary Campaign"/>
</apex:pageblockSection>
<apex:pageBlockSection title="Search Criteria" collapsible="false">
<apex:inputText value="{!campaignRecord.Name}"/>
<apex:inputField value="{!campaignRecord.StartDate}"/>
<!--<apex:inputField value="{!campaignRecord.Type}"/>-->
<apex:selectList value="{!campaignRecord.Type}" multiselect="false" size="1">
<apex:selectOptions value="{!campaignType}" ></apex:selectOptions>
</apex:selectList>
<apex:inputField value="{!campaignRecord.EndDate}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:outputPanel style="float:right;">
<apex:commandButton value="Search" action="{!search}" rerender="form"/> <apex:commandButton value="Assign Campaign" action="{!assign}" rerender="form"/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Search Results"></apex:pageBlockSection>
<apex:pagemessages ></apex:pagemessages>
<apex:pageBlockTable value="{!campaignRecords}" var="rec" id="pbTable">
<apex:column id="pbColumn" >
<apex:inputCheckbox value="{!rec.bol}">
<apex:actionSupport event="onchange" action="{!selectUnselect}" reRender="pbTable">
<apex:param value="{!rec.Campaig.Id}" assignTo="{!selectedCampaign}" name="recId"/>
</apex:actionSupport>
</apex:inputCheckbox>
</apex:column>
<apex:column value="{!rec.Campaig.Name}"/>
<apex:column value="{!rec.Campaig.Campaign_Short_Name__c }"/>
<apex:column value="{!rec.Campaig.Type}"/>
<apex:column value="{!rec.Campaig.StartDate}"/>
<apex:column value="{!rec.Campaig.EndDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
But when I clicked the button in lightning I get error like
This VF page works perfectly in the Classic and I have just included lightningStylesheets="true". Can anyone please let me know what am I missing here

How we can get the Mandatory sign in the Visual Force of SFDC?

I am new to the Visual Force code of the SDFC. I wanted to get the Mandatory details need sign shown below on my developed code of "Entry Section" of pageBLockSection. How Can I do that ?
<apex:page standardController="account">
<apex:form>
<apex:pageBlock title="Block One">
<apex:pageBlockSection title="Entry Section">
<apex:inputField value="{!account.Name}"/>
<apex:inputField value="{!account.phone}"/>
<apex:inputField value="{!account.billingcity}"/>
<apex:inputField value="{!account.Industry}"/>
<apex:commandButton value="Submit" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
To make a input tag required, set required = 'true' for the input.
Ex, <apex:inputtext value="{!Name}" required="true"/>

Salesforce show all cases based on criteria in visualforce

All,
I am attempting to show all cases that meet certain criteria in salesforce using visual force page, then I would like to use that data in a gantt chart. I do know much about coding, but trying based on user manuals. This visualforce page comes back without any case information.
<apex:page standardController="Case" >
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:PageBlockTable value="{!Case}" var="c">
<apex:column value="{!c.Account}"/>
<apex:column value="{!c.Number}"/>
<apex:column value="{!c.Owner}"/>
<apex:column headerValue="Install Date">
<apex:inputField value="{!a.Planned_Install_Date__c}"/>
</apex:column>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
You need an apex controller class to get data from Salesforce to the visual force page. Something like this:
Visual Page:
<apex:page standardController="Case" controller="MyCaseController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:PageBlockTable value="{!Cases}" var="c">
<apex:column value="{!c.Accountid}"/>
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.OwnerId }"/>
</apex:PageBlockTable>
</apex:pageBlock>
</apex:form>
Controller:
public class MyCaseController {
public list<Case> cases {get;set;}
public MyCaseController(){
cases = [select id, accountid, CaseNumber, OwnerId from case];
}
}
You should be able to accommodate the code to your needs.

How do I get a "New" button on my custom apex:pageBlockTable for Cases?

I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it:
<apex:page standardController="Case" recordSetVar="Case" sidebar="true" showHeader="true">
<apex:form >
<apex:pageBlock title="Cases">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="cases_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
<apex:pageBlock >
<apex:pageBlockButtons >
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!case}" var="c" rows="50" id="cases_table" >
<apex:column >
<a target="_parent" href="{!URLFOR($Action.Case.View, c.id)}">{!c.CaseNumber}</a>
<apex:facet name="header">Case Number</apex:facet>
</apex:column>
<apex:column value="{!c.ContactId}" />
<apex:column value="{!c.Subject}" />
<apex:column value="{!c.Status}" />
<apex:column value="{!c.Priority}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
<base target="_parent"/>
</apex:page>
I would like to get a button inside my apex:pageBlockButtons like in the default Cases page. When the user clicks the button, I would like it to take the user to the new Cases page. I tried this:
<apex:commandButton action="{!new}" value="New"/>
but that gave me an error. How do I make a button that will take me to the new Cases page?
Try this:
<apex:commandButton onclick="window.location.href='{!URLFOR($Action.Case.NewCase)}'" value="New" immediate="true" rerender="blank"/>
Important to note that the rerender tag is needed otherwise the page will do a postback. By using a dummy rerender tag the redirect will work. Immediate is there to avoid running any validation rules on click.
I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it(custom object):
<apex:commandButton action="{!URLFOR($Action.Your_Custom_Object__c.New)}" ...>

Resources