Skip to main content

Posts

.NET Framework DateTime format string for Salesforce dates

For future reference, the correct .NET Framework DateTime format string to use for a Salesforce Date/time is:
yyyy-MM-ddTHH:mm:ss.fffZ

Make sure it's in UTC! If the time represents the current moment, use DateTime.UtcNow

You might be tempted to use "O" (round-trip pattern) since it looks sort of similar, but don't.  It won't cause an error, but the time will be parsed incorrectly.
Recent posts

DIY Salesforce partial copy sandbox using SandboxBerry

Salesforce partial copy sandboxes are expensive, but it's possible to approximate one if you're willing to spend a little time moving the data around yourself with a fantastic little tool called SandboxBerry, which you can get from here. Big thanks to Ian Finch for all his work on it!

Below are the steps I had to go through to get all my data imported. Please let me know if you have any suggestions that could make this easier or more effective!

Make a new development sandbox and log into itDelete all outbound messages and workflows that relate to integrations with external systemsSave a copy of /ExampleInstructionFiles/ExampleInstructionFile.xml, henceforth called InstructionFile.xmlDecide which object types you want to migrate and add them as SbbObjects in InstructionFile.xmlDeactivate validation rules, mandatory fields and lookup filters for those objects (TODO: write a script to do this by exporting metadata, disabling them all programmatically, then re-importing the upda…

Useful Azure AD Powershell snippets

I've been doing a lot of Azure AD stuff lately, so here are some powershell snippets that have been coming in handy.

I always forget to Connect-AzureAD first, so don't do that

Get extension properties of a user (e.g. created date)
Get-AzureADUser -SearchString 'username or email addy' | select -ExpandProperty ExtensionProperty

Get guest users that are not members of a specified group
$allGuests = Get-AzureADUser -Filter "usertype eq 'guest'" -All $true
$groupMembers = Get-AzureADGroup -SearchString 'group-name' | Get-AzureADGroupMember -All $true
$allGuests | where {$groupMembers -notcontains $_ }

Get details and creators of all Salesforce reports that reference a specified field

If you're ever modifying a Salesforce field and you want to contact everyone who has created reports using the field, here's how you do that using Powershell and the Force.com CLI (which you can also install via chocolatey):

set-location C:\wherever
force export
$reportFiles = get-childitem -Path .\src\reports\ -Recurse | sls "field_to_search_for"

# I've included some extra fields here, they might come in useful
$reportData = force query --format=json "select id, createdby.name, createdby.email, developername, name, foldername, isdeleted, lastrundate, lastvieweddate from report" | convertfrom-json
$matchingReports = $reportData | where { $reportFiles.Filename -eq $_.DeveloperName + ".report" }

$matchingReports | % { $_.createdby.name + ' created report "' + $_.name +'"' }
# send an email to these folks: $matchingReports.Createdby.email | select -Unique

Salesforce bulk data load job fails with message "InvalidBatch : Field name not found : Id"

After creating a bulk / batch job, I'll sometimes see that it failed before even starting (failed batches:1, but with 0 records failed), with the following error:

InvalidBatch : Field name not found : Id

Annoyingly, this is caused by the inability of the Salesforce bulk import process to handle anything but ASCII.  Try saving your CSV again, making sure it's in ASCII (called "CSV (Comma delimited)" in Excel) and not using UTF-8 or some other encoding.  No idea how you're supposed to insert that new contact named José, though...

Testing Sendgrid SMTP without sending emails using sandbox mode

Here's how to test out a Sendgrid integration using SMTP without actually sending emails.  Obviously make sure you have Sendgrid SMTP set up in your config first, and then just add the X-SMTPAPI header (docs link) with some JSON like the below.


MailMessage msg = new MailMessage(); var json = @"{ ""mail_settings"": { ""sandbox_mode"": { ""enable"": true } } }"; msg.Headers.Add("X-SMTPAPI", json); // all the usual email stuff SmtpClient smtpclient = new SmtpClient(); smtpclient.Send(msg);

Chrome forcing all localhost queries to https, breaking various CLIs

I use the Azure CLI and the Force.com CLI pretty regularly, and both of them make use of a little webserver running on localhost, presumably to catch the auth tokens once the SSO process redirects back. I also like to use localhost as a new tab page, to better invoke Chrome's Vimium extension on all new tabs.  On several installs of several dev machines, http://localhost has been regularly redirected to https where it shouldn't be, causing breakage of all the CLIs, since they're not providing TLS certs, and my new tab page as I haven't got a TLS binding set up for the IIS default website.

Today I finally figured out the fix for it, it's explained here, basically Chrome is forcing connections over to TLS due to a HSTS header that it's picked up for localhost.  Deleting the security policy for the localhost domain immediately resolved all the problems I was having!  You can get to the HSTS security policies configuration at chrome://net-internals/#hsts