Skip to main content

Posts

Using the Force.com CLI and Powershell

There's not much information around for the Force.com CLI, so I'm keeping a list of things here for posterity...

Deleting: First, write the list of records to a file (you could just save to a variable but it can come in handy to keep a list of IDs when modifying records)

force query "SELECT Id FROM Object__c WHERE Field__c = 'Whatever'" | Out-File .\ids_to_delete.csv

If it's not a big list, just pipe that back into a CSV object and iterate over it, deleting each one with "force record delete"

Import-Csv .\ids_to_delete.csv | % { force record delete Object__c $_.Id }

It's not very fast, so if there's a lot of them you'll need to use the bulk API.  First remove the quotes from the CSV, no idea why, but "force bulk" hates them for some reason.  Then call it like this:

force bulk delete Object__c .\ids_to_delete.csv

If you just have a medium-sized list of IDs to delete and they're not in a CSV (e.g. copypasta from elsewhere), …
Recent posts

IIS HTTP Error 500.19, Error Code 0x8007000d

I probably come across this error at least once per year. Ran into it again today when setting up a website to host locally in IIS, on a computer I don't use much.

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:
Module   IIS Web Core
Notification   Unknown
Handler   Not yet determined
Error Code   0x8007000d

Config Source:
   -1:
    0:


Microsoft's documentation for that error code helpfully points out:

"This problem occurs because the ApplicationHost.config file or the Web.config file contains a malformed XML element."

Well that clears it up. Just remove the malformed XML element on line 0...

Except that the site runs just fine on other systems, and even in IIS Express on the same machine that's causing the error, so clearly there's no "malformed XML".  Anyway, it turns out that if your web.config has a section for something li…

Umbraco's TinyMCE error: "Cannot read property 'parentsRequired' of undefined"

If you find that the "Formats" list in an Umbraco RTE refuses to open, and the Javascript console contains this error:

"Cannot read property 'parentsRequired' of undefined"

Check the stylesheet that the RTE is using.  In my case, adding this style had triggered the issue:

/**umb_name:Small*/
small{}

Although there's nothing wrong with this style itself, the problem is in what TinyMCE considers to be "valid" HTML elements.  Why is "small" not valid?  No idea!  But you can fix this by opening /config/tinyMceConfig.cfg, finding the <validElements> section and appending this:
,small[class]
And that's it!  You can probably substitute "[class]" with other attributes if you need to, or even just [*].  I'm not really sure what all the implications of that are (let me know if you find out), so I just went with [class] like some of the other properties have.

Credit to Eric Schrepel for helping me figure this one out at h…

Using Umbraco ModelsBuilder

Firstly, make sure the following properties are set in your solution's top-level web.config to enable the models builder:

<add key="Umbraco.ModelsBuilder.Enable" value="true"/>
<add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveAppData"/>

I like the "LiveAppData" mode, but you should experiment with the others from the list in the ModelsBuilder docs here.  Generate your model classes, and include them in the VS Solution.
Unless you're on a brand new project, any existing views will need to be modified.

Model class inheritance Change instances of
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
to
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.ModelName>

Property Access Change instances of @Umbraco.Field("propertyAlias") to @Model.PropertyAlias Note that the ModelsBuilder converts property aliases to PascalCase instead of camelCase
Rendering Grid HTML Change instances of
@CurrentPage.GetGrid…

Powershell as a Visual Studio External Tool

It's handy to be able to open Powershell at the current solution directory, e.g. for invoking scripts or git commands etc.
Click the Tools menu  -> External Tools -> Add
Title: Powershell, or whatever you want
Command: your PS directory, e.g C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -ExecutionPolicy RemoteSigned -NoExit -Command "Set-Location '$(SolutionDir)' | Clear-Host"
Initial directory: $(SolutionDir)

Useful Vim Stuff

Open explorer   :!start explorer /select,%:p
cc - change current line from indent (like _C)
:bro[wse] ol[dfiles]
'0 to '9 - open file from oldfiles with this number
^ - previously opened file

Useful Powershell stuff

ii = Invoke-Item - for files, opens them using windows default program
vim = Opens with vim (custom alias)
csi = C# interactive (custom alias)

Making a self-signed cert for local dev:
New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "Cert:\LocalMachine\My\" -FriendlyName "localhost"
(don't forget to install the cert into "Trusted root certificate authorities" via IE)