Force.com중 Visualforce를 정리 합니다.
접속 URL : /apex/pageName
{!변수}
"설정 -> 개인 설정 -> 내 개인 정보 -> 개인 정보" 메뉴에서 "개발 모드", "개발 모드 상태 보기 표시"
Visualforce Page Sample
Layout에서 Visualforce Page를 사용하려면 다음과 같이 선언된 페이지를 미리 만들어야 합니다.
https://na7.salesforce.com/a0w/e?
CF00NA0000008Gc9u=이름
&CF00NA0000008Gc9u_lkid=아이디
Visualforce Page
{!name}
{!$ObjectType.Account.fields.fieldName.label}
Apex Code
public String name {get;}
public String getName()
public String name {get; set;}
public String getName(), public void setName(String Name)
Visualforce Page
Action, rerender=“id”, rendered
Controller.getAccount(Args, function(result, event), options)
~ = sforce.apex.execute(“ClassName”, “makeContact”, Args)
sforce.SObject, sforce.connection.query/insert/update/delete
Apex Code
public PageReference ~() { ~ }
@RemoteAction
global static Account getAccount(~) { ~ }
webService static Id makeContact(~) { ~ }
SOQL, DML
Page's view state
<- -> 일반 변수
tabStyle (/dCSS/dStandard.css, allCustom.css)
style, styleClass
$User.UITheme, $User.UIThemeDisplayed
http://wiki.developerforce.com/index.php/Using_the_Salesforce_CSS_in_Your_Apps
window.document.cookie
ApexPages.currentPage.getCookies().get(name)
Apex.currentPage().setCookies(new Cookie[](.md) {~})
Visualforce Page
,
,
Apex Code
private transient ApexPages.Message msg = null;
//--- ERROR, WARN, INFO, DEBUG, FINE, FINER, FINEST
msg = new ApexPages.Message(ApexPages.severity.ERROR, '이메일을 입력 하세요.');
ApexPages.addMessage(msg);
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, ‘~’))
ApexPages.addMessages(Exception)
sObject.addError(~), addError(Exception)
Visualforce Page
{!URLFOR(‘~’)}
{!URLFOR($Page.pageName)}
URLFOR($Action.개체.Tab, $ObjectType.개체)
URLFOR($Action.개체.List, $ObjectType.개체)
URLFOR($Action.개체.View, 아이디)
URLFOR($Action.개체.New)
URLFOR($Action.개체.Edit, 아이디)
URLFOR($Action.개체.Delete, 아이디), Clone, Accept
Apex Code
new PageReference(‘~’)
Page.pageName
Page.failure, Page.success, ~.setRedirect(true)
Schema.SObjectType.개체.getKeyPrefix() 사용
new ApexPages.StandardController(~).view()
PageReference
Office 파일 작성 방법 (Excel 사례)
Excel 파일에서 변수를 출력할 부분에 {!~} 문자열을 사용하여 작성
Excel을 htm으로 저장
zip 파일로 압축하여 Static Resource로 추가
Apex Code 예
public class CtrPaymentRequestVoucher {
public String urlBase = 'https://cs12.salesforce.com/resource/1319787964000/Template001/';
public String content {get; set;}
public CtrPaymentRequestVoucher(ApexPages.StandardController standardController) {
PageReference page = null;
page = new PageReference(urlBase + 'Template001.htm');
content = page.getContent().toString();
content = content.replace('{!title}', '안녕하세요');
}
}
Visualforce Page 예
Visualforce Page를 PDF로 저장
PDF에 한글 출력
PDF Page
size: 210mm 297mm;
margin-top : 6.0mm; margin-left : 6.0mm; margin-right : 6.0mm; margin-bottom : 6.0mm; ```
@page
@page {
margin-top: 10px;
margin-right: 10px
margin-bottom: 10px;
margin-left: 10px;
}
@page {
@bottom-center {
content: counter(page) "/" counter(pages);
color: green;
}
}
CSS3, http://dev.w3.org/csswg/
margin : top right bottom left
border : width style color : thin solid black
border-width: thin thick medium medium;
border-style: dashed solid solid solid;
none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset
border-color: lime lime lime lime;
padding : top right bottom left
vertical-align: middle 방법 :
또는 line-height: 50px;
text-align: center; text-wrap: normail; text-decoration: none;
font-color: black; font-size: 18px; font-weight: bold;
참고 문헌
{|cellspacing="0" cellpadding="2" border="1" width="100%" bgcolor="#FFFFFF" align="center" |- |width="25%" align="center" valign="middle" style="background-color:#eee;"|Page |width="75%"|
Visualforce Page에서 Controller에 해당하는 Apex Code 함수를 호출하여 동적으로 페이지를 갱신하기 위해서 rerender를 사용할 수 있습니다.
{!contact.Name}
수식에서도 7가지의 전역 변수를 사용할 수 있습니다.
//--- Visualforce Page에서 id가 test로 지정된 항목의 실제 ID값 (text)을 반환 합니다.
{!$Component.test}
window.document.all['{!$Component.test}']('{!$Component.test}'.md).innerText
{!$CurrentPage.parameters.parameter_name}
{!$CurrentPage.parameters.caseId != null}
$ObjectType.empoloyees__c
$ObjectType.objectname.accessible
$ObjectType.account.fields.Name.label
$ObjectType.Case.Fields[caseField](caseField.md).label
{!$ObjectType.Contact.Fields[f](f.md).label}
({!$ObjectType.Contact.Fields[f](f.md).type}):
{|cellspacing="0" cellpadding="2" border="1" width="100%" bgcolor="#FFFFFF" align="center" |- |width="20%" align="center" valign="middle" style="background-color:#eee;"|탭 |width="40%"|
width="40%" |
---|
align="center" valign="middle" style="background-color:#eee;" |
public with sharing class ~ {
public CtrViewItem(ApexPages.StandardController controller) {
}
}
public with sharing class ~ {
public CtrViewList(ApexPages.StandardSetController controller) {
}
}
public with sharing class BaseItemController {
public BaseItemController(ApexPages.StandardController controller) {
}
}
public with sharing class BaseDataController {
public BaseDataController(ApexPages.StandardSetController standardSetController) {
}
}
Map ~.getAll()
~ = ~.getInstance(name)
~ = ~.getValues(name)
~ = ~.getInstance()
~ = ~.getInstance(userId 또는 profileId)
~ = ~.getValues(userId 또는 profileId)
~ = ~.getOrgDefaults()
{!$Label.~}
System.Label.~
{!~} : name 또는 assignTo에 할당된 변수 사용법
//--- 전달된 component의 본문(내용)
//--- 본문에서 사용할 변수 할당
{!$Resource.~} : 정적 자원의 URL
{!URLFOR($Resource.~, ‘image/aaa.png’)} : 정적 자원이 zip 파일인 경우 aaa.png 파일의 URL
"설정 -> App 설정 -> 작성 -> 개체 -> 선택 -> 표준 버튼 및 링크/사용자 정의 버튼 및 링크"
"설정 -> App 설정 -> 작성 -> 개체 -> 선택 -> 표준 버튼 및 링크/사용자 정의 버튼 및 링크"
"설정 -> App 설정 -> 작성 -> 개체 -> 선택 -> 페이지 레이아웃"
복잡한 사용자 인터페이스를 손쉽게 개발
"설정 -> 개인 설정 -> 내 개인 정보 -> 개인 정보" 메뉴에서 Force.com Flow 사용자
<flow:interview />
Map<String, Object> myMap = new Map<String, Object>(); myMap.put('vaCaseNumber','123456'); myflow = new Flow.Interview.ModemTroubleShooting(myMap);

로그인 후에 사용할 수 있는 Visualforce Page로 사이트에서 사용시 로그인 없이도 접속이 가능 합니다.
호출 URL
/apex/페이지명
구성 요소 참조 : https://na7.salesforce.com/apexpages/apexcomponents.apexp
//--- HTML, JavaScript 등
//--- EMP_METATAG 구성 요소 추가
//--- 정적자원 (Resource) 사용 방법
//--- zip 형태의 resource에 포함된 qstyles_N.css 사용
Visualforce Components
{!EvaluationResult__c.필드명} : StandardController에 해당하는 레코드의 필드값
public class CtrUserHome {
private final SNB_HR_empoloyees__c item;
public CtrUserHome(ApexPages.StandardController controller) {
ID id = null;
if (id == null) {
item = new SNB_HR_empoloyees__c();
} else {
item = [SELECT id
FROM Account
WHERE id = :ApexPages.currentPage().getParameters().get('id')];
}
//--- 또는
item = (Account)controller.getRecord();
}
public PageReference gotoTest() {
PageReference acctPage = new PageReference('/apex/test);
acctPage.setRedirect(true);
return acctPage;
}
}
public class CtrUserHome {
public ApexPages.StandardSetController controller = null;
private final List data;
public CtrUserHome(ApexPages.StandardSetController controller) {
if (this.controller == null) {
this.controller = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT id, name,closedate
FROM Account]));
}
//--- 또는
data = (List)controller.getRecords();
}
public PageReference gotoTest() {
PageReference acctPage = new PageReference('/apex/test);
acctPage.setRedirect(true);
return acctPage;
}
}
enhancedList
<apex:enhancedList type="Account"
height="370" rowsPerPage="10"
id="AccountList" customizable="true"
rendered="{!$ObjectType.Account.accessible}">
<apex:pageBlock rendered="NOT({!$ObjectType.Account.accessible})"> <p>개체에 대한 권한이 없습니다.</p> ```
ListViews
<p>개체에 대한 권한이 없습니다.</p>
pageBlockTable
<p>개체에 대한 권한이 없습니다.</p>
dataTable
계정 목록
table header
table footer
Name
column footer
Owner
column footer
<p>개체에 대한 권한이 없습니다.</p>
dataList
{!item.name}, {!item.site},
{!item.type}, {!item.accountNumber}
<p>개체에 대한 권한이 없습니다.</p>
List, Map에 저장된 data 표시 방법
,
,
,
<p>개체에 대한 권한이 없습니다.</p>
detail
<p>개체에 대한 권한이 없습니다.</p>
pageBlockSection / inputField, outputField
<p>개체에 대한 권한이 없습니다.</p>
apex:dynamicComponent
Mobile 확인을 위한 UserAgent 체크
String userAgent = null;
userAgent = ApexPages.currentPage().getHeaders().get('USER-AGENT');
if (userAgent.contains('iPhone')) {
} else if(userAgent.contains('Android')) {
} else if(userAgent.contains('BlackBerry')) {
}
모바일 화면의 높이를 계산
function getScreenHeight() {
var orientation = null;
try {
orientation = jQuery.event.special.orientationchange.orientation();
} catch (ex) {
orientation = "portrait";
}
var port = orientation === "portrait",
winMin = port ? 480 : 320,
screenHeight = port ? screen.availHeight : screen.availWidth,
winHeight = Math.max( winMin, $( window ).height() ),
pageMin = Math.min( screenHeight, winHeight );
return pageMin;
}
<apex:inputText id="smsReserveDate" value="{!smsReserveDate}" onfocus="DatePicker.pickDate(true, this.id, false);" style="width: 75px;" />
href="javascript:DatePicker.insertDate('2012. 4. 12', '{!$Component.smsReserveDate}', true);">2012. 4. 12