0

I am trying to combine three columns(same data type) from three tables. I am receiving a malformed request error that I can't quite figure out. Initially I tried a UNION ALL but I learned that SOQL does not support this. Is there a way to write this query in a single line as below? I would like to have a single column ,single table result. This is the error I am getting

^\nERROR at Row:1:Column:43\nunexpected token: namecolumn', 'errorCode': 'MALFORMED_QUERY'}]
from sf_query_pull import QueryDataToFile
from pathlib import Path
import pandas as pd


class Pull_data:
    '''Pulls salesforce data'''

    def __init__(self):
        '''performs the actual query of salesforce data and calls the other methods.'''
        
        
        self.query = "".join(
            ["SELECT namecolumn FROM table1","SELECT namecolumn FROM table2","SELECT namecolumn FROM table3;"])
            
          
        self.files = { 'results': str(Path.cwd()) + '\\TestQueryResult.csv'}

        self.query_data()

    def query_data(self):
        '''Pull real-time data from Salesforce.'''
        print(': Pulling data from Salesforce.')
        QueryDataToFile('prod', self.query, self.files['results'])
        
Pull_data()

1 Answer 1

1

You can't do this in Salesforce's SOQL. You'll need three separate queries, which you can then combine at the end to create your CSV file.

You have two basic choices, though: you can use /services/data/v51.0/composite to perform three different queries via a Composite API request, or you can perform each one in sequence. I'd recommend the first option, as it uses only one API call and should be easier to code for.

0

You must log in to answer this question.

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