SalesForce.com – Accessing using Web Services and Scripting SOAP – Part 2

 

Powershell – SalesForce.com – SOAP Example :

CLS

# 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:“Email.LastName@company.com&quot;$SecToken">Email.LastName@company.com”
$SecToken</a> = "YOUR SECURITY TOKEN HERE"

$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.name, $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.name, $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.

image

Retrieves meta data about a specific object.

image

Retrieves RelationshipNames.

image

Querying Objects

image

For more info on how to get started see here

To go further see here

Enjoy!

Smile

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: