Update object description using simple_salesforce

pythonsimple-salesforce

I would like to set the description for all object fields that are layoutable but not present in any layout to: "Not used". I found out how to find fields that are layoutable, but I can't find out how to set the description of a Field using simple_salesforce.

I assume it must be done using the Metadata API, but I couldn't find an example anywhere. I couldn't figure it out myself either. I'd like to do it for all types of fields (both from standard and custom objects).

How can I set the description of a field using simple_salesforce?

Example pseudocode:

sf.objects["Account"].fields["AccountNumber"].set_description("Not used")

Best Answer

You can use mdapi as indicated here. I am not an expert in python, ignore any syntax issues.

    mdapi = sf.mdapi
    custom_object = mdapi.CustomObject.read("Account")
    custom_field = mdapi.CustomField(
        fullName = "AccountNumber",
        description = "Not used"
    )
    custom_object.fields = [custom_field]

    mdapi.CustomObject.update(custom_object)

I haven't dry-tested this code, shared here hoping this might help you. Here you can find more details about the list of attributes that we update through metadata API calls in the salesforce.

Related Topic