Friday, September 6, 2019

Microsoft.Build.Utilites 2.0.0 was not able to reference the assembly Telerik.Sitefinity.OpenAccess

When running an older version of Sitefinity under Windows 10, the Telerik enhancer.exe requires the .NET Framework 3.5 to be installed.  By default Windows 10 does not come with the .NET Framework 3.5 so you will need to install it.  Windows 10 comes with the .NET Framework 4.6 installed by default.

Here is the error for future reference:
Microsoft.Build.Utilites 2.0.0 was not able to reference the assembly Telerik.Sitefinity.OpenAccess in \packages\Telerik.DataAccess.Fluent.2015.3.926.1\tools\enhancer\enhancer.exe

Friday, August 16, 2019

Deleting Logs in Salesforce

Sometimes Salesforce logs are clog up the environment and you need to delete them. 

Logs are found in two different places in Salesforce.

Deleting Apex Logs

If you receive this message, this is an indicator that you need to delete your Apex Logs

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 251 MB of the maximum 250 MB of debug logs. Before you can edit trace flags, delete some debug logs.

1.  Click the gear icon and choose developer console

2.  In the query editor tab enter the query and click Execute

SELECT Id, StartTime, LogUserId, LogLength, Location FROM ApexLog

3.  Select the rows to delete and click Delete Row

Remove from Debug Logs

1.  Click on Gear Icon and then Setup

2.  Search for Logs

3.  Delete all the Logs or Just for your user

Tuesday, July 2, 2019

Creating an IIS Redirect Rule from Subdomain to the Root Domain

IIS Rewrite Rules have a lot of inherent complexity.  They use regular expressions and are difficult to debug.  The server variables have little documentation provided by Microsoft.  Recently we had an ask from the business to redirect any requests for subdomains to the main domain.  While this is simple to understand it is difficult to write.

Before you create and debug a rewrite rule you need a couple things:
1.  Install IIS by going into Programs and Features then Windows Features
2.  Install the Web Platform Installer  This installs modules for IIS like NuGet installs packages for .NET
3.  Use the Web Platform Installer to install the Rewrite Module

Here is the end result:

Match URL
The thing that hung me up for most of the time was the match url.  This is not the full URL as you would expect but simply the page that was requested like default.aspx.  This is Mistake #1 from Lex Li:

Condition Order
In order to do back references to conditions (see the {C:2} and {C:3} variables) you have to put the negate false conditions first.  If you don't the back reference does not work.

HTTP_HOST Matching
If you do not put the regular expression carat ^ for start and the dollar $ sign for end, IIS will redirect until the URL is too long and it throws an error.

Putting It All Together
https://www. - We always want to redirect to secure www
{C:2} and {C:3} - This is a back reference to the last condition, the last set of parenthesis.
{R:1} - This is the requested page from the Match URL

Debugging the Redirect Rule

1.  Here is some excellent documentation how to create a simple test file to debug your rewrite rule:

2.  I used Expresso to debug the regular expression to match the subdomain.rootdomain.  You can also use IIS by double clicking on the Re-write module for the site.  

3.  What I found to be very useful was to change the redirect url to a query string to see what the variables were.  
<action type="Redirect" url="{C:2}-{R:1}" appendQueryString="false" />

Here is the reference documentation from Microsoft:

Friday, June 21, 2019

Resetting the Admin Password in Sitefinity

If you lost the admin password for a site you can reset the password for the admin user in the database.  This will set the password format to clear text with no salt for the encryption.

UPDATE sf_users
SET    passwd = 'password',
       salt = NULL,
       password_format = 0
WHERE  user_name = 'someadminuser' 

Tuesday, May 21, 2019

How to redirect from HTTP to HTTPS in a web.config in CrownPeak CMS

  if (context.PublishingPackage.PackageName.Contains("Live")
    <rule name="Redirect to https" stopProcessing="true">
      <match url="(.*)" />
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />

Monday, February 11, 2019

What happened to my Salesforce System.Debug statements?

On our project we have complex report generation which creates a debug log file at the 5MB limit when the Apex Debug Log Level is set to finest.  According to Salesforce:

“Each debug log must be 5 MB or smaller. Debug logs that are larger than 5 MB are reduced in size by removing older log lines, such as log lines for earlier System.debug statements. The log lines can be removed from any location, not just the start of the debug log.“

If you just want to see the debug statements, simply log at the error level and then set everything else to none.

    System.debug(LoggingLevel.ERROR, ‘some logging message’);

Debug Levels
  • Database : None
  • Workflow : None
  • Validation : None
  • Callouts : None
  • Apex Code : Error
  • Apex Profiling : None
  • Visualforce : None
  • System:  None
  • Wave: None
  • Nba: None

If you want to debug in Visual Studio at the Apex finest level, break your code up into small testable pieces so that you can pinpoint errors and the log files can be under the 5MB limit.  The Single Responsibility should be your best friend when working in Salesforce.

Augmenting Salesforce CLI Commands for VS Code

I have been working with the Salesforce Extension Pack for VS Code and I have been mostly pleased with the capabilities.  On my current project, I find myself constantly switching between orgs.  I was tired of typing in the command to list out the current org and the command to switch the current org.  
There is a great hotkey VS Code extension called terminal-command-keys that allows you to create a hotkey that executes a terminal command.  The Salesforce CLI with hotkeys; what could be better!
Here are the steps to use
  1. Install the VS Code extension terminal-command-keys
  2. Edit your keybindings.json by pressing Ctrl-Shift-P on the PC or Command-Shift-P on the Mac.  Edit the file on the right

Add a command to list all your orgs by pressing Ctrl-Shift-l
    "key" : "ctrl+shift+l",
    "command": "",
    "args" :
            "cmd": "sfdx force:org:list",
            "saveAllFiles": false

Add a command to upload the current file by pressing Ctrl-Shift-u
        "key": "ctrl+shift+u",
        "command": "",
        "args": {
            "cmd": "sfdx force:source:deploy --sourcepath  ${file} --loglevel fatal",
            "newTerminal": false,
            "saveAllFiles": true,
            "showTerminal": true

Add a command to switch to your development org.  In my case, the alias is BossSand. Replace with the alias for your org.
        "key" : "ctrl+shift+d",
        "command": "",
        "args" :
            "cmd": "sfdx force:config:set defaultusername=BossSand",
            "saveAllFiles": false

Add a command to switch to your test org.  In my case the alias is BossStage. Replace with the alias for your org.
        "key" : "ctrl+shift+v",
        "command": "",
        "args" :
            "cmd": "sfdx force:config:set defaultusername=BossStage",
            "saveAllFiles": false