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
15 changes: 15 additions & 0 deletions Test/public/getsfId.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function Test_sfIdFromUrl{

$urlList = @(
"https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB/view",
"https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB/",
"https://github.lightning.force.com/lightning/r/Account/0010V00002Q8r78QAB",
"https://github.my.salesforce.com/0010V00002Q8r78QAB"
)

$urlList | ForEach-Object {
$result = Get-SfIdFromUrl $_
Assert-AreEqual -Expected "0010V00002Q8r78QAB" -Presented $result.SfId
}

}
15 changes: 14 additions & 1 deletion Test/public/getsfopportunity.test.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function Test_GetSfOpportunity{

Reset-InvokeCommandMock
Expand Down Expand Up @@ -44,6 +43,20 @@ function Test_GetSfOpportunity_Live{
Assert-NotImplemented
}

function Test_GetSfOpportunity_Id{
Reset-InvokeCommandMock

# Mocks
Mock_Database -ResetDatabase
Mock_Config
Mock_SfDataQuery_Opportunity_0065c00001SFRbYAAX

# Act with out cache
$result = Get-SfOpportunity -Id 0065c00001SFRbYAAX

# Assert
Assert-AreEqual -Expected "0065c00001SFRbYAAX" -Presented $result.Id
}

function Mock_SfDataQuery_Opportunity_0065c00001SFRbYAAX{
[CmdletBinding()]
Expand Down
17 changes: 17 additions & 0 deletions Test/public/getstaccount.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ function Test_GetSfAccount{
Assert-AreEqual -Expected "0010V00002KIWkaQAH" -Presented $result.Id
}

function Test_GetSfAccount_Id{
Reset-InvokeCommandMock

# Mocks
Mock_Database -ResetDatabase
Mock_Config
Mock_SfDataQuery_Account_0010V00002KIWkaQAH

# Act with out cache
$result = Get-SfAccount -Id 0010V00002KIWkaQAH

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

}

function Test_GetSfAccount_Transformations{
Reset-InvokeCommandMock

Expand Down
6 changes: 3 additions & 3 deletions docs/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

## Sample commands

### Get-SfAccount
### Get-SfUser

```powershell
Get-SfAccount https://github.lightning.force.com/lightning/r/Account/0013o00002ZKSfaAAH/view
```
Get-SfUser 0055c000009T2o8AAC
```
22 changes: 22 additions & 0 deletions public/getsfId.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# PowerShell module to get the ID from a Service Fabric URL
# Allow to integrate with ProjectHelper returning SfId

function Get-SfIdFromUrl{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-SfIdFromUrl' does not have a help comment. Note

The cmdlet 'Get-SfIdFromUrl' does not have a help comment.
[CmdletBinding()]
param(
[Parameter(Mandatory,ValueFromPipeline, Position=0)]
[string]$SfUrl
)

process{

# Extract Id from URL
$Id = Get-SfObjectIdFromUrl -SfUrl $SfUrl

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$ret = @{
SfId = $Id
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
return $ret

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-SfIdFromUrl' returns an object of type 'System.Collections.Hashtable' but this type is not declared in the OutputType attribute. Note

The cmdlet 'Get-SfIdFromUrl' returns an object of type 'System.Collections.Hashtable' but this type is not declared in the OutputType attribute.
}
} Export-ModuleMember -Function Get-SfIdFromUrl
36 changes: 27 additions & 9 deletions public/getsfaccount.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<#
.SYNOPSIS
Retrieves Salesforce Account data based on the specified Salesforce URL.
Expand All @@ -9,6 +8,16 @@
.PARAMETER SfUrl
The Salesforce URL of the Account object to query.

.PARAMETER AdditionalAttributes
Additional attributes to retrieve from the Salesforce Account object. This parameter accepts a comma-separated string of attribute names.
If not specified, the function retrieves a default set of attributes.

.PARAMETER Force
A switch parameter that forces the function to retrieve the data even if it is already cached.

.PARAMETER Id
The Salesforce ID of the Account object to query. If specified, the function will use this ID instead of extracting it from the URL.

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

Expand All @@ -19,24 +28,33 @@

This example retrieves the specified attributes for the Salesforce Account object with the ID extracted from the provided URL.

.EXAMPLE
PS> Get-SfAccount -Id 0013o00002OHreEAAT

This example retrieves the specified attributes for the Salesforce Account object with the specified ID.

.NOTES
The function uses the `Get-SfDataQuery` function to perform the query and the `Get-OwnerNameFromHtml` function to clean up the `Account_Owner__c` field.

#>
function Get-SfAccount{
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)][string]$SfUrl,
[Parameter(Position=0)][string]$SfUrl,
[string]$AdditionalAttributes,
[switch]$Force
[switch]$Force,
[Parameter()][string]$Id
)

# Extract Id from URL
$Id = Get-SfObjectIdFromUrl -SfUrl $SfUrl
$type = Get-SfObjectTypeFromUrl -SfUrl $SfUrl

if ($type -ne "Account") {
throw "Invalid Salesforce Object URL $SfUrl"
if ([string]::IsNullOrWhiteSpace($Id)){

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Extract Id from URL
$Id = Get-SfObjectIdFromUrl -SfUrl $SfUrl
$type = Get-SfObjectTypeFromUrl -SfUrl $SfUrl

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
if ($type -ne "Account") {
throw "Invalid Salesforce Object URL $SfUrl"
}
}

$attributes = @(
Expand Down
21 changes: 11 additions & 10 deletions public/getsfopportunity.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


<#
.SYNOPSIS
Retrieves Salesforce Opportunity data based on the specified Salesforce URL.
Expand Down Expand Up @@ -31,17 +29,20 @@
function Get-SfOpportunity{
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)][string]$SfUrl,
[Parameter(Position=0)][string]$SfUrl,
[string]$AdditionalAttributes,
[switch]$Force
[switch]$Force,
[Parameter()][string]$Id
)

# Extract Id from URL
$Id = Get-SfObjectIdFromUrl -SfUrl $SfUrl
$type = Get-SfObjectTypeFromUrl -SfUrl $SfUrl

if ($type -ne "Opportunity") {
throw "Invalid Salesforce Object URL $SfUrl"
if ([string]::IsNullOrWhiteSpace($Id)){
# Extract Id from URL
$Id = Get-SfObjectIdFromUrl -SfUrl $SfUrl
$type = Get-SfObjectTypeFromUrl -SfUrl $SfUrl

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
if ($type -ne "Opportunity") {
throw "Invalid Salesforce Object URL $SfUrl"
}
}

$attributes = @(
Expand Down
Loading