Tag Archives: Visualforce Page

Helptext Is Not Working In Lighting Out

Due to some issue in Salesforce lightning css, helpText is not displaying properly in lightning out. Using following styles in your visualforce page, you can display the helptext properly.

CSS:

<style>
        .slds-popover {
        position: relative;
        border-radius: .25rem;
        width: 20rem;
        min-height: 2rem;
        z-index: 6000;
        background-color: #fff;
        display: inline-block;
        box-shadow: 0 2px 3px 0 rgba(0, 0, 0, .16);
        border: 1px solid #d9dbdd;
        font-family: 'Salesforce Sans',Arial,sans-serif;
        }
        
        .slds-popover__body,
        .slds-popover__footer,
        .slds-popover__header {
        position: relative;
        padding: .5rem .75rem;
        word-wrap: break-word;
        }
        
        .slds-popover--tooltip .slds-popover__body,
        .slds-popover_tooltip .slds-popover__body {
        font-size: .75rem;
        color: #fff
        }
        
        .slds-popover--tooltip,
        .slds-popover_tooltip {
        width: auto;
        max-width: 20rem;
        background: #16325c;
        border: 0;
        }
        
        .slds-nubbin--bottom-left:before,
        .slds-nubbin_bottom-left-corner:before,
        .slds-nubbin_bottom-left:before {
        width: 1rem;
        height: 1rem;
        position: absolute;
        transform: rotate(45deg);
        content: '';
        background-color: inherit;
        bottom: -.5rem;
        margin-left: -.5rem;
        }
        
        .slds-nubbin--bottom-left:after,
        .slds-nubbin--bottom-left:before,
        .slds-nubbin_bottom-left-corner:after,
        .slds-nubbin_bottom-left-corner:before,
        .slds-nubbin_bottom-left:after,
        .slds-nubbin_bottom-left:before {
        left: 1.5rem;
        top: 100%;
        margin-top: -.5rem;
        }
    </style>

Redirect To Standard New Note & New Attachment Pages Using Apex

Redirect to New Attachment:

public PageReference redirectToNewAttachment() {
   PageReference pgRef = new pageReference('/p/attach/NoteAttach?pid=' + String.valueof(acc.Id).subString(0, 15) + '&retURL=' + acc.Id);
   pgRef.setRedirect(true);
   return pgRef;
}

Redirect to New Note:

public PageReference redirectToNewNote() {
   PageReference pgRef = new pageReference('/002/e?parent_id=' + String.valueof(acc.Id).subString(0, 15) + '&retURL=' + acc.Id);
   pgRef.setRedirect(true);
   return pgRef;
}

Inline Visualforce Page Needs To Redirect

Apex Class:

public class AccountExtensionController {

    public String redirectUrl {get; set;}
    public Boolean isRedirect {get; set;}
    private Account acc {get; set;}
    
    public AccountExtensionController(ApexPages.StandardController sc) {
        this.acc = (Account)sc.getRecord();
    }
    
    public PageReference redirectToNewContact() {
        isRedirect = true;
        redirectUrl = '/003/e?retURL=' + acc.Id + '&accid=' + acc.Id;
        return null;
    }
}

Visualforce Page:

<apex:page standardController="Account" extensions="AccountExtensionController" showHeader="false" sidebar="false">
    <apex:form >
        <apex:commandButton value="New Contact" action="{!redirectToNewContact}" rerender="redirectPanel" />
        <apex:outputPanel id="redirectPanel" >
            <apex:outputPanel rendered="{!isRedirect}">
                <!--redirect using javascript-->
                <script type="text/javascript">
                window.top.location.href = '{!redirectUrl}';
                </script>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>
</apex:page>

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>

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>