Home Tab For a Single Record Type:
This example shows calling an action from picklist and re-rendering a portion of the page.
public class crrecordTypeHomeTab {
static string rid = 'Supplier'; // change to match the record type for the tab
boolean which = true; // which list are we showing, simple toggle
public Account[] getAccounts() {
if (!which) {
return [select id,name,lastmodifieddate,billingcity,billingstate,phone,type,recordType.name from
Account where recordType.name = :rid order by createddate desc limit 20];
}
return [select id,name,lastmodifieddate,billingcity,billingstate,phone,type,recordType.name from
Account where recordType.name = :rid order by lastmodifieddate limit 20];
}
public PageReference changeRt() { // toggle a static var to flip between recent modified or created items
which = ( ! which) ;
return null;
}
public PageReference newRt() { // construct a new record with this record type already set
RecordType r = [select id from RecordType where Name = :rid];
PageReference p = new PageReference('/001/e?RecordType=' + r.id +
'&retURL='+ getBasePageName() );
p.setRedirect(true);
return p;
}
public string getBasePageName() {
PageReference cur = System.CurrentPageReference();
String url = cur.getUrl();
String [] basearray = url.split('\\?');
return basearray[0];
}
public String getUrl() {
return getBasePageName();
}
public static testMethod void testMyControler() {
RecordTypeHomeTab t = new RecordTypeHomeTab();
Account[] a = t.getAccounts();
t.changeRt();
t.getAccounts();
//System.Assert( t.getReportsArea() != '' );
//System.Assert( t.getToolsArea() != '' );
System.Assert( t.newRt() != null);
Boolean beforet = t.which;
t.changeRt();
System.Assert( beforet != t.which);
System.assert( t.getUrl() != '' );
}
}
<apex:page controller="crrecordTypeHomeTab" tabStyle="Account" >
<apex:sectionHeader title="Supplier Record Type" subtitle="Home" ></apex:sectionHeader>
<apex:pageBlock >
<apex:facet name="header" >
<apex:form ><apex:panelGrid styleClass="list" columnClasses="pbTitle,pbButton,pbHelp" columns="3" border="0" cellpadding="0" cellspacing="0" >
<apex:outputLabel ><h3>Recent Items</h3></apex:outputLabel>
<apex:commandButton value=" New " styleClass="btn" action="{!newRt}" ></apex:commandButton>
<apex:selectList id="recent" size="1" >
<apex:actionSupport event="onchange" action="{!changeRt}" reRender="recentmodify"></apex:actionSupport>
<apex:selectOption itemLabel="Recently Modified" itemValue="mod"></apex:selectOption>
<apex:selectOption itemLabel="Recently Created" itemValue="cre"></apex:selectOption>
</apex:selectList>
</apex:panelGrid></apex:form>
</apex:facet>
<!-- main record type data table -->
<apex:actionStatus >
<apex:facet name="start"><h1>Requesting...</h1></apex:facet>
<apex:facet name="stop">
<apex:dataTable id="recentmodify" value="{!accounts}" var="a" bgcolor="#F3F3EC"
styleClass="list" rowClasses="dataRow" onRowMouseOver="hiOn(this);" onRowMouseOut="hiOff(this);">
<apex:column >
<apex:facet name="header" ><b>Name</b></apex:facet>
<apex:outputLink value="/{!a.id}" >
{!a.name}
</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header"><b>Billing City</b></apex:facet>
{!a.billingcity}
</apex:column>
<apex:column >
<apex:facet name="header"><b>Phone</b></apex:facet>
{!a.Phone}
</apex:column>
<apex:column >
<apex:facet name="header"><b>Record Type</b></apex:facet>{!a.RecordType.Name}
</apex:column>
</apex:dataTable>
</apex:facet></apex:actionStatus>
</apex:pageBlock>
</apex:page>
No comments:
Post a Comment