I have an error with a new Visualforce page I'm creating that takes list from a custom controller I made. It is for a standard objects and the class file compiled just fine. But when I start building the Visualforce page it gives me an error that I can't figure out.
This is the Visual Force Page
<apex:page controller="SearchAccountListController">
<apex:repeat value="{! acctList}" var="acct">
<apex:outputLink value="/{!acct.Name}">
<apex:outputText value="{!acct.Phone}"/><br/>
</apex:outputLink>
</apex:repeat>
</apex:page>
And the Controller:
public class SearchAccountListController {
public List<Account> getNewAccounts() {
List<Account> acctList = [SELECT Name,Phone FROM Account];
return acctList;
}
}
The class compiles fine, I'm using the Developer Console, so that seems to be okay. But then when I go to save my Visualforce page it gives the following error:
Save error: Unknown property 'Unknown property 'SearchAccountListController.acctList'
You don't have a class-level property acctList, you only have a local variable with that name. That name is lost when you leave the function.
From visualforce's point of view you have a getter function and what it returns can be accessed with {!newAccounts}.
Related
I have a senario where i will be dispalying input text fieldon vf page ,when i enter some value and click on search button the realted accounts should be displayed depending on that keyword.
I have tried the following code ,but i am unable to resolve the error Unknown property 'VisualforceArrayList.Name'
The below is my code:
class:
public class AccountswithKeywordfrompage {
public string keyword{get;set;}
public List<List<Account>> accountlist{get;set;}
public void Accounts(){
keyword = System.currentPageReference().getParameters().get('search');
accountlist=[FIND '+keyword' IN ALL FIELDS
RETURNING Account(Name)];
}
}
vf page:
<apex:page controller="AccountswithKeywordfrompage" standardStylesheets="false">
<apex:form>
<apex:inputText label="SearchAccounts" id="search">
<apex:commandButton value="search" action="{!Accounts}"/>
</apex:inputText>
<apex:pageblock>
<apex:pageblockTable value="{!accountlist}" var="accountobj">
<apex:outputlink value="{!accountobj.Name}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Can anyone help me to solve the issue ?
accountlist is a List<List<Account>>, which is the wrong type; a SOSL search returns a List<List<sObject>>. It just so happens that your SOSL search only returns Account results.
When you iterate over a List<List<sObject>>:
<apex:pageblockTable value="{!accountlist}" var="accountobj">
the type of the iteration variable is List<Account>, which has no Name property.
The cleanest solution is to declare your variable as a List<Account> and extract the first element of the returned List<List<sObject>> from SOSL.
How do you print out a custom Apex class list, that is not related to an Sobject? I keep getting error of
Error: Unknown property 'apiMyIntegrationCom.customerScorecardDiscountDetail.discountCategory'
Most code cut out for simplicity. I know the data is there, cause if i just use {!DiscountDetails} in visualforcepage, the data comes out for the whole class,var names and everything. Just looking to get particular vars.
public class MyController{
private apiMyIntegrationCom.customerScorecardResponse custScoreCard;
......
public apiMyIntegrationCom.customerScorecardDiscountDetail[] getDiscountDetails(){
return this.custScoreCard.discountDetails;
}
}
VisualForce Page:
<apex:page standardController="Account" extensions="MyController">
<table id="discountTable">
<apex:repeat id="dd" value="{!DiscountDetails}" var="dds">
<tr>
<td>{!dds.discountCategory}</td>
</tr>
</apex:repeat>
</table>
I think you need to add getDiscountCategory() to your apiMyIntegrationCom.customerScorecardDiscountDetail class (and any other fields you wish to expose on VF)
VF needs either explicit getProperty(), setProperty() methods or this notation: public String property {get; private set;}. Some more info can be found in my other answer: https://salesforce.stackexchange.com/a/9171/799
It looks like your class is autogenerated from WSDL file? Yep, that means you need to modify this code by sprinkling getters everywhere and you'll have to repeat this process every time you regenerate the class...
I am following this link to Create Save and New Functionality on page
How to implement "Save & New" functionality in a VisualForce Page
According to that i have did following
1.Create a apex class Opportunity and implement extension method
public with sharing class Opportunity
{
ApexPages.standardController m_sc = null;
public Opportunity(ApexPages.standardController sc)
{
m_sc = sc;
}
public Pagereference doSaveAndNew()
{
SObject so = m_sc.getRecord();
upsert so;
string s = '/' + ('' + so.get('Id')).subString(0, 3) + '/e?';
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
return new Pagereference(s);
}
}
this compiles fine
2.create a new page , extend the controller ,create button and call method
<apex:page sidebar="false" standardController="Opportunity" extensions="Opportunity" >
<apex:form >
<apex:pageMessages />
{!Opportunity.Name}
<apex:commandButton action="{!doSaveAndNew}" value="Save & New"/>
</apex:form>
</apex:page>
this gives me error "Unknown method 'OpportunityStandardController.doSaveAndNew()'"
I dont know what step I am missing in this process
Any suggestions
The APEX Class extension should not be the same with object name
APEX Class Name
OpportunityController
APEX Page
OpportunityPage
The code should be
<apex:page sidebar="false" standardController="Opportunity" extensions="OpportunityController" >
I think maybe the class name equal the object standard name will error
As Joseph pointed out, the page is trying to access the method in the standard controller 'OpportunityStandardController.doSaveAndNew()' and cannot find it since both the extension and the standard controller are called the same thing and it's just looking in the wrong class.
You probably just need to rename your controller extension to something else. I typically throw "Extension" on the end of the class name so I know what it is for. As an example, maybe something like "OpportunitySaveExtension". Then update your visualforce page to reference the renamed class in the "Extensions" attribute.
extensions="OpportunitySaveExtension"
I'm currently trying to customize an object on Salesforce and need to create a action button that will lead to a new account edit page.
I would like to prefill the new account page by passing inputs through the URLFOR function (see below); in my example, the parameter value is not interpreted.
<apex:page>
<apex:outputLink value="{! URLFOR( $Action.Account.New, null, [acc2='{! Object__c.Name}'] ) }">New Account</apex:outputLink>
</apex:page>
Does anyone have an idea on how to pass variables inputs through URLFOR in apex ?
Thanks for your help.
Crak
Yes, you are using the URLFOR function correctly.
Using
<apex:outputLink value="{! URLFOR( $Action.Account.New, null, [acc2='Acme'] ) }">New Account</apex:outputLink>
I was able to have a account screen load with Acme as the account name.
I believe the problem is that your call to get the name is returning null or blank so it appears that it is not applying anything to the Name field.
In your controller you should have a property that gives you access to the working record. Get the name like the following example.
Controller
Object__c MyCustomObject {get;set;}
Page
<apex:outputLink value="{! URLFOR( $Action.Account.New, null, [acc2=MyCustomObject.Name] ) }">New Account</apex:outputLink>
If that doesnt work as is, try changing to [acc2='MyCustomObject.Name'] etc
To get more generic solution you can use:
$Action.Account[]
when actionName is string variable(from apexclass or custom setting) can be:
View: Shows the detail page of an object
Edit: Shows the object in Edit mode
Delete: URL for deleting an object
New: URL to create a new record of an object
Tab: URL to the home page of an object
We can do it even more generic by change the object name to a variable too
$Action[objectName][actionName]
for example:
VFP:
<apex:page standardController="Account" extensions="urlForParamCTRL"
action="{!urlFor($Action[objectName][actionName],account.Id, null, true)}">
</apex:page>
Apex class:
public class urlForParamCTRL {
Public String objectName {get;set;}
Public String actionName {get;set;}
public urlForParamCTRL(ApexPages.StandardController controller)
{
this.objectName = 'Account';
this.actionName = 'New';
}
}
reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_globals_action.htm
Hi there I created a visual force page to with a standard lead controller as the controller and extend it. I want to do this so i can still utilize the apex:detail control and not reinvent the wheel in dealing with the standard lead info, related list etc.
I added an apex:commandbutton and make it call save. When I click on this button I can clearly see that my function is being called. However, all changes that is done to the lead info via inline editing is not captured.
For example, If I edited LastName using the inline editing and i click on the apex:commandbutton the new LastName value is not being saved. It's almost like the save function that is being called by apex:commandbutton is not aware of the data changes.
the following is code to my visual force page.
<apex:page standardController="Lead" extensions="LeadTestExtensionController">
<apex:form >
<apex:commandButton action="{!save}" value="Save" id="btnSave"/>
<apex:detail subject="{!Lead.Id}" relatedList="true" showchatter="true" inlineEdit="true" />
</apex:form>
</apex:page>
the following is code to my controller
public with sharing class LeadTestExtensionController {
private Apexpages.StandardController controller;
private PageReference page;
private string id;
private final Lead myLead;
public String positions {get; set;}
public LeadTestExtensionController(ApexPages.StandardController stdController) {
this.controller = stdController;
this.myLead = (Lead)stdController.getrecord();
this.page = ApexPages.currentPage();
this.id = page.getParameters().get('id');
List<Lead> myLeads = [select Opportunity_Stage__c from lead where id = :id];
if(myLeads.size() > 0)
{
positions = myLeads[0].Opportunity_Stage__c;
}
}
public PageReference save() {
this.controller.save();
PageReference newPage = New PageReference('/apex/RCS');
newPage.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
newPage.setRedirect(true);
return newPage;
}
}
Once I click on the apex:command button, the page is being redirected to apex/RCS so i know its being called. However, if i return to the same lead, the last name doesn't change. I was under the impression that the following line would've called the standard controller's save function that should've taken care of the updating of the Last Name.
this.controller.save();
What am I doing wrong and how can I accomplish this. The above code is heavily simplified version of my actual code. What I am trying to do in my actual code is to check the value of certain field and if it meets certain criteria I want it to do something. However, I can't seems to see the new value entered.
Thank you.
Calling save() on the standard controller does not commit inline edits in a detail section. I've just reproduced the problem using only the standard controller, so the way you are overriding it is not the issue.
I think the reason for this is that apex:detail gets a record out of the database in its own right, rather than using a reference to the one in the standard controller.
Inline edit should provide you with its own save button, and I think your best bet is to try and incorporate that into your design.