Here hidden_field__c is a checkbox.
When in the VFP if user changes the checkbox to true in the database it still shows as false and vice-versa
Can someone please point out what's missing in my code.?
This is my code.
-----------controller --------------
public class dataTableCon {
List<Account> accounts;
public List<Account> getAccounts() {
if(accounts == null) accounts = [select name, owner.name,hidden_field__c from account limit 10];
return accounts;
}
}
---------VFP-------------
<apex:page controller="dataTableCon" id="page">
<apex:form >
<apex:pageBlock id="theBlock">
<apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even" styleClass="tableClass">
<apex:column >
<apex:facet name="header">Private</apex:facet>
<apex:inputCheckbox value="{!account.hidden_field__c}" >
<apex:actionSupport event="onchange" rerender="theBlock"/>
</apex:inputCheckbox>
</apex:column>
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!account.name}" >
</apex:column>
<apex:column >
<apex:facet name="header">Owner</apex:facet>
<apex:outputText value="{!account.owner.name}" >
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
You need to have some mechanism that actually saves the changes. Try adding an <apex:commandButton> inside your <apex:form>, and then have that button call an action that saves.
Apex:
public PageReference save()
{
update accounts;
}
Visualforce:
<apex:commandButton value="Save" action="{!save}"/>
Related
I'm trying to do a small project and I am stuck as I couldn't pull out the ID of the specified record of a custom object from vf page to apex class the code is given below
<apex:page standardController="enquiry__c" extensions='callme' recordSetVar="items"> <!--here enquiry__c is a custom object -->
<apex:form>
<apex:pageblock>
<apex:pageblocksection>
<apex:pageBlockTable value='{!items}' var='en' width="200" >
<apex:column value='{!en.name}'/>
<apex:column value='{!en.Student_Enquiry_Name__c}'/>
<apex:column value='{!en.phone__c}'/>
<apex:column value='{!en.email__c}'/>
<apex:column value='{!en.Status__c}'/>
<apex:column headerValue="Action">
<apex:commandButton value='convert to student'/>
</apex:column>
<apex:column headerValue="Record ID">
<apex:outputText value='{!en.id}' />
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value='new' action='{!newenquiry}'/>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
And the output is as below
So my question is when I click on button "convert to student" beside a particular record I have to get the ID of that record into apex class and the apex code is given below
public class callme
{
public enquiry__c e {get;set;}
public id i {get;set;}
public callme(ApexPages.StandardSetController c)
{
}
public PageReference newenquiry()
{
PageReference p=new PageReference('/apex/vfTab_on_enquiry');
return p;
}
public PageReference newcourse()
{
PageReference p=new PageReference('/apex/courseInsertion');
return p;
}
}
Please help me with this, thanks in advance.
-> you can use actionFunction for this.
-> create a js function called callActionMethod and invoke this function on the click of "convert to student" button.
-> create convertStudent method in apex class.
-> create an actionfunction named callConvertStudentMethod and pass the record id to the parameter.
Apex Controller:
public class callme
{
public enquiry__c e {get;set;}
public id i {get;set;}
public callme(ApexPages.StandardSetController c)
{
e = new enquiry__c();
}
public PageReference newenquiry()
{
PageReference p=new PageReference('/apex/vfTab_on_enquiry');
return p;
}
public PageReference newcourse()
{
PageReference p=new PageReference('/apex/courseInsertion');
return p;
}
public void convertStudent(){
system.debug('record id ---->'+i);
e = [SELECT FIELDS(ALL) FROM enquiry__c WHERE ID = :i];
system.debug('student record ---->'+e);
}
}
VF Page:
<apex:page standardController="enquiry__c" extensions='callme' recordSetVar="items"> <!--here enquiry__c is a custom object -->
<apex:form>
<apex:pageblock id='resultPanel'>
<apex:pageblocksection>
<apex:pageBlockTable value='{!items}' var='en' width="200" >
<apex:column value='{!en.name}'/>
<apex:column value='{!en.Student_Enquiry_Name__c}'/>
<apex:column value='{!en.phone__c}'/>
<apex:column value='{!en.email__c}'/>
<apex:column value='{!en.Status__c}'/>
<apex:column headerValue="Action">
<apex:commandButton value='convert to student' onclick="callActionMethod({!en.id})" />
</apex:column>
<apex:column headerValue="Record ID">
<apex:outputText value='{!en.id}' />
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value='new' action='{!newenquiry}'/>
</apex:pageblocksection>
</apex:pageblock>
<apex:actionFunction name="callConvertStudentMethod" action="{!convertStudent}" reRender="resultPanel" >
<apex:param name="firstParam" assignTo="{!i}" value="" />
</apex:actionFunction>
</apex:form>
<script type="text/javascript">
function callActionMethod(ele)
{
callConvertStudentMethod(ele);
}
</script>
</apex: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>
I get an error in visualforce page now. Saying:
Error:Unknown property 'tudent__cStandardController.d'
This happens when I add the delete commandLink button to the vf page. Before I add it it doesn't put out an error but on it doesn't display records on the page.
Thanks for help in advance
Visualforce code:
<apex:page standardController="tudent__c" extensions="vidsav">
<apex:form >
<apex:outputPanel id="check">
<apex:pageBlock title="Dodaj Študenta">
<apex:pageBlockSection columns="1">
<apex:inputField value="{! tudent__c.Name }"/>
<apex:inputField value="{! tudent__c.priimek__c }"/>
<apex:inputField value="{! tudent__c.Datum_rojstva__c }"/>
<apex:inputField value="{! tudent__c.letnik__c }"/>
<apex:inputField value="{! tudent__c.Naslov__c }"/>
<apex:inputField value="{! tudent__c.naziv_fakultete__c }"/>
<apex:inputField value="{! tudent__c.tudijski_program__c }"/>
<apex:inputField value="{! tudent__c.tip_tudija__c }">
<apex:actionSupport event="onchange" rerender="check" />
</apex:inputField>
<apex:inputField value="{! tudent__c.Samopla_nik__c }" rendered="{!IF( tudent__c.tip_tudija__c == 'izredni', true, false )}" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputPanel>
<apex:pageBlock title="Študenti">
<apex:pageBlockTable value="{!studentsR}" var="s" >
<apex:commandLink action="{!deleteStudent}" onclick="if(!confirm('Are you sure?')) return false;">`enter code here`Del
<apex:param value="{!d.Id}" name="idToDel" assignTo="{!SelectedStudentId}"/>
</apex:commandLink>
<apex:column value="{!s.Name}"/>
<apex:column value="{!s.priimek__c}"/>
<apex:column value="{!s.Datum_rojstva__c}"/>
<apex:column value="{!s.letnik__c}"/>
<apex:column value="{!s.Naslov__c}"/>
<apex:column value="{!s.naziv_fakultete__c}"/>
<apex:column value="{!s.tudijski_program__c}"/>
<apex:column value="{!s.tip_tudija__c}"/>
<apex:column value="{!s.Samopla_nik__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class vidsav {
public vidsav(ApexPages.StandardController controller) {
}
public List<tudent__c> studentsR {get;set;}
public String SelectedStudentId {get;set;}
public vidsav() {
loadData();
}
public void loadData() {
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c Order By CreatedDate desc];
}
public void deleteStudent(){
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c where id = :SelectedStudentId];
if(studentsR.size() > 0 || studentsR[0].Id != ''){
delete studentsR;
}
loadData();
}
}
Here is the updated code you should use ->
1) Update your PageBlockTable to this -
<apex:pageBlockTable value="{!studentsR}" var="s" >
<apex:column value="{!s.Name}"/>
<apex:column value="{!s.priimek__c}"/>
<apex:column value="{!s.Datum_rojstva__c}"/>
<apex:column value="{!s.letnik__c}"/>
<apex:column value="{!s.Naslov__c}"/>
<apex:column value="{!s.naziv_fakultete__c}"/>
<apex:column value="{!s.tudijski_program__c}"/>
<apex:column value="{!s.tip_tudija__c}"/>
<apex:column value="{!s.Samopla_nik__c}"/>
<apex:column>
<apex:commandLink action="{!deleteStudent}" onclick="if(!confirm('Are you sure?')) return false;" value="Del">
<apex:param value="{!s.Id}" name="idToDel" assignTo="{!SelectedStudentId}"/>
</apex:commandLink>
</apex:column>
You needed to put your commandLink inside an apex:column in order for it to display correctly in the pageBlockTable and also of course the d had to be replaced with a s since your table variable is s (var="s").
2) Update your Controller to this -
public class vidsav {
public vidsav(ApexPages.StandardController controller) {
loadData();
}
public List<Account> studentsR {get;set;}
public String SelectedStudentId {get;set;}
public void loadData() {
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c Order By CreatedDate desc];
}
public void deleteStudent(){
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c where id = :SelectedStudentId];
if(studentsR.size() > 0 || studentsR[0].Id != ''){
delete studentsR;
}
loadData();
}
}
You were using two constructors and were calling loadData() from the wrong one and this is why it was not loading data. With this you will be able to delete records and reload your table.
Replace {!d.Id} with {!s.Id}
The variable used to traverse the records in the pageblocktable is s not d.
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.
I have created a custom object "Assure__c" and a custom apex class "insEnfant" like this :
<apex:page standardController="Assure__c" extensions="insEnfant" standardStylesheets="true">
<apex:sectionHeader title="Ajouter un assuré"
subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
<apex:form >
<apex:pageBlock title="Nouveau assuré" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Enregistrer"></apex:commandButton>
<apex:commandButton action="{!cancel}" value=" Annuler "></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Liste des enfants" columns="1"
rendered="{!IF(Assure__c.Nombre_enfants__c > 0, true, false)}">
<apex:pageBlockTable value="{!accts}" var="a" id="table">
<apex:facet name="footer">
<apex:commandLink value="Ajouter" action="{!addRow}" rerender="table,error"/>
</apex:facet>
<apex:column headerValue="Nom">
<apex:inputHidden value="{!Assure__c.Name}" id="theHiddenInput"/>
</apex:column>
<apex:column headerValue="Nom">
<apex:inputField value="{!a.Name}"/>
</apex:column>
<apex:column headerValue="Prénom">
<apex:inputField value="{!a.Prenom__c}"/>
</apex:column>
<apex:column headerValue="Né le">
<apex:inputField value="{!a.Date_de_naissance__c}"/>
</apex:column>
<apex:column headerValue="Lieu de naissance">
<apex:inputField value="{!a.Lieu_de_naissance__c}"/>
</apex:column>
<apex:column headerValue="Situation">
<apex:inputField value="{!a.Situation__c }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class insEnfant{
public List<Enfants__c> accts {get; set;}
public insEnfant(){
accts = new List<Enfants__c>();
accts.add(new Enfants__c());
}
public void addrow(){
accts.add(new Enfants__c());
}
public PageReference save(){
insert accts;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
But when I tried to save it I obtain this error:
Error: Unknown constructor 'insEnfant.insEnfant(ApexPages.StandardController controller)'
Create Apex method 'insEnfant.insEnfant(ApexPages.StandardController controller)'
As I am new to salesforce.com, can anyone please give me the code for this??
Take a look at http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm which explains that a controller extension needs to have a constructor that takes a StandardController as argument. (You've provided a constructor that takes no arguments.) There's some sample code on that page that you may find helpful.