Posts

Showing posts from 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...

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:

Help Text on mouseover

Image
While using Title Attribute in <apex:selectOption> which is supposed to show the help text is not working, the below process works have a try!! Code: VF page:                            <apex:selectRadio layout="pagedirection" id="myList">                                                       <apex:selectOptions value="{!items}"/>                            </apex:selectRadio> Controller:  public List<SelectOption>  items =new List<SelectOption> ();  public List<SelectOption> getItems() {         List<SelectOption> options = new List<SelectOption>();         SelectOption so1 = new SelectOpt...

How to call a Visual Flow using Button and VF Page

Image
Through Button:   Call by using the URL Through VF page: Flow with a input Parameter <apex:page standardController="Case" tabStyle="Case" >     <flow:interview name="ModemTroubleShooting">         <apex:param name="vaCaseNumber" value="{!Case.CaseNumber}"/>     </flow:interview> </apex:page> P.S:  Comment Below for any Clarification or help!! Happy working!! :) :) 

Some Common Errors in the Visual flow

Error: An unhandled fault has occurred in this flow An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information Solution:  You Would get a detailed error description to the register email. Error: An Apex error occurred: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Task Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]  Solution: The user Might not have access to the Particular Record Type. Or you may be refreing to 15 Digit RecordType Id. Refer 18 Digit ID to solve the issue. Error: Error Occurred: The number of results does not match the number of interviews that were executed in a single bulk execution request. Solution: The size of the return value needs to match the input value. Resolved the issue by using void. P.S:  Comment Below for any Clarification or help!! Happy working!! :) :)  ...