Posts

Email Format Validation in Apex

Apex provides patterns and matchers that enable you to search text using regular expressions. And you can use that to validated, if the entered email address is valid or not in apex using the below code.Give a try! Code: Pattern p = Pattern.compile( '([a-zA-Z0-9_\\-\\.]+)@(((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3}))');          Matcher m = p.matcher(leadVar.Email);          if (!m.matches()) {             System.debug('Please enter a valid email address');                     return null;          } Ref: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_using.htm https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_pattern_methods.htm P.S:  Comment B...

Platform Cache Usage

Image
The platform cache is temporary cache and a performance-optimization technique. Divided into Org Cache and Session Cache. Here I used Session Cache which is cache space for an individual user session. Our Organization(Unlimited Edition) has 30MB free by Default. I allocated 5MB for session Cache and used it. Setup Platform Cache: Setup--> Develop-->Platform Cache How do we use this session Cache? Example: When you don't want to pass the variable in URL .You can use Platform cache. Code:   public with sharing class testClass {   public String test{get;set;}      public PageReference download(){              if (test!= null){           Cache.Session.put('test', test);    } } public with sharing cl...

Add and remove Members to permission set which adds and removes them automatically to public group

Add and remove Members to permission set which adds and removes them automatically to public group Permission Set Used: test_permission_set GroupId Used: 00Zx0000002ABCD Code below: global class AssignPermissionSetBatch implements Database.Batchable<SObject>{           // Start Method     global Database.QueryLocator  start(Database.BatchableContext bc){         system.debug([SELECT AssigneeId,Id,PermissionSetId,SystemModstamp FROM PermissionSetAssignment WHERE PermissionSetId IN ( SELECT Id FROM PermissionSet WHERE Name = 'test_permission_set')]);         return Database.getQueryLocator([SELECT AssigneeId,Id,PermissionSetId,SystemModstamp FROM PermissionSetAssignment WHERE PermissionSetId IN ( SELECT Id FROM PermissionSet WHERE Name = 'test_permission_set')]);     }        ...

Validate VF page required Fields Using JavaScript

Image
Output:                                       Code:    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />    <apex:includeScript value="https://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"/>     <head>    <style type="text/css">    .error {        border-color: #E51400;        background-color: #FFF0EF;    }    </style>   </head>   <body>        <apex:form id="CustomerForm">            <label for="customerName">Name &nbsp;</label>                <apex:inputField value="{!caseVar.SuppliedName}"   html-placeHolder="Cu...

Radio Button using input tag with type=radio in VF page and action support tag

VF Page:  <apex:page standardController="User" extensions="UserTestController">      <apex:form >         <apex:pageblock >                 <apex:outputPanel id="ca"><apex:pageMessages /></apex:outputPanel>             <apex:outputPanel id="counter">             <table cellpadding="7" cellspacing="7" border="1">                             <th>Select</th>                            <th> User Name</th>       ...

Validation Rule/Workflow Rules/Approval Process/ Page layouts and Record Types

Validation Rule: Validation rules verify that the data a user enters in a record meets the standards you specify before the user can save the record Validation Rules in Salesforce can help you enforce data quality. In other words, prevents users from saving incorrect data. Sample Validation Rules: https://developer.salesforce.com/docs/atlas.en-us.usefulValidationRules.meta/usefulValidationRules/fields_useful_validation_formulas_account.htm We can make a field required. We can limit the length We can limit the range Page layouts and Record Types: Different business process and different picklist values. http://www.salesforcetutorial.com/page-layouts-and-record-types-in-salesforce/ Workflow Rules: Workflow rules can help AUTOMATE the few actions such as ·       New  Tasks: Assign a new task to a user, role, or record owner.             Frequent Errors:             htt...

DatePicker in VF page

Image
Tried and tested this easy way. Use <apex:input> tag and refer the date variable in apex controller,which Shows up in date picker format VF Page:   <h4><b>Sample date: </b></h4>                            <apex:input type="date" value="{!sampleDate}"/> Controller: public Date sampleDate{ get; set; }          public pagereference saveRec(){           } Result: