Monday, April 26, 2021

Salesforce - Finding required fields in an Object

Sometimes during our many trails you find the need to identify  the required fields in an object. No need to go it one by one as Salesforce already has it listed for you...


  • Navigate to Set up
  • Enter "Field Accessibility" in the search bar (on the left)
  • Select your object 


  • Now select if you would like to view it by field or by profile.

  • If you are a system administrator - Select view by Profile



  • Once you select System Administrator this will list all the fields with their access


Happy trails!



Tuesday, April 20, 2021

Salesforce Formulas - What is what

 Add

Calculates the sum of two values


Subtract

Calculates the difference of two values


Multiply

Multiplies its values


Divide

Divides its values


Exponentiation 

Raises a number to a power of a specified number


Open Parenthesis 

Specifies that the expressions within the open parenthesis and close parenthesis

are evaluated first .

All other expressions are evaluated using standard operator Parenthesis

precedence


Equal

Evaluates if two values are equivalent 


Not Equal

Evaluates if two values are not equivalent


Less Than

Evaluates if a value is less than the value that follows this symbol


Greater Than

Evaluates if a value is greater than the value that follows this symbol


Less Than or Equal

Evaluates if a value is less than or equal to the value that follows this symbol


Greater Than

if a value is greater than or equal to the value that follows this symbol Equal


AND

Evaluates if two values or expressions are both true Use this operator as an


OR

Evaluates if at least one of multiple values or expressions is true 


Concatenate

Connects two or more strings


ADDMONTHS

Returns the date that is the indicated number of months before or after a

specified date If the resulting month has fewer days than the start month then

the function returns the last day of the resulting month Otherwise the result

has the same day component as the specified date


DATE

Returns a date value from year month and day values you enter Salesforce.Displays an error on the detail page if the value of the DATE function in a formula field is an invalid date such as February in a nonleap year


DATEVALUE

Returns a date value for a datetime or text expression


DATETIMEVALUE

Returns a year month day and GMT time value


DAY

Returns a day of the month in the form of a number between and


HOUR

Returns the local time hour value without the date in the form of a number from

through


MILLISECOND

Returns a milliseconds value in the form of a number from through


MINUTE

Returns a minute value in the form of a number from through


MONTH

Returns the month a number between January and December in number

format of a given date


NOW

Returns a datetime representing the current moment


SECOND

Returns a seconds value in the form of a number from through


TIMENOW

Returns a time value in GMT representing the current moment Use this function instead of the NOW function if you only want to track time without a date


TIMEVALUE

Returns the local time value without the date such as business hours


TODAY

Returns the current date as a date data type


WEEKDAY

Returns the day of the week for the given date using for Sunday for Monday

through for Saturday


YEAR

Returns the four digit year in number format of a given date


AND

Returns a TRUE response if all values are true returns a FALSE response if one or more values are false


BLANKVALUE

Determines if an expression has a value and returns a substitute expression if it

does not If the expression has a value returns the value of the expression


CASE

Checks a given expression against a series of values If the expression is equal to

a value returns the corresponding result If it is not equal to any values it returns

the else result


IF

Determines if expressions are true or false Returns a given value if true and

another value if false


ISBLANK

Determines if an expression has a value and returns TRUE if it does not If it contains a value this function returns FALSE


ISCLONE

Checks if the record is a clone of another record and returns TRUE if one item is a clone Otherwise returns FALSE


ISNEW

Checks if the formula is running during the creation of a new record and returns TRUE if it is If an existing record is being updated this function returns FALSE


ISNULL

Determines if an expression is null blank and returns TRUE if it is If it contains a value this function returns FALSE

Important Use ISBLANK instead of ISNULL in new formulas ISBLANK has the same functionality as ISNULL but also supports text fields. Salesforce will continue to support ISNULL so you do not need to change any existing formulas


ISNUMBER

Determines if a text value is a number and returns TRUE if it is Otherwise it returns FALSE


NOT

Returns FALSE for TRUE and TRUE for FALSE


NULLVALUE

Determines if an expression is null blank and returns a substitute expression if

it is If the expression is not blank returns the value of the expression . Important Use BLANKVALUE instead of NULLVALUE in new formulas

BLANKVALUE has the same functionality as NULLVALUE but also supports text fields Salesforce will continue to support NULLVALUE so you do not need to change existing formulas


OR

Determines if expressions are true or false Returns TRUE if any expression is true Returns FALSE if all expressions are false


PRIORVALUE

Returns the previous value of a field 


ABS

Calculates the absolute value of a number The absolute value of a number is

the number without its positive or negative sign


CEILING

Rounds a number up to the nearest integer away from zero if negative


DISTANCE

Calculates the distance between two locations in miles or kilometers


EXP

Returns a value for e raised to the power of a number you specify


FLOOR

Returns a number rounded down to the nearest integer towards zero if negative


GEOLOCATION

Returns a geolocation based on the provided latitude and longitude Must be used with the DISTANCE function


LN

Returns the natural logarithm of a specified number Natural logarithms are

based on the constant e value of


LOG

Returns the base logarithm of a number


MAX

Returns the highest number from a list of numbers


MCEILING

Rounds a number up to the nearest integer towards zero if negative


MFLOOR

Rounds a number down to the nearest integer away from zero if negative


MIN

Returns the lowest number from a list of numbers


MOD

Returns a remainder after a number is divided by a specified divisor


ROUND

Returns the nearest number to a number you specify constraining the new

number by a specified number of digits


SQRT

Returns the positive square root of a given number


BEGINS

Determines if text begins with specific characters and returns TRUE if it does Returns FALSE if it does not


BR

Inserts a line break in a string of text


CASESAFEID

Converts a character ID to a case insensitive character ID


CONTAINS

Compares two arguments of text and returns TRUE if the first argument contains

the second argument If not returns FALSE


FIND

Returns the position of a string within a string of text represented as a number


GETSESSIONID

Returns the users session ID


HTMLENCODE

Encodes text and merge field values for use in HTML by replacing characters that are reserved in HTML such as the greaterthan sign with HTML entity equivalents such as gt


HYPERLINK

Creates a link to a URL specified that is linkable from the text specified


IMAGE

Inserts an image with alternate text and height width specifications


INCLUDES

Determines if any value selected in a multiselect picklist field equals a text literal

you specify


ISPICKVAL

Determines if the value of a picklist field is equal to a text literal you specify


JSENCODE

Encodes text and merge field values for use in JavaScript by inserting escape

characters such as a backslash before unsafe JavaScript characters such as

the apostrophe


JSINHTMLENCODE

Encodes text and merge field values for use in JavaScript inside HTML tags by replacing characters that are reserved in HTML with HTML entity equivalents and inserting escape characters before unsafe JavaScript characters JSINHTMLENCODEs omeValue is a convenience function that is equivalent to JSENCODEHTMLENCODE someValue That is JSINHTMLENCODE first encodes someValue with HTMLENCODE and then encodes the result with JSENCODE


LEFT

Returns the specified number of characters from the beginning of a text string


LEN

Returns the number of characters in a specified text string


LOWER

Converts all letters in the specified text string to lowercase Any characters that

are not letters are unaffected by this function Locale rules are applied if a locale

is provided


LPAD

Inserts characters you specify to the leftside of a text string


MID

Returns the specified number of characters from the middle of a text string given

the starting position


RIGHT

Returns the specified number of characters from the end of a text string


RPAD

Inserts characters that you specify to the rightside of a text string


SUBSTITUTE

Substitutes new text for old text in a text string


TEXT

Converts a percent number date datetime or currency type field into text

anywhere formulas are used Also converts picklist values to text in approval

rules approval step rules workflow rules escalation rules assignment rules

autoresponse rules validation rules formula fields field updates and custom

buttons and links


TRIM

Removes the spaces and tabs from the beginning and end of a text string


UPPER

Converts all letters in the specified text string to uppercase Any characters that

are not letters are unaffected by this function Locale rules are applied if a locale

is provided


URLENCODE


Encodes text and merge field values for use in URLs by replacing characters that

are illegal in URLs such as blank spaces with the code that represent those characters as defined in RFC Uniform Resource Identifier URI Generic Syntax For example blank spaces are replaced with and exclamation points are replaced with


VALUE

Converts a text string to a number


PARENTGROUPVAL 

This function returns the value of a specified parent grouping A parent grouping is any level above the one containing the formula You can use this function only in custom summary formulas and at grouping levels for reports .


PREVGROUPVAL

This function returns the value of a specified previous grouping A previous grouping is one that comes before the current grouping in the report Choose the grouping level and increment The increment is the number of columns or rows before the current summary The default is the maximum is You can use this function only in custom summary formulas and at grouping levels for reports but not at summary levels


CURRENCYRATE

Returns the conversion rate to the corporate currency for the given currency ISO code If the currency is invalid returns


GETRECORDIDS

Returns an array of strings in the form of record IDs for the selected records in a

list such as a list view or related list


IMAGEPROXYURL

Securely retrieves external images and prevents unauthorized requests for user

credentials


INCLUDE

Returns content from an scontrol snippet Use this function to reuse common

code in many scontrols


ISCHANGED

Compares the value of a field to the previous value and returns TRUE if the values are different If the values are the same this function returns FALSE


JUNCTIONIDLIST

Returns a JunctionIDList based on the provided IDs


LINKTO

Returns a relative URL in the form of a link href and anchor tags for a custom scontrol or Salesforce page


REGEX

Compares a text field to a regular expression and returns TRUE if there is a match Otherwise it returns FALSE A regular expression is a string used to describe a format of a string according to certain syntax rules


REQUIRESCRIPT

Returns a script tag with source for a URL you specify Use this function when referencing the Lightning Platform AJAX Toolkit or other JavaScript toolkits


URLFOR

Returns a relative URL for an action scontrol Visualforce page or a file in a static resource archive in a Visualforce page


VLOOKUP

Returns a value by looking up a related value on a custom object similar to the VLOOKUP Excel function


Wednesday, January 6, 2021

Remove hyphen automatically from Opportunity name on Lead conversion

Hi Trailblazers


I had a client who was not happy with the hyphen (-) which Salesforce automatically appends to an opportunity during lead conversion.

Something small but it could prove to be useful on your many trails.

Follow the steps to remove the hyphen (-) automatically from the Opportunities Name upon Lead conversion.


Example: LEAD NAME (THE COMPANY INC) CONVERTED TO OPPORTUNITY (THE COMPANY INC- )

This is standard Salesforce functionality. By default, Salesforce allows Users to add the name which starts with Account Name -. So they can edit that name and use some other name. Generally, people use Account Name-Opportunity Name.


This can be accomplished by using a workflow rule, with field updates based on a formula that checks for hyphen:

 

Create a workflow rule to remove hyphens from the Opportunity Name when an Opportunity is created:

 

  1. Classic: Go to Setup | Workflow Rules | Click New Rule or  Lightning Experience: Gear Icon | Search for Workflow Rules | Click New Rule
  2. Select the Object as Opportunity
  3. Enter Rule Name
  4. Choose to evaluate the rule when a record is: created
  5. Then select the Rule Criteria as: formula evaluates to true

Use Rule: 

IF 

CONTAINS(Name,'-'),true,false 

 

  1. Click Save and Next
  2. Add Workflow Action to update New Field
  3. On the Field Update Edit page, enter a Name for the field update, and select Opportunity Name as the Field to Update.
  4. Specify New Field Value as below: 

SUBSTITUTE( Name , '-', '') 

 

  1. Activate the workflow rule. 

May the Force be with you!


Tuesday, October 20, 2020

Clearing Salesforce Logs Manually - UI Delete not working

Sometimes clearing the logs via the UI does not always work...but what to do now?


 Here are some steps to solve your problem:

  • Open your Developer Console
  • Select query editor

  • Enter the following query 
    • select id from Apexlog 
  • This will display all the logs by id


  • Highlight (select) all the lines you wish to delete (Shift + down arrow)
  • Then select Delete Row


This will start deleting your logs per id.

Happy Trails!




Tuesday, April 28, 2020

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

If Nginx wont start and is pushing back the following error:
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
Then it means nginx or some other process is already using port 80.
You can kill it using:
sudo fuser -k 80/tcp
And then try restarting nginx again:
service nginx start 
 sudo /opt/bitnami/ctlscript.sh start

Thursday, February 20, 2020

Code Coverage

Hey TrailBlazers!


One interesting area within any Salesforce org is code coverage.Inhereting an environment with low code coverage is never easy.

So the official statement : 

Code coverage indicates how many executable lines of code in your classes and triggers have been exercised by test methods. ... To deploy Apex or package it for the Salesforce AppExchange, unit tests must cover at least 75% of your Apex code, and those tests must pass.

...but how do you identify the root causes for your low coverage?



Select the Gear Icon >>Select Developer console




Once your developer console is open >>Select Query Editor >>




Paste the query below in the query editor  :

SELECT ApexClassorTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY NumLinesUncovered DESC LIMIT 10

Please ensure that you tick "Use Tooling API" and the execute:




This will give you a list of the top 10 classes lowering your code coverage.


Once identified its time to create the test classes.

Happy Trails!






Thursday, January 23, 2020

This organization isn't authorized to upload change sets to other organizations. For authorization, contact the deployment connections administrators on the organizations where you want to upload changes.


Soooo..... I refreshed my sandbox environment to create a partial copy of production.

Added my new components and merrily attempted to deploy them to production.

All of a sudden I was posed with :

This organization isn't authorized to upload change sets to other organizations. For authorization, contact the deployment connections administrators on the organizations where you want to upload changes.

There is a simple fix for this.


  • Logon to your production environment
  • Launch Set Up
  • Enter Deployment in the quick find box.

  • Select Edit next to the environment (e.g. Sandbox) where you received the error
  • Now tick the box that allows connections

  • Once done with ticking the radio button, hit save.
You should now be able to go back to your Sandbox and deploy.

Happy Trails
Jerome Slinger






Tuesday, December 17, 2019

Salesforce - Find the list of required fields for any Object


Sometimes we find ourselves in a situation where we need to identify all the required fields for an object.

This is useful  for feedback to business or when preparing for a migration.

Yes, I know we could have gone the route of using the developer console, Apex code and so much more but for this solution we are going with simplicity :-)



  1. Select your avatar/profile
  2. Then Select Switch to Salesforce Classic (Under Options)
  3. Navigate to Setup
  4. Look for Field Accessibility under Security Controls
  5. Pick an Object > View by Profile > Pick a Profile
  6. Required Fields display in Red




May the force be with you and happy trails.

Jerome Slinger


Monday, December 2, 2019

Salesforce Lightning - Using the "lightning:fileUpload"

Sometimes we find ourselves in a situation where the standard file upload process just doesn't meet the required grade.

This is when we have to dust off the old developer console and write some code :-)

Step 1: Login to your Salesforce and open developer console (I always recommend your Sandbox first). 

tep 2: Navigate to File | New | Apex Class and Create an Apex controller called UploadManager. Replace following code in apex controller.  

UploadManager.apxc


 public class UploadManager{
    
@AuraEnabled  
   public static List getFiles(string recordId){  
     List DocumentList = new List();  
     Set documentIds = new Set();  //store file ids
     List cdl=[select id,LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId=:recordId];  
     for(ContentDocumentLink cdLink:cdl){  
       documentIds.add(cdLink.ContentDocumentId);  // Document ids
     }      
     DocumentList = [select Id,Title,FileType,ContentSize,Description from ContentDocument where id IN: documentIds];  
     return DocumentList;  
   }  
   @AuraEnabled  
   public static List UpdateFiles(string documentId,string title,string recordId){  
     system.debug('title: ' +title);  
     ContentDocument cd = [select id,title from ContentDocument where Id=:documentId]; // Getting files from Parent record 
     cd.Title = title;  // Changing file Title with user entered title
     try{  
       update cd;  // Update ContentDocument (File)
     }  
     catch(DMLException e){  
       system.debug('Exception has occurred! ' +e.getMessage());  
     }  
      List DocumentList = new List();  
     Set documentIds = new Set();  
     List cdl=[select id,LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId=:recordId];  
     for(ContentDocumentLink cdLink:cdl){  
       documentIds.add(cdLink.ContentDocumentId);  
     }      
     DocumentList = [select Id,Title,FileType,ContentSize,Description from ContentDocument where id IN: documentIds];  
     return DocumentList;  // Return list of files on parent record
   }  
 }  
Step 3: Navigate to File | New | Lightning Component and create a Lightning Component called FileUpload. Replace the following markup in the Lightning Component.

LightningFileUpload.cmp





LightningFileUploadController.js
({  
   doInit:function(component,event,helper){  
     var action = component.get("c.getFiles");  
     action.setParams({  
       "recordId":component.get("v.recordId")  
     });      
     action.setCallback(this,function(response){  
       var state = response.getState();  
       if(state=='SUCCESS'){  
         var result = response.getReturnValue();  
         console.log('result: ' +result);  
         component.set("v.files",result);  
       }  
     });  
     $A.enqueueAction(action);  
   } ,  
   //Open File onclick event  
   OpenFile :function(component,event,helper){  
     var rec_id = event.currentTarget.id;  
     $A.get('e.lightning:openFiles').fire({ //Lightning Openfiles event  
       recordIds: [rec_id] //file id  
     });  
   },  
   UploadFinished : function(component, event, helper) {  
     var uploadedFiles = event.getParam("files");  
     var documentId = uploadedFiles[0].documentId;  
     var fileName = uploadedFiles[0].name;  
     helper.UpdateDocument(component,event,documentId);  
     var toastEvent = $A.get("e.force:showToast");  
     toastEvent.setParams({  
       "title": "Success!",  
       "message": "File "+fileName+" Uploaded successfully."  
     });  
     toastEvent.fire();  
     /* Open File after upload  
     $A.get('e.lightning:openFiles').fire({  
       recordIds: [documentId]  
     });*/  
   },  
 })  

LightningFileUploadHelper.js
({  
       UpdateDocument : function(component,event,Id) {  
     var action = component.get("c.UpdateFiles");  
     var fName = component.find("fileName").get("v.value");  
     //alert('File Name'+fName);  
     action.setParams({"documentId":Id,  
              "title": fName,  
              "recordId": component.get("v.recordId")  
              });  
     action.setCallback(this,function(response){  
       var state = response.getState();  
       if(state=='SUCCESS'){  
         var result = response.getReturnValue();  
         console.log('Result Returned: ' +result);  
         component.find("fileName").set("v.value", " ");  
         component.set("v.files",result);  
       }  
     });  
     $A.enqueueAction(action);  
   },  
 })  


Step 4: To Create a quick action Navigate to Setup | Object Manager | Account |Buttons, Links and Actions | New Action. Fill all required fields and hit the Save button.


Create an Action

Step 5: To add quick action in account page layout Navigate to Setup | Object Manager | Account | Page Layouts. Edit Account Layout and move to Mobile & Lightning Actions.



Step 6: Drag File Upload quick action in  Salesforce Mobile & Lightning Experience Actions section and save the Account page layout.



Step 7: Open an account record and click on the File upload quick action button.



Output:






And just like that you are all done :-)

Happy Trails!

Generate reports from Opportunities using a Visualforce Page in Salesforce

  Step 1: Create a Visualforce Page Go to the Setup menu in Salesforce. Search for "Visualforce Pages" in the Quick Find box and c...