Skip to main content

Posts

Azure AD error - 'IDX10311: RequireNonce is true but validationContext.Nonce is null'

I've experienced this one enough times now that I'd like to preserve the solution/s for future occurrences. The exact message is:
IDX10311: RequireNonce is 'true' (default) but validationContext.Nonce is null. A nonce cannot be validated. If you don't need to check the nonce, set OpenIdConnectProtocolValidator.RequireNonce to 'false'. An easy way to reproduce this one is to hit the "back" button after having signed in to an ASP.NET web app that auths with Azure AD using the OWIN library.

https://stackoverflow.com/questions/29502788/enabling-ssl-in-asp-net-mvc-5-app-results-in-openidconnectprotocolvalidator-issu
Recent posts

Export every field of every record of a bunch of Salesforce objects

I needed to get a backup of every record of a bunch of objects (for posterity) which were about to be deleted, I wanted to grab every field and do it in one line. I cheated a little, because I've defined some functions that just do some of the basic processing. I could put the whole function definitions on one line too, but that'd be a bit contrived ;) They're below for reference



('object_name_1__c','object_name_2__c') | foreach-object { $fields = (sffields $_) -join ',' $query = "select $fields from $_" sfquery $query | export-csv "$_.csv" -NoTypeInformation -Encoding ASCII } function SFFields { (force describe -n="$($args[0])" -t=sobject | ConvertFrom-Json).Fields | Sort-Object name | Select-Object -ExpandProperty name } function SFQuery { force query --format json $args[0] | ConvertFrom-Json }

Combine many CSVs into batches of a specified size with Powershell

$batchMaxSize = 9.5MB $allFiles = Get-ChildItem 'fileLocation\*.csv' $batchNumber = 0; $batchMagnitude = $allFiles.Count.ToString().Length # group the files together until there's none left while ($allFiles.Count -gt 0) { $batchNumber++; $batchSuffix = $batchNumber.ToString().PadLeft($batchMagnitude,"0"); $totalSize = 0; # add the file sizes together, keeping a running total until it exceeds the max $batchFiles = $allFiles | where {$totalSize += $_.Length; $totalSize -lt $batchMaxSize}; # combine the files in memory - don't need to deal with headers # this step could cause memory issues with extremely large files # but then you probably wouldn't be batching them ;) $comboFile = $batchFiles | Foreach-Object { Import-Csv -Path $_; } $comboFile | Export-Csv "batched\batch-$batchSuffix.csv" -Encoding ASCII -NoTypeInformation # removes the files we just batched together from the list of all…

Exporting from an SQL database (e.g. Dynamics) into Salesforce, without Excel

Whenever you paste content into it, Excel likes to be helpful and reformat it according to what it thinks you're doing (e.g. format dates, interpret formulae), but often with CSVs it gets this wrong and messes up your carefully-formatted raw data. This was getting pretty frustrating, so rather than figuring out workarounds for Excel's weirdness, here's how to cut out the middleman and get the output of an SQL query directly into Salesforce. Don't forget the max length variables of Invoke-SqlCmd!

# first, write your query and save in query.sql
Invoke-SqlCmd -ServerInstance serverName -Database dbName -InputFile 'query.sql' -MaxCharLength ([Int32]::MaxValue) | Export-Csv -Path 'outputFile.csv' -Encoding ascii -NoTypeInformation
force login
force bulk -c insert -o objectName outputFile.csv

# upsert version, won't work if you're including audit fields (CreatedDate etc)
force bulk -c upsert -o objectName -e External_ID__c outputFile.csv

Invoke-SqlCmd…

Count all Salesforce records of all object types owned by a specific user

It's not the fastest or most elegant script, but using the Force.com CLI it's pretty easy to get a count of objects (of all types) owned by a specific user. It assumes that the field to be checked is ownerid, though, so might not work if you have other fields. A slightly better way might be to check which objects have an ownerid field first.

$ErrorActionPreference = 'SilentlyContinue' $objects = force sobject list $ownerId = '00590000001Abcd' # obviously replace this foreach($object in $objects) { $resp = (force query --format json "select count(id) from $object where ownerid='$ownerId'" | convertfrom-json | select -ExpandProperty expr0) $count = 0 if([Int32]::TryParse($resp, [ref]$count) -and $count -gt 0) { "$object : $count" } }