Public/Invoke-SfCreateObject.ps1

<#
    .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)
    }
}