Did a proof-of-concept for an Azure Function in node.js that uses Redis Cache for session storage as the function runtime is 100% managed and using memory store doesn’t make sense. Once I had this I wanted to play with the local development support but that didn’t work as I was using node.js v. 13 and the Azure tooling only works an LTS version of node.js (meaning 12.x at the time of this writing). To fix I had to uninstall my current version of node.js and switch to v. 12.x as follows (I’m using Homebrew to manage dependencies):
brew uninstall node
brew install node@12
Then I had to update my PATH as the node binary is not in /usr/local/bin anymore but rather in /usr/local/opt/node@12/bin. Once that was done the Azure tooling for local application development worked like a charm.
The proof-of-concept is at https://github.com/lekkimworld/poc-azure-functions-with-session.
I’m using homebrew to manage many of the addons I use on my Mac. I had openjdk 12.0 installed previously but needed OpenJDK 1.8 to run Mulesoft AnyPoint Studio 7.4. Making that work I had to install OpenJDK 1.8 from adoptopenjdk (https://adoptopenjdk.net/) using homebrew and then tweak the ini-file controlling the AnyPoint Studio which is Eclipse based.
I started by downloading and installing Mulesoft AnyPoint Studio from Mulesoft. Then I installed openjdk 1.8 using homebrew.
brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8
OpenJDK 1.8 was installed to /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk and the Java Runtime Environment could be found in /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre. Making sure it works is always a good idea.
Now edit the AnypointStudio.ini for and specify the Java Runtime to use using the -vm switch (in bold).
For a demo I needed to make calls to the Petstore API using a Swagger / OpenAPI definition from Apex. Unfortunately the Apex support that External Services in Salesforce provides is only callable from Flows so I needed another approach. Using openapi-generator and installing via Homebrew it went relatively smoothly anyway.
It’s always nice to stand on the shoulder of giants so the examples provided by Rene Winkelmeyer (Connecting to Swagger-backed APIs with Clicks or Code ) came in handy. Unfortunately didn’t work as the prefix for the generated classes was different plus the petId was was 1 and not 100. Anyway again easy to fix.
Below are my steps to get working using Homebrew and Salesforce DX.
$ brew install openapi-generator
$ openapi-generator generate \
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
-g apex \
$ cd /tmp/petstore_swagger
$ sfdx force:org:create \
-v my_devhub \
-f config/project-scratch-def.json -a petstore_swagger
$ sfdx force:source:push -u petstore_swagger
$ sfdx force:apex:execute -u petstore_swagger
>> Start typing Apex code. Press the Enter key after each line,
>> then press CTRL+D when finished.
OASClient client = new OASClient();
OASPetApi api = new OASPetApi(client);
Map<String,Object> params = new Map<String, Object>();
Long petId = Long.valueOf('1');
OASPet pet = api.getPetById(params);