Skip to content

Instantly share code, notes, and snippets.

@mxalix258
Created June 26, 2013 01:04
Show Gist options
  • Save mxalix258/5863899 to your computer and use it in GitHub Desktop.
Save mxalix258/5863899 to your computer and use it in GitHub Desktop.
Replace "New" page with visualforce page with apex extension
<apex:page standardController="Leave_Request__c" extensions="vacationdays" showHeader="true" sidebar="true">
<apex:form >
<apex:sectionHeader subtitle="New Leave Request" title="Leave Request Edit"/>
<apex:pageBlock title="Leave Request Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" >
<apex:outputField label="Owner" value="{!UserInfo.Name}"/>
<apex:inputField value="{!Leave_Request__c.Manager__c}"/>
<apex:inputField value="{!Leave_Request__c.Dates_of_Requested_Leave__c}" required="true"/>
<apex:inputField value="{!Leave_Request__c.Status__c}" required="true"/>
<apex:inputField value="{!Leave_Request__c.Type__c}" required="true"/>
<apex:outputField label="Total Vacation Days Allowed" value=" {!UserInfo.Yearly_Vacation_Days__c}"/>
<apex:inputField value="{!Leave_Request__c.Total_Days_Off__c}" required="true"/>
<apex:outputField label="Remaining Vacation Days" value=" {!UserInfo.Vacation_Days__c}"/>
<apex:inputField value="{!Leave_Request__c.Comments__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class vacationdays {
Public User CurrentUser {get;set;}
public vacationdays(ApexPages.StandardController controller) {
}
public User getUserInfo(){
String userid = UserInfo.getUserId();
CurrentUser = [SELECT ID, Name, FirstName, LastName, Vacation_Days__c, Yearly_Vacation_Days__c FROM User WHERE Id =:userid];
return CurrentUser;
}
}
@isTest
private class vacationdaysTEST{
private static testMethod void vacationdaysTEST(){
Leave_Request__c lr = new Leave_Request__c();
ApexPages.StandardController sc = new ApexPages.StandardController(lr);
vacationdays controller = new vacationdays(sc);
controller.getUserInfo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment