Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Test/public/getstaccount.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function Test_GetSfAccount{
$result = Get-SfAccount -SfUrl $url

# Assert with cache
Assert-AreEqual -Expected "Hashtable" -Presented $result.GetType().BaseType.Name
Assert-AreEqual -Expected $id -Presented $result.Id
$path = Get-Mock_DatabaseStore | Join-Path -ChildPath $filename
Assert-ItemExist -Path $path
Expand All @@ -31,6 +32,7 @@ function Test_GetSfAccount{
$result = Get-SfAccount -SfUrl $url

# Assert
Assert-AreEqual -Expected "Hashtable" -Presented $result.GetType().BaseType.Name
Assert-AreEqual -Expected "0010V00002KIWkaQAH" -Presented $result.Id
}

Expand Down
5 changes: 3 additions & 2 deletions public/getsfaccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function Get-SfAccount{
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)][string]$SfUrl,
[string]$AdditionalAttributes
[string]$AdditionalAttributes,
[switch]$Force
)

# Extract Id from URL
Expand Down Expand Up @@ -70,7 +71,7 @@ function Get-SfAccount{
}

# Get object
$ret = Get-SfDataQuery -Type Account -Id $Id -Attributes $attributes
$ret = Get-SfDataQuery -Type Account -Id $Id -Attributes $attributes -Force:$Force

# Transformations
$ret = $ret | Edit-AttributeValueFromHTML `
Expand Down
12 changes: 10 additions & 2 deletions public/getsfopportunity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ The `Get-SfOpportunity` function extracts the Salesforce Opportunity ID from the
.PARAMETER SfUrl
The Salesforce URL of the Opportunity object to query.

.PARAMETER AdditionalAttributes
Additional attributes to retrieve from the Opportunity object. This parameter accepts a comma-separated string of attribute names.

.PARAMETER Force
Forces the function to bypass any caching
when retrieving data. If this switch is set, the function will always query Salesforce for the latest data, regardless of any cached results.

.OUTPUTS
The function returns a PowerShell object representing the queried Salesforce Opportunity data. If the query is unsuccessful or the object is not found, the function returns `$null`.

Expand All @@ -25,7 +32,8 @@ function Get-SfOpportunity{
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)][string]$SfUrl,
[string]$AdditionalAttributes
[string]$AdditionalAttributes,
[switch]$Force
)

# Extract Id from URL
Expand Down Expand Up @@ -68,7 +76,7 @@ function Get-SfOpportunity{
}

# Get object
$ret = Get-SfDataQuery -Type opportunity -Id $Id -Attributes $attributes
$ret = Get-SfDataQuery -Type opportunity -Id $Id -Attributes $attributes -Force:$Force

# Transformations

Expand Down
15 changes: 13 additions & 2 deletions public/getsfuser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ This function retrieves user information using the `sf data query` command.
.PARAMETER Id
The Salesforce user ID.

.PARAMETER AdditionalAttributes
Additional attributes to retrieve from the User object. This parameter accepts a comma-separated string of attribute names.

.PARAMETER Force
Forces the function to bypass any caching
when retrieving data. If this switch is set, the function will always query Salesforce for the latest data, regardless of any cached results.

.OUTPUTS
The function returns a PowerShell object representing the queried Salesforce User data. If the query is unsuccessful or the object is not found, the function returns `$null`.

.EXAMPLE
Get-SfUser -Id "0050V000001Sv7XQAS"

Expand All @@ -21,7 +31,8 @@ function Get-SfUser{
param(
[Parameter(Mandatory,Position=0)]
[string]$Id,
[string]$AdditionalAttributes
[string]$AdditionalAttributes,
[switch]$Force
)

$attributes = @(
Expand All @@ -41,7 +52,7 @@ function Get-SfUser{
}

# Get object
$ret = Get-SfDataQuery -Type User -Id $Id -Attributes $attributes
$ret = Get-SfDataQuery -Type User -Id $Id -Attributes $attributes -Force:$Force

# remove attributes
# $ret.PsObject.Properties.Remove("attributes")
Expand Down
16 changes: 10 additions & 6 deletions public/sfDataQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ function Get-SfDataQuery{
param(
[Parameter(Mandatory)][ValidateSet("Account", "User", "Opportunity")][string]$Type,
[Parameter(Mandatory)][string]$Id,
[Parameter(Mandatory)][string[]]$Attributes
[Parameter(Mandatory)][string[]]$Attributes,
[switch]$Force
)

# Testcache first
$cacheKey = getcacheKey -Type $Type -Id $Id -Attributes $Attributes
if(Test-Database -Key $cacheKey){
return Get-Database -Key $cacheKey
# avoid cache if Force is set
if(-Not $Force){
# Testcache first
$cacheKey = getcacheKey -Type $Type -Id $Id -Attributes $Attributes
if(Test-Database -Key $cacheKey){
return Get-Database -Key $cacheKey
}
}

$params = @{
Expand All @@ -22,7 +26,7 @@ function Get-SfDataQuery{

$result = Invoke-MyCommand -Command "sfDataQuery" -Param $params

$obj = $result | ConvertFrom-Json -Depth 10
$obj = $result | ConvertFrom-Json -Depth 10 -asHashtable

if($obj.status -ne 0){
throw "Status $($obj.status)"
Expand Down
5 changes: 3 additions & 2 deletions public/transformations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function Edit-AttributeValueFromHTML{
}

# Add the new attribute
Add-Member -InputObject $ret -MemberType NoteProperty -Name $NewAttributeName -Value $value
$object.$NewAttributeName = $value

# Remove the original attribute if specified
if ($RemoveOriginalAttribute) {
$Object.PsObject.Properties.Remove($AttributeName)
$Object.Remove($AttributeName)
}

return $Object
Expand Down
Loading