Category Archives: Salesforce

InputField datePicker is missing when standardStylesheets are disabled in Visualforce Page

Sample Code:

<apex:page standardController="Opportunity" showHeader="false" standardStylesheets="false" docType="html-5.0">
   <apex:form id="frm">
      <apex:pageBlock title="Opportunity">
         <apex:pageBlockSection title="Opportunity Information" collapsible="false">
            <apex:inputField value="{!Opportunity.ClosedDate}" showDatePicker="false" type="datetime-local" />
         </apex:pageBlockSection>
         <apex:pageBlockButtons>
            <apex:commandButton value="Save" action="{!save}"/>
         </apex:pageBlockButtons>
      </apex:pageBlock>
   </apex:form>
</apex:page>

Send Email To Non-Contacts Using Apex

Using renderStoredEmailTemplate(templateId, whoId, whatId) method of Messaging Class, we can send email to non-contacts using apex. Here is an example to send email to Opportunity owner.

Sample code:

//Send email to opportunity owner
Messaging.SingleEmailMessage mail = Messaging.renderStoredEmailTemplate(emailTemplateId, ownerId, opportunityId);
mail.setTargetObjectId(ownerId);
mail.setSubject(mail.getSubject());
mail.sethtmlBody(mail.gethtmlBody());
mail.saveAsActivity = false;
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

Restrict Numbers And Special Characters In Visualforce Page Input Field

Sample Code:

<apex:page standardController="Lead" docType="html-5.0">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputField id="firstname" value="{!Lead.FirstName}" onkeypress="return (event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123)" />
                <apex:inputField id="lastname" value="{!Lead.LastName}" onkeypress="return (event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123)" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>