Four Stars

Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

Hello,

 

I have a Talend job that takes in 3 salesforce table name strings given in an input csv file and queries them for one column, "name". I created a tJavaRow component where I am able to loop through all table names in the input file and query them like so: "Select Name from " + TableName + " limit 10"

 

However, I want to be able to get all the columns of the table and query them each. Basically, I want the query to look like this:

"Select " + fieldName + "from " + TableName + " limit 10"

 

I'm having trouble figuring out how to get all the column names of the salesforce table from the input file. Is there any possible way to do this? Below you will find my job design and tJavaRow code screenshots. Thanks in advance to anyone who can help!

 

 

Job Design

Screen Shot 2017-05-10 at 12.27.53 PM.png

 

tJavaRow Component Code

Screen Shot 2017-05-10 at 12.31.03 PM.png

 

6 REPLIES
Ten Stars

Re: Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

it depend - what format of Your csv file (may require different methods)

 

for example - for read all column names from header line, read only 1 row and split it

for not guess and produce ideas, could You attach example - what Your source?

-----------
Four Stars

Re: Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

Hi vapukov,

 

Thanks for your reply. Actually, the column names are not in the excel file. My goal is to get the column names dynamically from the salesforce schema that exists in the talend Metadata panel. So based on the table name, which does exist in the csv file, I want to get the column name from the schema. Here is the excel file formatted with Table name, schema, and last run time.

 

input csv

Screen Shot 2017-05-11 at 10.41.18 AM.png 

 

The salesforce schema exists in the metadata section, which exists in the repository panel in Talend. Here is the screenshot:

Metadata Salesforce section

Screen Shot 2017-05-11 at 10.45.05 AM.png

 

Is there a way I can get the column name of the table from the csv file? I want to be able to access that salesforce metadata from the tJavaRow component. Thanks!

Eleven Stars TRF
Eleven Stars

Re: Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

Hi,

Sorry, but your request is still not very clear IMHO. Just one point, if you want to get Salesforce metadata, you need to go with the Salesforce metadata API which is dedicated to this purpose (not the Rest/Soap API you use to get/put data from/to Salesforce).
Refer to the Salesforce documentation for details.

TRF
Ten Stars

Re: Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

agree with @TRF - better to check Salesforce API for this

 

Talend metadata not available for loop with code or components (similar as Information Schema is databases where You can select all columns, types and etc)

 

 

-----------
Four Stars

Re: Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

Hello Everyone,

 

Thanks for your helpful tips! I'm just having trouble understanding how to integrate the Salesforce Metadata API. Since I am writing my Java code within the tJavaRow component, is it even possible to write the java code to implement the Salesforce Metadata API? To clarify again what I am trying to do, I am given 4 table names within a csv file that exist in the Salesforce schema located in the Metadata section of the Talend Repositories Panel, shown below.

Screen Shot 2017-05-11 at 10.45.05 AM.png

So say the current table being processed by the tJavaRow code is "Account". I want to be able to get all of its columns that exist within it, but the code has to be written inside the tJavaRow component. To clarify again, here is the tJavaRow component code.

Screen Shot 2017-05-10 at 12.31.03 PM.png

 

My question now is, is it even possible to write code for the Salesforce Metadata API within this component? I need to be able to make that SOQL query have dynamic field names, so there must be a way to access it given the table name from the csv file, which in this case is stored in the TabName1 variable.

 

I know that my request sounds very complex and that I'm repeating myself, but I am new to Talend and Salesforce and have a tight deadline to complete this goal. Any help on how to implement the Salesforce API to get the column names given the table name from csv file by writing code in the tJavaRow component would be greatly appreciated. Thanks again everyone for your continued help!

Eleven Stars TRF
Eleven Stars

Re: Get Column Names of Salesforce Table Given Salesforce Table Name in tFileInputDelimitted CSV File

Hi, 

Sorry no time to go in details now but Salesforce metadata API should be accessed using tRest family components, not tJava family. 1st try to get documentation from Salesforce regarding this API with Java example, then translate these examples to Talend (or maybe an other guy have the response ready)


TRF