1

Hello currently I am playing around python and simple salesforce library. I succesfully connect and get data sy SOQL query, but cannot find you the way how to update records/permissions.

sf = Salesforce(username="user", password="pass",security_token="token")

desc = sf.Account.describe()
field_names = [field['name'] for field in desc['fields']]

print(field_names)

soql = "SELECT sObjectType, Field, PermissionsRead, PermissionsEdit FROM FieldPermissions WHERE ParentId IN ( SELECT Id FROM PermissionSet WHERE PermissionSet.Name = 'Experience_Profile_Manager' ) and sObjectType = 'Account' ORDER BY sObjectType"


results = sf.query_all(soql)
df = pd.DataFrame(results['records']).drop(['attributes'],axis=1)

print(df)

here I get permissions on Account object for fields that are actively used.

My question is what is the way, that I can change by request permission of field from query from True to False and vice versa?

Result of my query from org:

0     Account  Account.AccountNumber             True            False
1     Account  Account.AnnualRevenue             True            False
2     Account    Account.CleanStatus             True            False
3     Account     Account.Tradestyle             True            False

My try was:

    sf.FieldPermissions.update('01k7Q0000rOqcyWQAR',{'Field':'Account.AnnualRevenue', 'PermissionsEdit': 'True'})

But unfortunately not right

UPDATE:

Found the way how to UPDATE and CREATE permission sets.

UPDATE: only need permission ID

sf.FieldPermissions.update('01k7Q0000rOr2gVQAR',{'SobjectType' : 'Account', 'Field': 'Account.AccountNumber', 'PermissionsRead': True, 'PermissionsEdit': Flase})

CREATE:

sf.FieldPermissions.create({'ParentId' : '0PS7Q000004Beu0WAC', 'SobjectType' : 'Account', 'Field': 'Account.AccountSource', 'PermissionsRead': True, 'PermissionsEdit': False})
2
  • 1
    What specific error did you receive? Does your user have the View Setup and Configuration system permission? (Please edit your post)
    – David Reed
    Commented Dec 17, 2022 at 0:19
  • @DavidReed my user is system administrator, he has full access. Error is [{'message': 'Cannot deserialize instance of boolean from VALUE_STRING value True or request may be missing a required field at [line:1, column:34]', 'errorCode': 'JSON_PARSER_ERROR'}]
    – Alhanz
    Commented Dec 17, 2022 at 10:51

1 Answer 1

2

This is a great example of why the specific error is so important. As shown in a comment, the error message you received was

[{'message': 'Cannot deserialize instance of boolean from VALUE_STRING value True or request may be missing a required field at [line:1, column:34]', 'errorCode': 'JSON_PARSER_ERROR'}]

That immediately tells you what the problem is. It's not that what you wanted to do isn't possible, or that you didn't have permission to do it. Your JSON just wasn't valid for that API endpoint!

sf.FieldPermissions.update(
    '01k7Q0000rOqcyWQAR',
    {
        'Field': 'Account.AnnualRevenue',
        'PermissionsEdit': 'True'
    }
)

The error message could be clearer, for sure, but Cannot deserialize instance of boolean from VALUE_STRING value True points to the problem: you've supplied the value 'True' as a string, instead of the expected Boolean value True (no quotes).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .