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})
View Setup and Configuration
system permission? (Please edit your post)[{'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'}]