salesforce apex refresh VF pageblock section - salesforce

I am trying to refresh a page block section based on the value of a select list. Here is the VF:
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!reasonCode}">
<apex:selectOptions value="{!reasonCodes}"/>
<apex:actionSupport event="onchange" reRender="a"/>
<apex:actionSupport event="oncomplete" action="{!isAcceptedReasonCode}" reRender="orders"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection id="orders" rendered="{!isAcceptedRC==true}" >
<apex:outputLabel value="Order Number" for="odNum"/>
<apex:inputText id="odNum" value="{!OrderNumber}"/>
</apex:pageBlockSection>
I have tried a bunch of different events, but none seem to work. Here is the isAcceptedReasonCode function:
public PageReference isAcceptedReasonCode (){
if(reasonCode == 'Accepted Offer') {
isAcceptedRC = true;
}else {
isAcceptedRC = false;
}
return null;
}
This seems pretty straightforward but it doesn't seem to work... of course i change the select list to be = 'Accepted Offer'

Add apex:outputPanel above apex:pageBlockSection and reRender outputpanel when Selection options is changed.
Sample Code:
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!reasonCode}">
<apex:selectOption itemLabel="Test" itemValue="Test"></apex:selectOption>
<apex:selectOption itemLabel="Accepted Offer" itemValue="Accepted Offer"></apex:selectOption>
<apex:actionSupport event="onchange" action="{!isAcceptedReasonCode}" reRender="testPanel"/>
</apex:selectList>
</apex:pageblockSectionItem >
</apex:pageBlockSection>
<apex:outputPanel id="testPanel">
<apex:pageBlockSection id="orders" rendered="{!isAcceptedRC}" >
<apex:outputLabel value="Order Number" for="odNum"/>
<apex:inputText id="odNum" value="{!OrderNumber}"/>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock >

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

View operation in salesforce using apex and visualforce

Below are the code of my VF and controller class
The save and cancel method works fine but my search method is not working correctly. After saving the objects when i click the view button it says to enter the field name instead of showing the list of objects.
VF code
<apex:page controller="c5">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="1">
<apex:inputField value="{!a.Name}"/>
<apex:inputField value="{!a.First_Name__c}"/>
<apex:inputField value="{!a.Last_Name__c}"/>
<apex:inputField value="{!a.Email__c}"/>
<apex:inputField value="{!a.Contact_Number__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
<apex:commandButton value="view" action="{!search}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
controller class
public class c5
{
public PageReference cancel()
{
PageReference pageRef = new PageReference('/apex/Reg');
pageRef.setRedirect(true);
return pageRef;
}
List<Register__c> b = new List<Register__c>();
Register__c a = new Register__c();
public Register__c geta(){
return a;
}
public PageReference save(){
insert a;
return null;
}
public List<Register__c> getb(){
return b;
}
public PageReference search(){
b = (List<Register__c>)[select Name, First_Name__c, Last_Name__c, Email__c, Contact_Number__c from Register__c];
return null;
}
}
You're assigning the result of your search to the property b but you don't display / use this property in the VisualForce page.
Try something like this:
<apex:page controller="c5">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="1">
<apex:inputField value="{!a.Name}"/>
<apex:inputField value="{!a.First_Name__c}"/>
<apex:inputField value="{!a.Last_Name__c}"/>
<apex:inputField value="{!a.Email__c}"/>
<apex:inputField value="{!a.Contact_Number__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
<apex:commandButton value="view" action="{!search}" rerender="bData"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1" id="bData">
<apex:dataTable value="{!b}" var="theSObject" rendered="{!NOT(ISBLANK(b))}">
<apex:column value="{!theSobject.Name}"/>
</apex:dataTable
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

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"/>

Visualforce page not performing action

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.

Resources