.ultrageek. Computers, Music, and Thoughts

4Oct/190

Silly Dev Trick: Running Lead Assignment Rules on New Leads

Another posting that resulted from a lot of great examples on the web but none that were actually bulked and tested.

So the business case is "Run the default lead assignment rules when leads are created". Seems easy but when you look at the documentation, forums, and blog postings it is all none bulked examples with all kinds of answers for how to bulk. The issue I kept hitting was this error:

"DML statement cannot operate on Trigger.new or Trigger.old"

Wait what? Works fine if you just update the record but if you added it to a list blamo. Someone mentioned future class as an option but that involves all kinds of overhead for catching when the queue is full and managing that. So noodling the error message I decided to give a "what if sObject?" and that works like a charm. Calling the class on After Insert.

Below is an example class that is tested and works. Created a checkbox to manage resubmissions/looping but other than that it's pretty straight forward:

18Sep/190

Silly Dev Trick: Converting Ids from 15 to 18 Automagically in Apex

Anyone that has dealt with Opportunity Line Items knows that you cannot create a lookup to that record on another. So the next best thing is to put a text field and store the Id. Apex stores Ids in their 18 length form but in the UI it shows it to you as 15 digits. Since it is not uncommon for folks to update data manually I needed a quick way to 'fix' Ids from 15 to 18 in apex like CASESAFEID. Workflow would have worked...but let's pretend it didn't heh.

Here's a quick trick to convert those 15 digit text ids back to 18:

string idStr = '001E000000nwg7g';   // 15 character id
id idval = idStr;                   // assign to ID variable
idStr = idval;                      // back to string to prove the point
system.debug('18 char: ' + idStr);  // note that you could just append idval instead
                                    // of converting to string first

Got this trick from this awesome Stackexchange post: https://salesforce.stackexchange.com/questions/25575/casesafeid-apex-equivalent

As usual this was a little harder to find than it should have been.

16Sep/190

Apex sObject Examples

sObjects are great for dynamic apex where you need to re-use code across objects and/or need to dynamically set data. I've had several projects where the same logic is used across many objects such as date, territory, and ownership. Recently had a use case where I used sObjects and a custom setting with a list of fields between two objects to dynamically load the fields and keep data synchronized. Going to clean up that example and posted it later but below is a cheat sheet I finally pulled together of common programming patterns and uses:

Tagged as: , No Comments
3Sep/190

Salesforce Quick Action: Setting the FROM Email Address using a formula

Business Case: Client has a lot of email-to-case addresses and wants their quick action 'From' to be preselected in order to cut down on clicks and ensure the email goes out from an address that is not the agent and that will be returned directly to Salesforce. Seems easy enough! When looking at the predefined field values for the email quick action it can get confusing as to which one to use and the correct formula to use so here's how I solved it:

if(ISPICKVAL(Case.Origin, "Product_Name_1 Email"),
"Product_Name_1.support@your_domain.com",
if(ISPICKVAL(Case.Origin, "Product_Name_2 Email"),
"Product_Name_2.support@your_domain.com",
NULL))

The trick was using the 'From' field AND NOT the 'From Name' or 'From Address' AND using only the email address and not the name or name + email address (believe me I tried both). It was looking at the html source code of the New Predefined Values page that clued me in. Predefined Field Values on picklists are just so awesome!

26Aug/190

Silly Admin Trick: Showing the User License in List Views and Reports

Todays silly admin trick which you can find in 2 seconds on google is how to get the license of the user in Salesforce to show up in a list view or in reports. Once you see the answer it is a no brainer but:

  1. Create Formula field -> Text
  2. Name it something like: License Type
  3. Copy/Paste: Profile.UserLicense.Name
  4. Viola!~

Makes total sense to dig in through the profile's related license to determine the users license but would be handy if this was a standard field in Salesforce.

23Jul/190

Silly Admin Trick: Disable Customer Portal Navigation Bar

In Salesforce Classic when you create your first community (Customer Portal) Salesforce puts a black navigation bar at the very top of the page that allows you to quickly toggle between the standard user interface and your customer portals. It...is annoying and for some reason since I rarely run in to this I forget how to disable it so once and for all:

Profile: Global Header -> Uncheck

Go in to User Management Settings and turn on Profile List Views if they're not already turned on and then create a list view with that attribute to mass turn off. I can see how this would be helpful for testing but for users it is pretty useless and confusing.

9Jul/190

Mass Edit Button for Lightning Related List

Inline editing is super easy in Salesforce Lightning but not from a related list on a record page. So this is a quick and easy way to without a controller create a VF page that can be used as a button to update a field selected records in a related list. Just flip the object name and fields and you are off to the races. And this example is straight off of the Salesforce site examples but I removed the extension class so that a test class is not necessary.

Mass-Updating Records with a Custom List Controller

StackExchange post: https://salesforce.stackexchange.com/questions/146973/run-a-mass-action-on-multiple-records-in-a-list-view

3Jul/190

Apex Class working with both Trigger and Batch

Sometimes there is a need for a class to execute based on a record value (checkbox) or as part of a scheduled batch job. Not a new concept but you will get this error: Static method cannot be referenced from a non static context

So a quick fix is to just create a non-static method that calls the static method...crazy that this works but it does.

Again - nothing magical or new here but in case google was not giving you the results here is one solution.

 

Tagged as: No Comments
18Jun/190

VS Code Quick Tip: Disable Quick fix available Lightbulb

July 2019 Update: They ended up fixing this...but boy was it annoying.

VS Code is great but after a recent update I started getting a lot of suggestions to created classes in triggers for classes that already exist. I'm sure it is a bug but it was a distraction so after more searching than necessary I found the secret sauce key word in settings to turn this off...at least for now.

How to disable the light bulb in Visual Studio Code

Basically:

  • Settings
  • Search for 'bulb'
  • Disable and restart VS Code

I only post this as for some reason searching on the keyword quick fix available did not provide the results I was looking for so maybe this will help out the next person...either that or I need sharpen those google skills.

29Jan/190

Silly Admin Trick: Enable Service Contracts

Should be straight forward...to enable Service Contracts you have to "Enable Entitlement Management"

...why is this so hard to google.