July, 2016
SALESFORCE icons available
http://free-121d5f44d20-121d603d1c5-121ee2b8103.force.com/force2b/salesforceicons Favorite
How to user apex:stylesheet in visualforce page?
1 2 3 4 5 6 7 8 |
Step 1: Create a CSS file. Save the file with a .css extension Step 2: Upload the saved file as a Static resource. Have reference in VFP like this: <apex:stylesheet value="{!$Resource.CssExample}"/> |
Another way of referencing is:
1 |
<apex:stylesheet value="{!URLFOR($Resource.myofferZIP, 'myofferCSS.css')}"/> |
Favorite
String is null or empty or blank using Apex in Salesforce
To check whether a String is null or empty or blank using Apex in Salesforce, we can use the following methods
1 2 3 4 5 6 7 8 9 10 11 |
isBlank Returns true if the specified String is white space, empty (''), or null; otherwise, returns false. isEmpty Returns true if the specified String is empty ('') or null; otherwise, returns false. isNotBlank Returns true if the specified String is not whitespace, not empty (''), and not null; otherwise, returns false. isNotEmpty Returns true if the specified String is not empty ('') and not null; otherwise, returns false. |
Sample Code:
1 2 3 4 5 6 7 |
String var = 'abc'; if(String.isNotBlank(var)) { //The string is not empty or blank or null } else { //The string is empty or blank or null } |
Favorite
ApexPages.addMessages
Here are some examples of how to add messages with different severities and how they are outputted: VFP:
1 |
<apex:pageMessages /> |
APEX Controller: Confirm/Success:
1 2 |
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Confirm,'Sample Success Message')); |
Warning:
1 2 |
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Warning,'Sample Warning Message')); |
Informational:
1 2 |
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Info,'Sample Informational Message')); |
Error:
1 2 |
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Error,'Sample Error Message')); |
Favorite
Remove –None– from Salesforce Picklist
1 2 3 4 5 6 7 8 9 10 11 12 |
<apex:page standardController="Lead"> <apex:form> <script type='text/javascript' src= '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'> </script> <script language="javascript"> $(function() { $('select.RemoveNone option[value=]').remove(); }); </script> <apex:inputField styleClass="RemoveNone" value="{!Lead.LeadSource}"/> </apex:form> </apex:page> |
Favorite
Managing Matching/Duplicates Rules
How to detect the duplicate records using Duplicate Management:
1 2 3 4 5 6 7 8 9 10 11 |
Step 1: MATCHING RULES: Setup--> Data.com Administration -->Duplicate Management -->Matching Rules (Click) -->New -->Select the object --> Rule Name: "Unique Name matching rule" (of whatever it suites your needs) --> Field: Name --> Matching Method: Exact -->Save/Activate |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Step 2: DUPLICATE RULES: Setup--> Data.com Administration -->Duplicate Management -->Duplicate Rules (Click) -->New Rule -->Select the object --> Rule Name: "Unique Name" (of whatever it suites your needs) -->Record-Level Security: Enforce sharing rules -->Action on Create/Edit: Block -->Compare Merchants With: <select your object> -->Matching Rule: select the matching rules you have created in the STEP 1 -->Save/Activate |
Favorite
Visualforce page Search: InputText with Button
Visualforce page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
<apex:page standardcontroller="Offer__c" extensions="OfferPreviewExtController" title="Offer - {!Offer__c.Name}" sidebar="false" showHeader="false"> <!-- Page Header --> <!--apex:sectionHeader title="Candidate Edit" subtitle="New Candidate" /--> <br/> <apex:image style="padding:5px;" value="http://www.rbcroyalbank.com/rds/v2/_assets/images/logos/logo-rbcroyalbank.com.svg" styleClass="logo" /> <!-- Begin Form --> <br/> <style type="text/css"> .bg { color:white !important; background:#00CC00 !important; } </style> <apex:form > <apex:pageBlock > <center> <apex:outputLabel value="Offer ID: " style="font-size:22px;"></apex:outputLabel> <apex:inputText value="{!searchText}" id="theSearchstring" styleClass="increaseSize" style="font-size:32px;width: 350px; height: 38px"/> <apex:commandButton rerender="op_detail" Id="btnSearch" action="{!search}" title="Search" value=" GO " style="font-size:27px;" styleClass="bg"> </apex:commandButton> </center> </apex:pageBlock> <apex:outputPanel id="op_detail"> <apex:outputPanel rendered="{!searchResultsFound==false}" > <apex:pageMessage summary="No Offer found matching criteria!" severity="warning" strength="3" /><apex:pageMessages /></apex:outputPanel> <apex:pageBlock title="Offer Preview" id="pb" rendered="{!searchResultsFound }" > <apex:pageBlockSection title="General Information" columns="2" > <apex:repeat value="{!SearchResults}" var="off"> <apex:pageBlockSection > <apex:outputField value="{!off.Offer_Id__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Offer_Status__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Name}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Inactive_Reason__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Display_Name_En__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Display_Name_Fr__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Requested_Approval_Date__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Merchant__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Offer_API_Name__c}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:outputField value="{!off.Offer_Program__c}"/> </apex:pageBlockSection> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page> |
Controller:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
public class OfferPreviewExtController { transient public List<Offer__c> searchResults {get; set; } public boolean searchClicked {get; set; } public OfferPreviewExtController(ApexPages.StandardController controller) { searchClicked = false; } public string searchText { get { if (searchText==null) searchText = ''; return searchText; } set; } public boolean searchResultsFound {get; set;} public void isRecordFound() { searchResultsFound = true; if(SearchResults !=null) { if(SearchResults.isEmpty()) { searchResultsFound = false; //not found } } } public PageReference search() { searchClicked = true; if(SearchResults == null) { SearchResults = new List<Offer__c >(); } else { SearchResults.Clear(); } SearchResults = [Select Offer_Id__c,Id, Name,Offer_Status__c,Inactive_Reason__c,Display_Name_En__c,Display_Name_Fr__c,Requested_Approval_Date__c,Merchant__r.Name,Offer_API_Name__c,Offer_Program__c from Offer__c where name =: searchText]; if(!SearchResults.isEmpty()) { searchResultsFound = true; } else { searchResultsFound = false; } return null; } } |
Favorite
Visualforce page with two columns
1 2 3 4 5 6 7 8 9 10 11 12 |
<apex:pageBlockSection> <apex:repeat value="{!accounts}" var="acc"> <apex:pageBlockSection> <apex:outputLink value="{!URLFOR($Action.Account.Edit, acc.id, [retURL=URLENCODE('/apex/RetUrlSearchPage?query='+nameQuery)}"> {!acc.Name} </apex:outputLink> </apex:pageBlockSection> <apex:pageBlockSection> <apex:outputField value="{!acc.BillingStreet}" /> </apex:pageBlockSection> </apex:repeat> </apex:pageBlockSection> |
Favorite
Salesforce – Making the User Object standard field Unique.
PS: make sure to add
1 |
<apex:pageMessages id="pageMsg"/> |
on the VFP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
trigger ExtesionTrigger on User (before insert , before update) { Set<String> setExtension = new Set<String>(); for(User u : trigger.new) { Boolean isNewExt = setExtension.add(u.Extension); //This will ensure that in bulk insert you are not inserting two users with same extension if(!isNewExt) u.addError('Dulicate Extension'); } List<User> ul = [Select id from User where Extension in: setExtension]; if(ul.size() > 0) { trigger.new.get(0).addError('Dulicate Extension'); } } |
Favorite
Salesforce – How to determine the value is unique
At first let us create a new Field on the custom object/standard object.
1 2 3 4 5 6 7 8 |
1. Go to Setup | Customize | Accounts | Fields. 2. Scroll down to Custom Fields & Relationships Section. 3. Click New Field. 4. Select the Type as: Text 5. Name it as: Account Name Dupe Check[Field_Name_Dupe_Check, 255]. 6. Check the Option: Unique and also select: 'Treat "ABC" and "abc" as different values (case sensitive)'. 7. Make it Visible for the appropriate Profiles. While you make them Visible also check the Option: 'Read Only'. 8. You need not put them on the Page Layouts. |
Now, let us create a new Workflow Rule[Account Dupe Check].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
1. Go to Setup | Create | Workflows & Approvals | Workflow Rules. 2. Click New Rule. 3. Select the Object: custom or standard object 4. Evaluation Criteria: created and every time it's edited. 5. Rule Criteria: criteria are met. 6. Field: select your field OPERATOR: not equal to 7. Save & Next. 8. From under Immediate Actions, click Add Workflow Action to select 'Field Update'[Set the Name]. 9. Select the Field to Update: object Name Dupe Check 10. Select: Use a formula to set the new value 11. In the formula box, type in 'Name'. 12. Click Save. 13. Click Done. 14. Activate the WFR. |
Favorite