Closed16

Salesforce GraphQL - Trial to get PicklistValue

ぺこぺこ

Create scratch org

sf org create scratch --edition developer --no-namespace --alias demo-userorg

Confirm created

sf org list
ぺこぺこ

Insert account record

  • New record
    • Name: Foo
    • Type: Customer - Direct

Via Web Page

Via Developer Console - Query Editor

SELECT Id, Name, Type FROM Account
ぺこぺこ

Describe field Type of Account

Via Object Manager

  • equal API参照名

Via REST API

curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer ${access_token}" "${instance_url}/services/data/v58.0/sobjects/Account/describe/"
  • label equal value in picklistValues
// omission

    {
      "aggregatable": true,
      "aiPredictionField": false,
      "autoNumber": false,
      "byteLength": 765,
      "calculated": false,
      "calculatedFormula": null,
      "cascadeDelete": false,
      "caseSensitive": false,
      "compoundFieldName": null,
      "controllerName": null,
      "createable": true,
      "custom": false,
      "defaultValue": null,
      "defaultValueFormula": null,
      "defaultedOnCreate": false,
      "dependentPicklist": false,
      "deprecatedAndHidden": false,
      "digits": 0,
      "displayLocationInDecimal": false,
      "encrypted": false,
      "externalId": false,
      "extraTypeInfo": null,
      "filterable": true,
      "filteredLookupInfo": null,
      "formulaTreatNullNumberAsZero": false,
      "groupable": true,
      "highScaleNumber": false,
      "htmlFormatted": false,
      "idLookup": false,
      "inlineHelpText": null,
      "label": "取引先 種別",
      "length": 255,
      "mask": null,
      "maskType": null,
      "name": "Type",
      "nameField": false,
      "namePointing": false,
      "nillable": true,
      "permissionable": true,
      "picklistValues": [
        {
          "active": true,
          "defaultValue": false,
          "label": "Prospect",
          "validFor": null,
          "value": "Prospect"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Customer - Direct",
          "validFor": null,
          "value": "Customer - Direct"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Customer - Channel",
          "validFor": null,
          "value": "Customer - Channel"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Channel Partner / Reseller",
          "validFor": null,
          "value": "Channel Partner / Reseller"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Installation Partner",
          "validFor": null,
          "value": "Installation Partner"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Technology Partner",
          "validFor": null,
          "value": "Technology Partner"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Other",
          "validFor": null,
          "value": "Other"
        }
      ],
      "polymorphicForeignKey": false,
      "precision": 0,
      "queryByDistance": false,
      "referenceTargetField": null,
      "referenceTo": [],
      "relationshipName": null,
      "relationshipOrder": null,
      "restrictedDelete": false,
      "restrictedPicklist": false,
      "scale": 0,
      "searchPrefilterable": false,
      "soapType": "xsd:string",
      "sortable": true,
      "type": "picklist",
      "unique": false,
      "updateable": true,
      "writeRequiresMasterRead": false
    },

// omission
ぺこぺこ

Get Accounts by GraphQL

GraphQL Request body

accounts_with_picklist.json
{
  "query": "query accounts {
    uiapi {
      query {
        Account {
          edges {
            node {
              Id
              Name { value }
              Type {
                value
                label
                displayValue
              }
            }
          }
        }
      }
    }
  }"
}

Request to GraphQL

curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${access_token}" "${instance_url}/services/data/v58.0/graphql" -d @accounts_with_picklist.json
response
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Id": "0011m00000lxQLAAA2",
                "Name": {
                  "value": "Foo"
                },
                "Type": {
                  "value": "Customer - Direct",
                  "label": "Customer - Direct",
                  "displayValue": "Customer - Direct"
                }
              }
            },
            {
              "node": {
                "Id": "0011m00000lzjq8AAA",
                "Name": {
                  "value": "Sample Account for Entitlements"
                },
                "Type": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                }
              }
            }
          ]
        }
      }
    }
  },
  "errors": []
}
ぺこぺこ

Add new Picklist field to Account

  • New field
    • Label: extra_type
    • Name: extra_type
    • Values:
      • Foo
      • Bar
      • Baz

Values after field created

ぺこぺこ

Edit field extra_type of current Account record

Via Web Page

Via Developer Console - Query Editor

SELECT Id, Name, Type, extra_type__c FROM Account

ぺこぺこ

Get Accounts by GraphQL (2) - after extra_type__c created

GraphQL Request body

accounts_with_picklist.json
{
  "query": "query accounts {
    uiapi {
      query {
        Account {
          edges {
            node {
              Id
              Name { value }
              Type {
                value
                label
                displayValue
              }
              extra_type__c {
                value
                label
                displayValue
              }
            }
          }
        }
      }
    }
  }"
}

Request to GraphQL

curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${access_token}" "${instance_url}/services/data/v58.0/graphql" -d @accounts_with_picklist.json
response
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Id": "0011m00000lxQLAAA2",
                "Name": {
                  "value": "Foo"
                },
                "Type": {
                  "value": "Customer - Direct",
                  "label": "Customer - Direct",
                  "displayValue": "Customer - Direct"
                },
                "extra_type__c": {
                  "value": "Foo",
                  "label": "Foo",
                  "displayValue": "Foo"
                }
              }
            },
            {
              "node": {
                "Id": "0011m00000lzjq8AAA",
                "Name": {
                  "value": "Sample Account for Entitlements"
                },
                "Type": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                },
                "extra_type__c": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                }
              }
            }
          ]
        }
      }
    }
  },
  "errors": []
}
ぺこぺこ

Edit field extra_type__c - label of values

Via Object Manager

  • not equal API参照名

Via REST API

  • label not equal value in picklistValues
// omission

    {
      "aggregatable": true,
      "aiPredictionField": false,
      "autoNumber": false,
      "byteLength": 765,
      "calculated": false,
      "calculatedFormula": null,
      "cascadeDelete": false,
      "caseSensitive": false,
      "compoundFieldName": null,
      "controllerName": null,
      "createable": true,
      "custom": true,
      "defaultValue": null,
      "defaultValueFormula": null,
      "defaultedOnCreate": false,
      "dependentPicklist": false,
      "deprecatedAndHidden": false,
      "digits": 0,
      "displayLocationInDecimal": false,
      "encrypted": false,
      "externalId": false,
      "extraTypeInfo": null,
      "filterable": true,
      "filteredLookupInfo": null,
      "formulaTreatNullNumberAsZero": false,
      "groupable": true,
      "highScaleNumber": false,
      "htmlFormatted": false,
      "idLookup": false,
      "inlineHelpText": null,
      "label": "extra_type",
      "length": 255,
      "mask": null,
      "maskType": null,
      "name": "extra_type__c",
      "nameField": false,
      "namePointing": false,
      "nillable": true,
      "permissionable": true,
      "picklistValues": [
        {
          "active": true,
          "defaultValue": false,
          "label": "Label - Foo",
          "validFor": null,
          "value": "Foo"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Label - Bar",
          "validFor": null,
          "value": "Bar"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Label - Baz",
          "validFor": null,
          "value": "Baz"
        }
      ],
      "polymorphicForeignKey": false,
      "precision": 0,
      "queryByDistance": false,
      "referenceTargetField": null,
      "referenceTo": [],
      "relationshipName": null,
      "relationshipOrder": null,
      "restrictedDelete": false,
      "restrictedPicklist": true,
      "scale": 0,
      "searchPrefilterable": false,
      "soapType": "xsd:string",
      "sortable": true,
      "type": "picklist",
      "unique": false,
      "updateable": true,
      "writeRequiresMasterRead": false
    }

// omission
ぺこぺこ

View Account records after edit field extra_type__c label of values

  • In Web Page, Label change.
  • extra_type__c value of record does not change.

Via Web Page

Via Developer Console - Query Editor

SELECT Id, Name, Type, extra_type__c FROM Account

ぺこぺこ

Get Accounts by GraphQL (3) - after extra_type__c label of vlaues edited

GraphQL Request body

accounts_with_picklist.json
{
  "query": "query accounts {
    uiapi {
      query {
        Account {
          edges {
            node {
              Id
              Name { value }
              Type {
                value
                label
                displayValue
              }
              extra_type__c {
                value
                label
                displayValue
              }
            }
          }
        }
      }
    }
  }"
}

Request to GraphQL

curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${access_token}" "${instance_url}/services/data/v58.0/graphql" -d @accounts_with_picklist.json
  • In extra_type__c, value and label are different.
response
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Id": "0011m00000lxQLAAA2",
                "Name": {
                  "value": "Foo"
                },
                "Type": {
                  "value": "Customer - Direct",
                  "label": "Customer - Direct",
                  "displayValue": "Customer - Direct"
                },
                "extra_type__c": {
                  "value": "Foo",
                  "label": "Label - Foo",
                  "displayValue": "Label - Foo"
                }
              }
            },
            {
              "node": {
                "Id": "0011m00000lzjq8AAA",
                "Name": {
                  "value": "Sample Account for Entitlements"
                },
                "Type": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                },
                "extra_type__c": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                }
              }
            }
          ]
        }
      }
    }
  },
  "errors": []
}
ぺこぺこ

Edit field extra_type__c value of values

Via Object Manager

Via REST API

// omission

    {
      "aggregatable": true,
      "aiPredictionField": false,
      "autoNumber": false,
      "byteLength": 765,
      "calculated": false,
      "calculatedFormula": null,
      "cascadeDelete": false,
      "caseSensitive": false,
      "compoundFieldName": null,
      "controllerName": null,
      "createable": true,
      "custom": true,
      "defaultValue": null,
      "defaultValueFormula": null,
      "defaultedOnCreate": false,
      "dependentPicklist": false,
      "deprecatedAndHidden": false,
      "digits": 0,
      "displayLocationInDecimal": false,
      "encrypted": false,
      "externalId": false,
      "extraTypeInfo": null,
      "filterable": true,
      "filteredLookupInfo": null,
      "formulaTreatNullNumberAsZero": false,
      "groupable": true,
      "highScaleNumber": false,
      "htmlFormatted": false,
      "idLookup": false,
      "inlineHelpText": null,
      "label": "extra_type",
      "length": 255,
      "mask": null,
      "maskType": null,
      "name": "extra_type__c",
      "nameField": false,
      "namePointing": false,
      "nillable": true,
      "permissionable": true,
      "picklistValues": [
        {
          "active": true,
          "defaultValue": false,
          "label": "Label - Foo",
          "validFor": null,
          "value": "FooValue"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Label - Bar",
          "validFor": null,
          "value": "BarValue"
        },
        {
          "active": true,
          "defaultValue": false,
          "label": "Label - Baz",
          "validFor": null,
          "value": "BazValue"
        }
      ],
      "polymorphicForeignKey": false,
      "precision": 0,
      "queryByDistance": false,
      "referenceTargetField": null,
      "referenceTo": [],
      "relationshipName": null,
      "relationshipOrder": null,
      "restrictedDelete": false,
      "restrictedPicklist": true,
      "scale": 0,
      "searchPrefilterable": false,
      "soapType": "xsd:string",
      "sortable": true,
      "type": "picklist",
      "unique": false,
      "updateable": true,
      "writeRequiresMasterRead": false
    }

// omission
ぺこぺこ

View Account records after edit field extra_type__c value of values

  • In Web Page, Label does not change.
  • extra_type__c value of record change.

VIa Web Page

Via Developer Console - Query Editor

ぺこぺこ

Get Accounts by GraphQL (4) - after extra_type__c value of values edited

GraphQL Request body

accounts_with_picklist.json
{
  "query": "query accounts {
    uiapi {
      query {
        Account {
          edges {
            node {
              Id
              Name { value }
              Type {
                value
                label
                displayValue
              }
              extra_type__c {
                value
                label
                displayValue
              }
            }
          }
        }
      }
    }
  }"
}

Request to GraphQL

curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${access_token}" "${instance_url}/services/data/v58.0/graphql" -d @accounts_with_picklist.json
response
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Id": "0011m00000lxQLAAA2",
                "Name": {
                  "value": "Foo"
                },
                "Type": {
                  "value": "Customer - Direct",
                  "label": "Customer - Direct",
                  "displayValue": "Customer - Direct"
                },
                "extra_type__c": {
                  "value": "FooValue",
                  "label": "Label - Foo",
                  "displayValue": "Label - Foo"
                }
              }
            },
            {
              "node": {
                "Id": "0011m00000lzjq8AAA",
                "Name": {
                  "value": "Sample Account for Entitlements"
                },
                "Type": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                },
                "extra_type__c": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                }
              }
            }
          ]
        }
      }
    }
  },
  "errors": []
}
ぺこぺこ

Edit field extra_type__c value of values disabled

Via Object Manager

Via Web Page

View

  • already has set disabled value, does not change.

New Page

  • Disabled value does not display in candidates.

Via Developer Console - Query Editor

SELECT Id, Name, Type, extra_type__c FROM Account

ぺこぺこ

Get Accounts by GraphQL (5) - after extra_type__c value of values disabled

GraphQL Request body

accounts_with_picklist.json
{
  "query": "query accounts {
    uiapi {
      query {
        Account {
          edges {
            node {
              Id
              Name { value }
              Type {
                value
                label
                displayValue
              }
              extra_type__c {
                value
                label
                displayValue
              }
            }
          }
        }
      }
    }
  }"
}

Request to GraphQL

curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${access_token}" "${instance_url}/services/data/v58.0/graphql" -d @accounts_with_picklist.json
response
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Id": "0011m00000lxQLAAA2",
                "Name": {
                  "value": "Foo"
                },
                "Type": {
                  "value": "Customer - Direct",
                  "label": "Customer - Direct",
                  "displayValue": "Customer - Direct"
                },
                "extra_type__c": {
                  "value": "FooValue",
                  "label": "Label - Foo",
                  "displayValue": "Label - Foo"
                }
              }
            },
            {
              "node": {
                "Id": "0011m00000lzjq8AAA",
                "Name": {
                  "value": "Sample Account for Entitlements"
                },
                "Type": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                },
                "extra_type__c": {
                  "value": null,
                  "label": null,
                  "displayValue": null
                }
              }
            }
          ]
        }
      }
    }
  },
  "errors": []
}
このスクラップは2023/09/10にクローズされました