Public/Invoke-SfObjectUpdate.ps1
<# .SYNOPSIS Updates a Salesforce object .DESCRIPTION Updates a Salesforce object .INPUTS A PSCustomObject that has the fields to update. .OUTPUTS None .PARAMETER Object A PSCustomObject that has the fields to update. .EXAMPLE PS> $du = @{ attributes = @{ url = "/services/data/v48.0/sobjects/phecc__Device__c/a0N3t000008XXe5EAG" } phecc__Replace_Request_Date__c = "2020-10-12" } PS> Invoke-SfObjectUpdate $du .LINK https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_update_fields.htm?search_text=Patch Set-Config .NOTES Assumes config is initialized for org access. #> function Invoke-SfObjectUpdate { [CmdletBinding()] [OutputType([PSCustomObject])] param( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [PSCustomObject] $Object ) 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)" # e.g. /services/data/v48.0/sobjects/phecc__Device__c/a0N3t000008XXe4EAG $Type = ($Object.attributes.url -split "/")[5] $Id = ($Object.attributes.url -split "/")[6] $Object = $Object | Select-Object -Property * -ExcludeProperty attributes $Body = $Object | ConvertTo-Json -Depth 100 Invoke-SfApi "/sobjects/$($Type)/$($Id)" -Method Patch -Body $Body } } |