Public/Invoke-SfCreateObject.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<# .SYNOPSIS Creates a Salesforce object .DESCRIPTION Creates a Salesforce object .INPUTS A PSCustomObject that can be converted to JSON in the format of the Salesforce object .OUTPUTS Returns as PSCustomObject with the following members: id - Salesforce Object Id success - a boolean indicating success or failure errors - any errors .PARAMETER Object A PSCustomObject that can be converted to JSON in the format of the Salesforce object .PARAMETER Name The name of the Salesforce object .EXAMPLE PS> Invoke-SfCreateObject -Name Account -Object [PSCustomObject]@{ Name = 'Test Account' } .LINK Set-Config .NOTES Assumes config is initialized for org access. #> function Invoke-SfCreateObject { [CmdletBinding()] [OutputType([PSCustomObject])] param( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline)] [PSCustomObject] $Object, [Parameter(Mandatory = $true, Position = 1)] [String] $Name ) begin { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" } end { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } process { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" Invoke-SfApi "/sobjects/$($Name)/" -Method Post -Body ($object | ConvertTo-Json -Depth 100) } } |