Posts

Showing posts from October, 2017

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...