Skip to content

Commit

Permalink
use bulk query method
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Oct 28, 2024
1 parent 236d37e commit fe3aa8a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions salesforce/management/commands/update_opportunities.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,23 @@ def handle(self, *args, **options):
"AND Opportunity__r.Contact__r.Adoption_Status__c != 'Current Adopter'").format(base_year)

# This generally returns more than 2,000 records (the SF limit)
# See simplate_salesforce documentation for query_all: https://github.com/simple-salesforce/simple-salesforce?tab=readme-ov-file#queries
response = sf.query_all(query)
records = response['records']
# See simplate_salesforce documentation for query_all: https://github.com/simple-salesforce/simple-salesforce?tab=readme-ov-file#using-bulk
results = sf.bulk.Adoption__c.query(query)

# TODO: this doesn't need to be updating on the opp id, the info never changes
for record in records:
for i, record in enumerate(results):
opportunity, created = AdoptionOpportunityRecord.objects.update_or_create(
opportunity_id=record['Id'],
defaults={'account_uuid': uuid.UUID(record['Opportunity__r']['Contact__r']['Accounts_UUID__c']),
account_uuid=uuid.UUID(record['Opportunity__r']['Contact__r']['Accounts_UUID__c']),
book_name=record['Opportunity__r']['Book__r']['Name'],
defaults={'opportunity_id': record['Id'],
'opportunity_stage': record['Opportunity__r']['StageName'],
'adoption_type': record['Adoption_Type__c'],
'base_year': record['Base_Year__c'],
'confirmation_date': record['Confirmation_Date__c'],
'confirmation_type': record['Confirmation_Type__c'],
'how_using': record['How_Using__c'],
'savings': record['Savings__c'],
'students': record['Students__c'],
'book_name': record['Opportunity__r']['Book__r']['Name'],
'students': record['Students__c']
}
)
opportunity.save()
Expand Down

0 comments on commit fe3aa8a

Please sign in to comment.