Public/Get-SurveyDefinitions.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
59
60
61
62
63
<#
    .SYNOPSIS
    Query salesforce for all survey definitions

    .DESCRIPTION
    Queries for all the surveys, questions and answers

    .INPUTS
    None. You cannot pipe objects to Get-SurveyDefinitions.

    .OUTPUTS
    An PSCustomObject containing the following members:
        answers
        surveys
        questions

    The 'answers' key contains an array of PSCustomObject with the following members:
        Id
        phecc__Answer__c
        phecc__Survey_Question__c

    The 'surveys' key contains an array of PSCustomObject with the following members:
        Id
        Name

    The 'questions' key contains an array of PSCustomObject with the following members:
        Id
        phecc__Question__c
        phecc__Survey__c

    .EXAMPLE
    PS> $surveyDefs = Get-SurveyDefinitions

    .LINK
    Set-Config

    .NOTES
    Assumes config is initialized for org access.
#>

function Get-SurveyDefinitions {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param()

    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)"
        Write-Verbose "Reading Org Survey Metadata"
        @{
            surveys   = (invoke-sfquery "SELECT Id,Name FROM phecc__Survey__c WHERE IsDeleted = false AND phecc__Status__c = 'Published'")
            questions = (invoke-sfquery "SELECT Id,phecc__Question__c,phecc__Survey__c FROM phecc__Survey_Question__c")
            answers   = (invoke-sfquery "SELECT Id,phecc__Answer__c,phecc__Survey_Question__c FROM phecc__Survey_Answer__c")
        }
    }
}