– Accessing using Web Services and Scripting – Part 3

March 23, 2016


Powershell – – REST Example :


function Get-AuthorizationTokenWithUsernamePasswordFlow ` 
($client_id, $client_secret, $username, $password, $security_token)
    Add-Type -AssemblyName System.Web

    # $uri = "";
    $uri = "";
    $grant_type = "password";

    $username = [System.Web.HttpUtility]::UrlEncode($username)
    $password = [System.Web.HttpUtility]::UrlEncode($password)

    $requestBody = "";
    $requestBody += "grant_type=$grant_type";
    $requestBody += "&client_id=$client_id";
    $requestBody += "&client_secret=$client_secret";
    $requestBody += "&username=$username";
    $requestBody += "&password=$password$security_token";

    Write-Host "Uri:" $uri
    Write-Host "Body:" $requestBody

    Invoke-RestMethod -Method Post -Uri $uri -Body $requestBody

# usage create a ClientID and ClientSecret

# Obtaining a Token in an Autonomous Client (Username and Password Flow)

$Cred = Get-Credential -credential ""
$username = $Cred.UserName
$password = $Cred.GetNetworkCredential().Password $client_id = "YOUR CLIENT ID";
$client_secret = "YOUR CLIENT SECRET";
$security_token = "YOUR SECURITY TOKEN";

# Debug
 Get-AuthorizationTokenWithUsernamePasswordFlow ` 
 $client_id $client_secret $username $password $security_token

$Token = Get-AuthorizationTokenWithUsernamePasswordFlow ` 
$client_id $client_secret $username $password $security_token

$URI = $Token.instance_url+"/services/data/v20.0/"

$Response = Invoke-RestMethod -URI $URI -Method GET ` 
-Headers @{"Authorization" = "OAuth " + $Token.access_token};

Write-Host ""

# Response = availaible REST services


Write-Host ""

# Query Accounts Example 
Write-Host "Accounts :"

$StrQuery = "SELECT Name, Id from Account LIMIT 100"

$URI = $Token.instance_url+"/services/data/v20.0/query?q=" + $StrQuery

$Response = Invoke-RestMethod -URI $URI -Method GET ` 
-Headers @{"Authorization" = "OAuth " + $Token.access_token};

Write-Host ""
Write-Host " # of Records : "

Write-Host ""
Write-Host "Enum Account Name :"
$Response.records | % {$}

# Query Opporunities Example 
$StrQuery = "SELECT AccountId, OwnerId, Name, Description, ` 
StageName, Amount, Probability FROM Opportunity WHERE StageName <> `</pre>
<pre>'Closed Lost' ORDER BY StageName "

$URI = $Token.instance_url+"/services/data/v20.0/query?q=" + $StrQuery

$Response = Invoke-RestMethod -URI $URI -Method GET ` 
-Headers @{"Authorization" = "OAuth " + $Token.access_token};


Write-Host ""
Write-Host "Query Output :"

Foreach ($objItem in $Response.records) {

    "{0,-120} {1, 25} {2, 30}" -f `
   $, $objItem.StageName, $objItem.Amount

This script will return your Access Token, using this function



Next it will list the REST API’s you can use


Query Accounts Example :


Enjoy !

Smile – Accessing using Web Services and Scripting SOAP – Part 2

March 23, 2016


Powershell – – SOAP Example :


# WSDL is created from within SF.Com Application
$Path = Split-Path -Path $($global:MyInvocation.MyCommand.Path)
$Uri = $Path+"\Enterprise.wsdl" # You can also chose to create a Partner WSDL

$Cred = Get-Credential –credential “<a href="mailto:“;$SecToken">”

$User = $Cred.UserName
$Password = $Cred.GetNetworkCredential().Password 

# Proxy
$service = New-WebServiceProxy -Uri $Uri -Namespace sforce -UseDefaultCredential

# Login
$loginResult = $service.login($Cred.UserName, $Password+$SecToken)

# Debug info
# $loginResult

$service = New-Object sforce.SforceService
$service.Url = $loginResult.serverUrl
$service.SessionHeaderValue = New-Object sforce.SessionHeader
$service.SessionHeaderValue.sessionId = $loginResult.sessionId

# Listing SalesForce Objects
$accountObjects = $service.describeGlobal()

Write-Host "Enum SalesForce Objects"
Write-Host "-----------------------"

Foreach ($item in $accountObjects.sobjects)
    Write-host ($, $item.label)

Write-Host ""
Write-Host "Retrieving Object Meta Data"
Write-Host "---------------------------"

# Retrieving meta data about a specific object
$opportunityObject = $service.describeSObject("Opportunity")

foreach ($item in $opportunityObject.fields)
    Write-Host ($, $item.label, $item.type)

Write-Host ""
Write-Host "RelationshipNames"
Write-Host "-----------------"

foreach ($item in $opportunityObject.childRelationships)
  Write-Host ($item.relationshipName)

Write-Host ""
Write-Host "Querying Objects"
Write-Host "----------"

# $StrQuery = "SELECT Id, Name, StageName, Amount FROM Opportunity WHERE IsWon = True";

$StrQuery = "SELECT AccountId, OwnerId, Name, Description, StageName, `
Amount, Probability FROM Opportunity";
$queryResult = $service.query($StrQuery) 
foreach ($item in $queryResult.records)
   Write-Host ( $item.AccountId, $item.OwnerId, $item.Name, ´
   $item.Description, $item.StageName, $item.Amount, $item.Probability)

rv Password, SecToken 

This Script will list SalesForce Account Objects.


Retrieves meta data about a specific object.


Retrieves RelationshipNames.


Querying Objects


For more info on how to get started see here

To go further see here


Smile – Accessing using Web Services and Scripting – Part 1

March 23, 2016

Many of the modern Web platform offer Web Services API’s to access their data.

One of them is I choose this example because it has a huge global audience and a well documented Developer Guide.

Before starting your scripting exercise you need to plough through the extensive developer manuals. Which is the lease fun part. Therefore I summarized it all for you to give you all a head start. Winking smile has a number of Web Services Protocols as well as a number of authentication methods using the OAuth 2.0 protocol.

On top of that you can start developing in using APEX

What is APEX

Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the platform server in conjunction with calls to the​ API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.

1. Web Services Protocol

You can use the SOAP protocol or you can use the REST protocol, to access to the web services API.

Both have different ways of dealing with this in you programming / scripting environment.


The REST API is designed to be easily accessible from any programming language – once you understand the basic concepts of the API, you will be able to apply them to PHP, Ruby, .NET, or any other environment.


Use SOAP API to create, retrieve, update or delete records, such as accounts, leads, and custom objects. With more than 20 different calls, SOAP API also allows you to maintain passwords, perform searches, and much more. Use SOAP API in any language that supports Web services.

Choosing a WSDL

· Enterprise WSDL—This API is for most enterprise users who are developing client applications for their organization. The enterprise WSDL file is a strongly typed representation of your organization’s data.

Note the following when generating the enterprise WSDL:

· If new custom fields or objects are added to, renamed, or removed from your organization’s information, you need to regenerate the WSDL file in order to access them.

· The generated WSDL contains the objects and fields in your organization, including those available in the selected versions of each installed package. If a field or object is added in a later package version, you must generate the enterprise WSDL with that package version to work with the object or field in your API integration.

· Partner WSDL—This API is for Salesforce partners who are developing client applications for multiple organizations. As a loosely-typed representation of the Salesforce object model, the partner WSDL can be used to access data within any organization.

More API’s and which one to chose ?

2. Authtentication Protocol uses OAuth2.0 protocol for users to authorize applications, to access resources (via the REST and SOAP Web Service APIs).

More info :

The OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service.

More info on OAuth 2.0 authorization framework :

1. Obtaining an Access Token in a Web Application (Web Server Flow)

2. Obtaining an Access Token in a Browser or Native Application (User-Agent Flow)

3. Obtaining an Access Token using a JWT Bearer Token

4. Obtaining an Access Token using a SAML Bearer Assertion

5. Obtaining an Access Token using a Web SSO SAML Assertion

6. Obtaining a Token in an Autonomous Client (Username and Password Flow)

For our scripting purpose we are going to use the Autonomous Client method.

clip_image002 Configuration Settings

Before Starting you need to do some configurations in

1. User

On the user level you need to trigger a Security Token, that we will use in the client application



Generate your WSDL file ENTERPRISE or PARTNER



Create a new APP Config and setup the OAuth access parameters.

If you use a Client Application (no Web Interface) you don’t need to set the Callback URL.

Just fill in some dummy data.


Once you have configured the new APP, you can read out the CLIENT CONSUMER KEY and the CONSUMER SECRET

This you will need later on when configuring the Client Application Access.

4. Object Model

Next you need to get acquainted with the Object Model / Data Model in order to run the proper Queries definitions.


OK, so now you are ready to get started if you have made up your mind which of the options you want to chose.

Powershell Examples :

1. SOAP API : See here

2. REST API : See here

Out of experience the REST method is much faster.

More info here:

As you can notice is that you go a long way just using a Scripting environment.



Fiddler – How to capture non Web Browser traffic

March 21, 2016

I had a need to debug an external app using fiddler.

Seems to be a trivial exercise, but I could not see the captured traffic in fiddler ?

After Googling a bit, I could only find part of the solution.

Below is the full story.

Solution :

1. Proxy Settings : First of all you need to know that Fiddler acts as a proxy server on your machine when you start it.

The default address / port is

You can check the settings after starting Fiddler in you Browser settings.


So you need to set the proxy settings in your local application that you want to test.

2. Decrypt HTTPS settings

Make sure you have set to Decrypt HTTPS



This needs a extra extension to Fiddler (which is not installed by default)

3. Capture all Processes

After that you need to make sure that you tell Fiddler to capture all traffic for all Processes.


This last step I overlooked for a few hours before my eyes caught the option menu at the bottom.

Enjoy Winking smile

Windows – How to Debug NTFS Disk Corruption Event ID 55

March 16, 2016



Event ID 55 Analysis resulted in the following :

Hardware Diagnostics

No hardware issues reported ?



Running chkdsk did not report any errors ?


After analyzing the Eventlog I saw a pattern coming back.

The Event ID came back 3 times a day with approx. 8 hours in between :

5.45 AM /  13.45 PM  / 21.45 PM

This lead me to the fact that it had something to do with the VSS ?


Check for errors.


No Errors reported ?

So next I cleaned all the VSS copies and pushed the CREATE NOW button.


I saw again the NTFS events ID 55 ?

Next I checked the VSS Settings, to see the available capacity.



Check the available disk capacity and the size allocated for VSS.

=> C drive had 90 Gb available and the size allocated for VSS was 95 Gb ?

Once I changed the size below the available disk capacity and run the create Shadow Copy again.

No errors were reported in the event log

An Other issue can be that this related to a corrupt Shadow Copy

Use these steps to debug and fix

1. Open an elevated cmd prompt

2. Diskshadow> List Shadows All

3. Look out for the GUID of the shadow copy to be deleted  or if you are deleting all, just put “Delete Shadows ALL“.

Like this Delete shadows ID  {6c63605e-96aa-46ce-8d70-9f98b415208d}

4. Check again Diskshadow> List Shadows All

PS :

1. Using “Vssadmin delete shadows …” command does work for shadows or snapshots created by backup software.

These shadow copies may not show up or be visible using the GUI.

Check to ensure no backup is running (see this in the date stamp on the shadows)


An other option is just to run the chhkdsk /f command

2. Here is how to fix an Event 55 Error on \System Volume Information

Which fixed our issue …

Events appeared always at the same time every day …


after a CHECK disk event in verify mode (= Windows Backup)


Another fix that we had on a different server …

After a long struggle and debugging we found out that the error appeared always during a backup window.

So finally we found out that there was a conflict in the schedule that runs to create VSS snapshot, the same time the backup was running.


Once we rescheduled the VSS Snapshot on the C drive it error was gone Smile

On an other server we had disable the VSS on the C: drive completely to get rid of the error 55.

No use to have a VSS running on the C: drive anyhow ?

So it all depends on the situation and kind of backup software that is running on the machine.

More info here for potential reasons of Event ID 55

VSS driver Issue ?

Symantec Backup Exec Issue ?

Step by step guide to help ?

Bottom line is that 9 out of 10 these errors are related to Backup and VSS snapshots. And not that much to real disk errors Smile

Enjoy !