-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
4Questions
-
7Replies
Display list of fields as checkbox choices on VF page
What I would like to do is display as many as 50 fields from a Contract detail page (i.e. Terms_and_Conditions__c) as a list in a single vertical column, next to a checkbox. Users would be able to choose the fields they want by checking the box.
So far I’m able to set the column headers in the VF page, and I’ve added a summary list class in my controller, but I’m stuck on how to generate the list of fields, and to render that list in the VF page. Any ideas?
Desired output:
Apex controller:
VF page:
Page rendering:
So far I’m able to set the column headers in the VF page, and I’ve added a summary list class in my controller, but I’m stuck on how to generate the list of fields, and to render that list in the VF page. Any ideas?
Desired output:
Select: | Contract Field |
□ | Terms_and_Conditions__c |
□ | Return_Provisions__c |
Apex controller:
public class AccountContractPickerControllerExt{ public String currentContractRecordId {get;set;} // public String parameterValue {get;set;} public Contract currentContract{get;set;} public String selectedContract {get;set;} public String contractLeaseStatusFilter = 'Lease In force'; public PageReference pageRef = new PageReference('/' + 'recordID'); // public Account acc {get;set;} //public String AccountID {get;set;} //public String AccountName {get;set;} public List<Contract> contracts = new List<Contract>(); // Obtain list of Contract Fields for Build SOQL statements Map<String, Schema.SObjectField> fieldMap = Contract.sObjectType.getDescribe().fields.getMap(); Set<String> fieldNames = fieldMap.keySet(); String soqlCurrentContract = 'Select' + string.join((Iterable<String>)fieldNames, ',') + ' From Contract Where id =: currentContractRecordID'; String soqlSelectedContract = 'SELECT' + string.join ((Iterable<String>)fieldNames, ',') + 'FROM Contract WHERE AccountID =:currentContract.AccountID and Lease_Status__c =:contractLeaseStatusFilter ORDER BY name'; public AccountContractPickerControllerExt(ApexPages.StandardController controller) { currentContractRecordId = ApexPages.CurrentPage().getparameters().get('id'); currentContract=[select ID, Name, AccountID from Contract where id =: currentContractRecordId]; //parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam'); } private ApexPages.StandardSetController stdController; /** * Retrieves Contracts by the lease status set on * contractLeaseStatusFilter. * * @return List of Contracts */ public List<Contract> getContracts() { getContractsByLeaseStatus(); return contracts; } /** * Executes query to retrieve Contracts by the lease status set on contractLeaseStatusFilter. * Retrieve the results using <code>getContracts</code> * This is typically called externally via JavaScript (AJAX). * * @return PageReference (null) */ public PageReference getContractsByLeaseStatus() { // Contracts=database.query(soqlSelectedContract); contracts = [SELECT Name, Account.Name, ContractNumber, Lease_Status__C, Rent_Monthly_PC__C, Lease_Type__C, Cars_on_Billing__C FROM Contract WHERE AccountID = :currentContract.AccountID and Lease_Status__c = :contractLeaseStatusFilter ORDER BY Name]; return null; } public String getContractLeaseStatusFilter() { return contractLeaseStatusFilter; } public void setContractLeaseStatusFilter(String filter) { contractLeaseStatusFilter = filter; } /** * Generates the SelectOptions necessary to create a dropdown menu containing the * available Contracts. * * @return List of SelectOptions for the available Contracts */ public List<SelectOption> getContractSelectOptions() { List<SelectOption> opts = new List<SelectOption>(); for (Contract contract : getContracts()) { opts.add(new SelectOption(contract.Id, contract.Account.Name + ' : ' + contract.Name + ' - ' + + contract.Lease_Status__C + ' - '+ + contract.Rent_Monthly_PC__C + ' - ' + + contract.Lease_Type__C + ' - ' + Contract.Cars_on_Billing__C)); } return opts; } /* Associates the Contracts with the Account by setting the contracts on the related Account. * * @return PageReference to the related contracts view if the save is successful, otherwise * returns the PageReference back to the ContractImport page. */ public ApexPages.PageReference save() { System.debug('Entering AccountContractPickerControllerExt.save'); Boolean hasError = false; List<Contract> contracts = (List<Contract>)stdController.getRecords(); System.assert(contracts.isEmpty(), 'At least one contract should be passed to the controller.'); return ApexPages.currentPage(); } //retrieve list of Terms fields for import selection public class Summary{ public List<String> summary_list {get; set;} public Summary(List<String> s){ summary_list = s; } } public List<Summary> summary_list_wrap {get; set;} public List<String> items_in_column {get; set;} public void build_Table(){ //populating the data here - which is working as per the screenshot below } }
VF page:
<apex:page standardController="Contract" extensions="AccountContractPickerControllerExt" sidebar="False" lightningStylesheets="true" docType="html-5.0"> <apex:form > <script> function getSelectedLeaseStatus() { var leaseStatusSelect = document.getElementById("leaseStatusFilter"); return leaseStatusSelect.options[leaseStatusSelect.selectedIndex].value; } </script> <apex:pageMessages /> <apex:outputPanel layout="block" rendered="{!contract != null}"> <apex:pageBlock title="Assign Lease to Account"> <apex:pageBlock title="Selected Lease to Import Term To"> <apex:pageBlockTable value="{!contract}" var="contracts"> <apex:column headerValue="Lease"> <apex:outputField value="{!contract.Name}"/> </apex:column> <apex:column headerValue="Order Number"> <apex:outputField value="{!contract.ContractNumber}"/> </apex:column> <apex:column headerValue="Lease Status"> <apex:outputField value="{!contract.Lease_Status__c}"/> </apex:column> <apex:column headerValue="Account ID"> <apex:outputField value="{!contract.AccountID}"/> </apex:column> <apex:column headerValue="Start Date"> <apex:outputField value="{!contract.StartDate}"/> </apex:column> <apex:column headerValue="End Date"> <apex:outputField value="{!contract.EndDate}"/> </apex:column> <apex:column headerValue="Rent Monthly PC"> <apex:outputField value="{!contract.Rent_Monthly_PC__c}"/> </apex:column> <apex:column headerValue="Lease Type"> <apex:outputField value="{!contract.Lease_Type__c}"/> </apex:column> <apex:column headerValue="Cars On Billing"> <apex:outputField value="{!contract.Cars_On_Billing__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Select a Lease to Import Terms From"> <label for="leaseStatusFilter">Select a lease status to filter on: </label> <select id="leaseStatusFilter" onchange="getContractsByLeaseStatusJS(getSelectedLeaseStatus())"> <option>Lease In Force</option> <option>Order</option> <option>Expiring-Available</option> <option>Expired</option> <option>Return</option> <option>Closed - Renewed</option> <option>Closed - Reassigned</option> <option>Closed - Sold</option> </select> <br/> <label for="contractSelector">Select a contract: </label> <apex:selectList value="{!selectedContract}" size="1" id="contractSelector"> <apex:selectOptions value="{!contractSelectOptions}"/> </apex:selectList> </apex:pageBlock> <apex:pageBlockButtons > <apex:commandButton value="Save-Import Terms" action="{!save}"/> <apex:commandButton value="Cancel-No Import Performed" action="{!cancel}"/> </apex:pageBlockButtons> </apex:pageBlock> <apex:pageBlock title="Term"> <apex:pageblockTable value="{!summary_list_wrap}" var="slw"> <apex:column value="{!slw}"/> <apex:column headerValue="Field"> </apex:column> Summary:[fieldNames (Abatement_General_Text__c,Abatement_Gen_Rep_Start_Days__c, ...)]; <tr > <th>Contract Name</th> <td>{!contract.Abatement_General_Text__c}</td> </tr> <apex:repeat var="slw" value="{!contract}"> <tr> <td>{!contract.Abatement_General_Text__c}</td> </tr> </apex:repeat> </apex:pageblockTable> </apex:pageBlock> <apex:pageBlock title="Import From"> </apex:pageBlock> <apex:pageBlock title="Import To"> </apex:pageBlock> <apex:actionFunction action="{!getContractsByLeaseStatus}" name="getContractsByLeaseStatusJS" reRender="contractSelector"> <apex:param name="leaseStatus" assignTo="{!contractLeaseStatusFilter}" value="contractId"/> </apex:actionFunction> </apex:outputPanel> </apex:form> </apex:page>
Page rendering:
- Rob Koch 1
- August 11, 2020
- Like
- 0
- Continue reading or reply
Custom clone button question
Hello. I am working on a custom button that will basically create a new record prepopulated with the values on the original record.
But I do not want any related child items to be carried over.
How do I ensure that only the values come over, with no related items?
But I do not want any related child items to be carried over.
How do I ensure that only the values come over, with no related items?
- Rob Koch 1
- July 21, 2020
- Like
- 0
- Continue reading or reply
Apex Trigger to Update Account on Asset Delete
Hello, I am looking to create a trigger that will update an account field to "Null" or "0" when a child asset is deleted. The two account fields are Max Advisor Count, and Max Mortgage Advisor Count. When adding an asset, depending on the type, it will add a quantity of "1" to either the Max Advisor Count or the Max Mortgage Advisor Count.
I set up Process Builder to update those counts when an asset record is created or changed. But it looks like I will need a trigger to set either of those counts to 0 when an asset record is deleted.
All I need is for the trigger to fire after an asset is deleted. Any suggestions are welcome, thank you!!!
I set up Process Builder to update those counts when an asset record is created or changed. But it looks like I will need a trigger to set either of those counts to 0 when an asset record is deleted.
All I need is for the trigger to fire after an asset is deleted. Any suggestions are welcome, thank you!!!
- Rob Koch 1
- October 04, 2017
- Like
- 0
- Continue reading or reply
Custom clone button question
Hello. I am working on a custom button that will basically create a new record prepopulated with the values on the original record.
But I do not want any related child items to be carried over.
How do I ensure that only the values come over, with no related items?
But I do not want any related child items to be carried over.
How do I ensure that only the values come over, with no related items?
- Rob Koch 1
- July 21, 2020
- Like
- 0
- Continue reading or reply
Apex Trigger to Update Account on Asset Delete
Hello, I am looking to create a trigger that will update an account field to "Null" or "0" when a child asset is deleted. The two account fields are Max Advisor Count, and Max Mortgage Advisor Count. When adding an asset, depending on the type, it will add a quantity of "1" to either the Max Advisor Count or the Max Mortgage Advisor Count.
I set up Process Builder to update those counts when an asset record is created or changed. But it looks like I will need a trigger to set either of those counts to 0 when an asset record is deleted.
All I need is for the trigger to fire after an asset is deleted. Any suggestions are welcome, thank you!!!
I set up Process Builder to update those counts when an asset record is created or changed. But it looks like I will need a trigger to set either of those counts to 0 when an asset record is deleted.
All I need is for the trigger to fire after an asset is deleted. Any suggestions are welcome, thank you!!!
- Rob Koch 1
- October 04, 2017
- Like
- 0
- Continue reading or reply
Create a Simple Camping List Lightning Component
Hi,
the challenge is as follows :
Create a camping component that contains a campingHeader and a campingList component.
1.The campingList component contains an ordered list of camping supplies that include Bug Spray, Bear Repellant, and Goat Food.
2.The campingHeader component contains an H1 heading style with a font size of 18 points and displays 'Camping List'.
so i made a lightening application named "camping.app" having code :
<aura:application >
<br/><br/><br/>
<c:campingHeader/>
<c:campingList/>
</aura:application>
where lightening component "campingHeader.cmp" having code :
<aura:component >
<h1> Camping List </h1>
</aura:component>
for I have "campingHeader.css" having code :
.THIS {
}
h1.THIS {
font-size: 18px;
}
and lightening component "campingList.cmp" having code :
<aura:component >
<ol>
<li>Bug Spray</li>
<li>Bear Repellant</li>
<li>Goat Food</li>
</ol>
</aura:component>
when i preview the application it is working nice; but when checking the challenge it says :
"Challenge Not yet complete... here's what's wrong:
The 'camping' Lightning Component does not include either the campingHeader or campingList component."
please help me know where I m doing wrong. Thanx waiting for your reply
the challenge is as follows :
Create a camping component that contains a campingHeader and a campingList component.
1.The campingList component contains an ordered list of camping supplies that include Bug Spray, Bear Repellant, and Goat Food.
2.The campingHeader component contains an H1 heading style with a font size of 18 points and displays 'Camping List'.
so i made a lightening application named "camping.app" having code :
<aura:application >
<br/><br/><br/>
<c:campingHeader/>
<c:campingList/>
</aura:application>
where lightening component "campingHeader.cmp" having code :
<aura:component >
<h1> Camping List </h1>
</aura:component>
for I have "campingHeader.css" having code :
.THIS {
}
h1.THIS {
font-size: 18px;
}
and lightening component "campingList.cmp" having code :
<aura:component >
<ol>
<li>Bug Spray</li>
<li>Bear Repellant</li>
<li>Goat Food</li>
</ol>
</aura:component>
when i preview the application it is working nice; but when checking the challenge it says :
"Challenge Not yet complete... here's what's wrong:
The 'camping' Lightning Component does not include either the campingHeader or campingList component."
please help me know where I m doing wrong. Thanx waiting for your reply
- Saroj Kushwaha
- June 16, 2016
- Like
- 1
- Continue reading or reply
Trailhead: Creating & Using Custom Controllers error
I'm on the second to last unit of the Visualforce Basics module, called Creating & Using Custom Controllers.
I THINK I have followed everything correctly (being new to coding) but I'm getting an error when in the section Add A New Action Method:
line 7: expecting a semi-colon, found "("
The custom controller I am trying to use is as follows and the line in bold is line 7:
public class ContactsListController {
private String sortOrder = 'LastName';
public List<Contact> getContacts() {
public void sortByLastName() {
this.sortOrder = 'LastName';
}
public void sortByFirstName() {
this.sortOrder = 'FirstName';
}
List<Contact> results = Database.query(
'SELECT Id, FirstName, LastName, Title, Email ' +
'FROM Contact ' +
'ORDER BY ' + sortOrder + ' ASC ' +
'LIMIT 10'
);
return results;
}
}
Any ideas on where I have gone wrong?
Thanks
Dan
I THINK I have followed everything correctly (being new to coding) but I'm getting an error when in the section Add A New Action Method:
line 7: expecting a semi-colon, found "("
The custom controller I am trying to use is as follows and the line in bold is line 7:
public class ContactsListController {
private String sortOrder = 'LastName';
public List<Contact> getContacts() {
public void sortByLastName() {
this.sortOrder = 'LastName';
}
public void sortByFirstName() {
this.sortOrder = 'FirstName';
}
List<Contact> results = Database.query(
'SELECT Id, FirstName, LastName, Title, Email ' +
'FROM Contact ' +
'ORDER BY ' + sortOrder + ' ASC ' +
'LIMIT 10'
);
return results;
}
}
Any ideas on where I have gone wrong?
Thanks
Dan
- DMalone
- December 15, 2015
- Like
- 0
- Continue reading or reply