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
Related
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>
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.
If I try to rendered the code below it doesn't work.
If I show me the size of the list I will get the value 1, but nothing is happen.
Where is the mistake?
I tried it also with != NULL .isempty etc., the same problem.
<apex:pageblock title="Unternehmen Detail" id="pbAccDL" rendered="{!If(AccDList2.size > 0,true,false)}>
<apex:pageblocktable value="{!AccDList2}" var="AccD" rendered="{!IF(AccDList2.size != 0, true, false)">
<apex:column style="font-size:16pt; font-weight: bold" headerValue="" value="{!AccD.Name}"/>
</apex:pageblocktable>
<apex:pageblocktable value="{!AccDList2}" var="AccD" columnswidth="50%, 25%, 25%">
<apex:column value="{!AccD.BillingStreet}"/>
<apex:column value="{!AccD.BillingPostalCode}"/>
<apex:column value="{!AccD.BillingCity}"/>
</apex:pageblocktable>
Public List <Account> getAccDList2() {
List <Account> AccD = [SELECT Id, Name, RecordTypeId, Status__c, Kunde_seit__c, Billingstreet, BillingPostalCode, BillingCity FROM Account WHERE Id = :SelectedAccountId];
RETURN AccD;
}
Public pageReference getAccDList() {
getAccDList2();
//RETURN NULL;
RETURN ApexPages.CurrentPage();
}
I don't understand the problem, because I use the same function for an other pageblock and works fine.
<apex:pageblock title="Account" id="pbAcc" rendered="{!IF(AccList2.size != NULL,true,false)}">
<apex:pageblockButtons location="top">
<apex:commandButton value="page 1" rerender="pbAcc" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="prev page" rerender="pbAcc" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="next page" rerender="pbAcc" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="last page" rerender="pbAcc" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
<apex:pageblocktable value="{!AccList2}" var="Acc" columnswidth="5%, 70%, 25%">
<apex:column headervalue="LINK">
<apex:outputLink target="_blank" value="/{!Acc.Id}">Details</apex:outputLink>
</apex:column>
<apex:column headervalue="Account">
<apex:outputField value="{!Acc.Name}" />
<apex:actionSupport event="onclick" action="{!getOppList}" rerender="pbOpp, pbAccDL, pbAccDR, pbOppD">
<apex:param assignTo="{!SelectedAccountId}" value="{!Acc.Id}" name="SelectedAccountId"/>
</apex:actionSupport>
</apex:column>
<apex:column headervalue="City">
<apex:outputField value="{!Acc.BillingCity}"/>
</apex:column>
</apex:pageblocktable>
Could someone help me please.
Thanks,
peX
Note that if the outer container (apex:pageBlock in your case) wasn't rendered at page load time you wouldn't be able to rerender inner elements later. To make sure this is not the problem remove rendered attribute from outer apex:pageblock. One more thing to note in your second example you are writing AccList2.size != NULL which is never the case (if AccList2 is a list) you should check with AccList2.size > 0
I'm trying to use command buttons using a dynamic component. I want to render these command buttons on the bottom of the page but I'm not able to do it. when I use location=top, it works. when I use location=bottom, I can't see the buttons at all. When I use location=both, I see them only at the top. I'm not using any facets. Please help me if someone knows!
I used them using apex code.
This is the VF page:
<apex:page title="Opportunity Display" controller="MyPageController1" showHeader="true" sidebar="false" readOnly="true" cache="false" >
<apex:sectionHeader subtitle="SOQL Offset Example w/Dynamic Page Buttons" title="Opportunity Display Table" />
<apex:form >
<apex:pageBlock >
<apex:dynamicComponent componentValue="{!myCommandButtons}" />
<apex:actionFunction action="{!refreshGrid}" name="queryByPage" reRender="myPanel,myButtons" >
<apex:param name="firstParam" assignTo="{!selectedPage}" value="" />
</apex:actionFunction>
<apex:pageBlockSection title="Opportunity Display (Total List Size: {!total_size})" collapsible="false">
<apex:outputPanel id="myPanel">
<apex:pageMessages id="theMessages" />
<apex:pageBlockTable value="{!opportunity}" var="n" align="center">
<apex:column><apex:inputCheckbox value="{!n.checked}"/></apex:column>
<apex:column value="{!n.cat.Id}" />
<apex:column value="{!n.cat.Name}" />
<apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
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)}" ...>