Export Attachments from Salesforce using Teland?

Highlighted
Five Stars

Export Attachments from Salesforce using Teland?

please can any one tell me how to export attachments like (xml,pdf....) from Salesfroce using Talend?

 


Accepted Solutions
Fifteen Stars TRF
Fifteen Stars

Re: Export Attachments from Salesforce using Teland?

As a minimalist solution, connect your tSalesforceInput component to a tJavaRow with the following code:

 

if(input_row.BodyLength > 0) {
    File f = new File(context.YourOutputPath + "/" + input_row.Name);
    FileOutputStream output = new FileOutputStream(f);
    byte[] decoded = Base64.decodeBase64(input_row.Body);
    output.write(decoded);
}

Include the these lines into the advanced settings tab of the tJavaRow component:

 

 

import java.io.File;
import java.io.FileOutputStream;
import org.apache.commons.codec.binary.Base64;

The schema for the tSalesforce component should look like this:

 

Capture.png


TRF
Tags (1)

All Replies
Forteen Stars

Re: Export Attachments from Salesforce using Teland?

@abdelhamed,check below case may be useful.

 

https://community.talend.com/t5/Design-and-Development/resolved-Upload-Attachment-into-Salesforce/td...

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Fifteen Stars TRF
Fifteen Stars

Re: Export Attachments from Salesforce using Teland?

The link provided by @manodwhb is for upload, not for download but you can found many links on Google searching for "java salesforce attachment dowload".

The principle is derived from the upload process: query the attachment objet - decode64 the body content - create the output file.

 

Hope this helps.


TRF
Five Stars

Re: Export Attachments from Salesforce using Teland?

Thanks @TRF

can you please help me more i dont know from where i can start.

Smiley Happy

Fifteen Stars TRF
Fifteen Stars

Re: Export Attachments from Salesforce using Teland?

As a minimalist solution, connect your tSalesforceInput component to a tJavaRow with the following code:

 

if(input_row.BodyLength > 0) {
    File f = new File(context.YourOutputPath + "/" + input_row.Name);
    FileOutputStream output = new FileOutputStream(f);
    byte[] decoded = Base64.decodeBase64(input_row.Body);
    output.write(decoded);
}

Include the these lines into the advanced settings tab of the tJavaRow component:

 

 

import java.io.File;
import java.io.FileOutputStream;
import org.apache.commons.codec.binary.Base64;

The schema for the tSalesforce component should look like this:

 

Capture.png


TRF
Tags (1)
Five Stars

Re: Export Attachments from Salesforce using Teland?

 Hallo @TRF,

 

thanks so much it works like magic Smiley Happy 

 

Merci de votre aide

Fifteen Stars TRF
Fifteen Stars

Re: Export Attachments from Salesforce using Teland?

That's not magic, that's Talend!

TRF
Four Stars

Re: Export Attachments from Salesforce using Teland?

@TRF Is there a way to simply pass the file to the next component instead of writing to your local drive?

 

Ideally I'd like to be passing the created file to a Box folder, therefore using the tBoxInput component which should be accepting the output row.

 

2019-09-26 10_23_31-Window.png

Fifteen Stars TRF
Fifteen Stars

Re: Export Attachments from Salesforce using Teland?

@IanJones, add an output field (let say "decoded") with datatype Object for the tJavaRow component and push the result of decodeBase64 to this field.

Then, select "Upload Incoming Content" for the Upload mode.

This should work (sorry, not tried).

If this is not enough, open a new topic.


TRF

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

APIs for Dummies

View this on-demand webinar about APIs....

Watch Now