<apex:page controller="OrderStatusUpdate" id="pageId"> <script type="text/javascript"> function updateStatus(input,id) { if(input.checked){ document.getElementById(id).value="Processing"; //alert(document.getElementById(id).value); }else{ document.getElementById(id).value="New"; //alert(document.getElementById(id).value); } } </script> <apex:form id="formId"> <apex:pageBlock id="pageBId"> <apex:pageBlockTable id="tableId" value="{!Orders}" var="order"> <apex:column value="{!order.Name}"/> <apex:column value="{!order.Customer__c}"/> <apex:column id="checkId" headerValue="Status"> <apex:inputField id="inputStatus" value="{!order.Status__c}" /> </apex:column> <apex:column headerValue="Started Processing" > <apex:selectCheckboxes onclick="updateStatus(this,'{!$Component.inputStatus}');" > </apex:selectCheckboxes> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
<apex:page controller="JavaScriptRemotingController" id="pageId"> <script type="text/javascript"> function updateStatus(input,id) { var inputStatus=id; JavaScriptRemotingController.doStartShipping(inputStatus,function(result,event){ },{escape:true}); }</script> <apex:form id="formId"> <apex:pageBlock id="pageBId"> <apex:pageBlockTable id="tableId" value="{!Orders}" var="order"> <apex:column value="{!order.Name}"/> <apex:column value="{!order.Customer__c}"/> <apex:column id="checkId" headerValue="Status"> <apex:inputField id="inputStatus" value="{!order.Status__c}" /> </apex:column> <apex:column headerValue="Started Processing" > <apex:selectCheckboxes onclick="updateStatus(this,'{!order.Id}');"> </apex:selectCheckboxes> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
global with sharing class JavaScriptRemotingController {
public List<Order__c> Orders{
get{
Orders = new List<Order__c>();
Orders = [SELECT id, Name, Customer__c, Status__c, Planned_Delivery_Date__c, Delivered__c FROM Order__c LIMIT 1000];
return Orders;
}
set;
}
public JavaScriptRemotingController(){
}
@RemoteAction
global static Item__c doStartShipping(String para){
Order__c updateOrder;
try{
updateOrder=[SELECT id, Name, Customer__c, Status__c, Planned_Delivery_Date__c, Delivered__c FROM Order__c Where Id =: para];
updateOrder.Status__c = 'Shipping';
update updateOrder;
}catch(DMLException e){
ApexPages.addMessages(e);
return null;
}
return null;
}
}
<apex:page StandardController="Order__c" id="pageId"> <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <script type="text/javascript"> j$ = jQuery.noConflict(); j$(document).ready(function() { j$('.checkBox').click(function () { j$('.inputStatus').val('Processing'); }); }); </script> <apex:form id="formId"> <apex:pageBlock id="pageBId"> <apex:pageBlockSection id="pBlockSection"> <apex:outputField value="{!Order__c.Name}"/> <apex:outputField value="{!Order__c.Customer__c}"/> <apex:inputField styleClass="inputStatus" value="{!Order__c.Status__c}" /> <apex:pageBlockSectionItem id="pbSectionItem"> <apex:outputLabel value="Mark as Started Processing"></apex:outputLabel> <apex:selectCheckboxes styleClass="checkBox" > </apex:selectCheckboxes> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
<apex:page docType="html-5.0" sidebar="false" showHeader="false" standardStylesheets="false" cache="true" > <html> <head> <style type="text/css"> #div1 {width:400px;height:400px;padding:10px;border:1px solid #aaaaaa;} </style> <script> function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("Text",ev.target.id); } function drop(ev) { ev.preventDefault(); var data=ev.dataTransfer.getData("Text"); ev.target.appendChild(document.getElementById(data)); } </script> </head> <body> <p>Drag the Salesforce logo into the rectangle:</p> <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div> <br/> <img id="drag1" src="{!URLFOR($Resource.CustomStyleZip,'/CustomStyleZipFolder/images/sfLogo.png')}" draggable="true" ondragstart="drag(event)" width="400" height="400"/> </body> </html> </apex:page>
<apex:page controller="DynamicBindingsMapListExample"> <apex:form > <apex:actionFunction name="reDisplayCustomers" rerender="cust" /> <apex:pageBlock title="Criteria"> <apex:outputLabel value="Starting Letter"/> <apex:selectList value="{!selectedKey}" size="1" onchange="reDisplayCustomers()"> <apex:selectOptions value="{!keys}" /> </apex:selectList> </apex:pageBlock> <apex:pageBlock title="Customers"> <apex:outputPanel id="cust"> <apex:pageBlockTable value="{!customerMap[selectedKey]}" var="cus"> <apex:column value="{!cus.name}"/> <apex:column value="{!cus.Address__c}"/> <apex:column value="{!cus.Email__c}"/> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
public class DynamicBindingsMapListExample
{
public Map<string, List<Customer__c>> customerMap{get; set;}
public List<selectoption> keys {get; set;}
public String selectedKey {get;set;}
public Map<string, Customer__c> custByName {get;set;}
public Set<string> getMapKeys()
{
return customerMap.keySet();
}
public DynamicBindingsMapListExample()
{
custByName = new Map<string, Customer__c>();
List<string> sortedKeys=new List<string>();
customerMap = new Map<string, list<Customer__c>>();
customerMap.put('All', new List<Customer__c>());
List<Customer__c> customers = [SELECT Id, Name, Email__c, Address__c FROM Customer__c ORDER BY Name asc];
for (Customer__c tempCustomer : customers)
{
customerMap.get('All').add(tempCustomer);
String start = tempCustomer.Name.substring(0,1);
List<Customer__c> custFromMap = customerMap.get(start);
if (custFromMap == null)
{
custFromMap =new List<Customer__c>();
customerMap.put(start, custFromMap);
}
custFromMap.add(tempCustomer);
custByName.put(tempCustomer.name, tempCustomer);
}
keys=new List<selectoption>();
for (String key : customerMap.keySet())
{
if (key != 'All')
{
sortedKeys.add(key);
}
}
sortedKeys.sort();
sortedKeys.add(0, 'All');
for (String key : sortedKeys) {
keys.add(new SelectOption(key, key));
}
selectedKey='All';
}
}
Working with field sets
A field set is a group of fields which can be defined in a declarative manner. Field sets are available in Visualforce pages in the API Version 21.0. These field sets can be displayed on a Visuaforce page by dynamic binding. For example, suppose we have created a field set (field set name:
CustomerDetails) with the Email__c, Name, and Address__c fields of the customer object. We can refer to the CustomerDetailsfield set in Visualforce as follows:<apex:page standardController="Customer__c"> <apex:repeat value="{!$ObjectType.Customer__c.FieldSets.CustomerDetails}" var="f"> <apex:outputText value="{! Customer__c [f]}" /><br/> </apex:repeat> </apex:page>
When we want to create a managed package or add/ remove/reorder fields in the field set, we can accomplish that without modifying any code.