Reputation: 1
I am trying to access Salesforce through their API. I am trying to run the preliminary code but I get a NameError which doesn't make any sense to me at the moment.
This is my first time taking the previous developers code and trying to run it. I keep getting an error after error.
l=[]
for p in products:
query = 'SELECT '
for c in columns[:-1]:
query += c+','
if (p=='Sigma Upgrade to Insight'):
query += columns[-1] + ' FROM Implementation__c WHERE Imp_Type__c = \''+p+'\''
else:
query += columns[-1] + ' FROM Implementation__c WHERE Imp_Type__c INCLUDES (\''+p+'\') AND Implementation_Status__c != \'PE Trial Ended\''
df_temp = pd.DataFrame(sf.query(query))
l.append(df_temp)
runthrough = ('nextRecordsUrl' in df_temp.columns)
while runthrough:
df_temp = pd.DataFrame(sf.query_more(nextRecord,True))
l.append(df_temp)
runthrough = ('nextRecordsUrl' in df_temp.columns)
I am expecting to run this without any errors but I keep getting a NameError
NameError Traceback (most recent call last)
<ipython-input-4-7b44b14c79ff> in <module>
14 runthrough = ('nextRecordsUrl' in df_temp.columns)
15 while runthrough:
---> 16 df_temp = pd.DataFrame(sf.query_more(nextRecord,True))
17 l.append(df_temp)
18 runthrough = ('nextRecordsUrl' in df_temp.columns)
NameError: name 'nextRecord' is not defined
Upvotes: 0
Views: 43
Reputation: 781726
You need to set nextRecord
to the value of the nextRecordsUrl
element of df_temp
.
df_temp = pd.DataFrame(sf.query(query))
l.append(df_temp)
while 'nextRecordsUrl' in df_temp.columns:
nextRecord = df_temp['nextRecordsUrl']
df_temp = pd.DataFrame(sf.query_more(nextRecord,True))
l.append(df_temp)
Upvotes: 1