question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SalesforceQuerySet update is failing

See original GitHub issue

I’m trying to use the SalesforceQueryset.update method to set a Picklist value and I’m getting a TypeError, stating that what should be a str is in fact a Query

  ...
  account_queryset.update(status=new_status)
  ...
TypeError at /bulk/
must be str, not Query
Request Method: | POST

these are the variables values when invoking salesforce.backend.query.CursorWrapper.execute_update

headers | {'Content-Type': 'application/json'}
pk | <django.db.models.sql.query.Query object at 0x7f10347774a8>
post_data | {'Status__c': 'NEW_STATUS'}
query | <django.db.models.sql.subqueries.UpdateQuery object at 0x7f103a63da20>
self | <salesforce.backend.query.CursorWrapper object at 0x7f1034777128>
table | 'Account'

and this is what gets through to the rest_api_url method itself

args | ('Account', <django.db.models.sql.query.Query object at 0x7f10347774a8>)
service | 'sobjects'
sf_session | <requests.sessions.Session object at 0x7f1034844d30>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hynekcercommented, Aug 30, 2017

I should note, that you don’t need the filter condition is_deleted=False with a normal query set. The “trash bin” can be searched only after query_all() method.

0reactions
dhbahrcommented, Aug 30, 2017

@hynekcer just to be completely clear: my custom managers on SalesforceModel models are actually subclasses of SalesforceManager.

this is my actual code there:

from salesforce.backend.manager import SalesforceManager


DefaultManager = SalesforceManager


class UniversityManager(DefaultManager):

    def get_queryset(self):
        return super(UniversityManager, self).get_queryset().filter(
            is_deleted=False,
            record_type__developer_name='Hochschule')


class StudentManager(DefaultManager):

    def get_queryset(self):
        return super(StudentManager, self).get_queryset().filter(
            is_deleted=False,
            record_type__developer_name='Sofortzahler')

and then on the objects (e.g: Account)

from salesforce import models
from . import managers
...
class Account(models.Model):
    record_type = models.ForeignKey(
        RecordType,
        models.DO_NOTHING,
        blank=True,
        null=True,
        limit_choices_to={'sobject_type': 'Account'})
    ...
    objects = managers.DefaultManager()
    universities = managers.UniversityManager()
    students = managers.StudentManager()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update failed error - Salesforce Developer Community
When I try to modify a field in an object I get this error(which is actually in a trigger). Update failed. First exception...
Read more >
Database.update is not working as expected
1 Answer 1 · According to the docs a QueryException is thrown after 10 seconds when an exclusive lock cannot be obtained. ·...
Read more >
Salesforce Connector OAuth JWT - {"error":"invalid_grant ...
CAUSE. This is usually caused by an invalid Audience Url value specified in Salesforce Connector config. SOLUTION. To solve this, please try ...
Read more >
Update using OpenQuery and Salesforce driver hangs with ...
Run Update OpenQuery(LinkserverName,Query) set Fieldname = value where "TextFieldName" = <value> Observed Results: The query hangs and never ...
Read more >
Salesforce: Scheduled SOQL Recipe won't Trigger When ...
I have a new recipe with a scheduled SOQL Query, set to trigger hourly. Whenever I click Test, the recipe says there is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found