Four Stars

Convert String to base64

Hi. Im kind of newbie in all these things and definitely cannot code, so please be patient with me Smiley Happy In our Salesforce org we have custom Note field (String) on Account object. There is a new Notes feature (introduced few releases back), information is stored in ContentNote object, in the Content field, which is base64 type. Im trying to migrate old Notes in new Notes. Im facing the problem to convert the data from String to base64. I found the article where was recommended to use tJava component with following code:

String s = new sun.misc.BASE64Encoder().encode(out.Content);
            //System.out.println("Text Decryted : " + s);
            row4.Content = s;

I tried this but unfortunately it doesnt work, I received an error saying: 

Error in the component's properties:The method encode(byte[]) in the type CharacterEncoder is not applicable for the arguments (String)

Can anyone please help? See attached pictures. For this moment Im just trying to create records in new Notes, I will relate them to Accounts in next step. Many thanks for helptJava Component.pngtMap.pngDesign.png

 

  • Data Integration
1 ACCEPTED SOLUTION

Accepted Solutions
Nine Stars TRF
Nine Stars

Re: Convert String to base64

I think you need to convert String to bytes array before to encode.

Here is a example from StackExchange for the conversion:

String example = "Convert Java String";
byte[] bytes = example.getBytes();

You need to put this in the tJava (or tJavaRow) and pass the result to BASE64Encoder.

Something like that:

byte[] b = out.Content.getBytes();
String s = new sun.misc.BASE64Encoder().encode(b);
row4.Content = s;

If it doesn't solve your problem, let us know.


TRF
2 REPLIES
Nine Stars TRF
Nine Stars

Re: Convert String to base64

I think you need to convert String to bytes array before to encode.

Here is a example from StackExchange for the conversion:

String example = "Convert Java String";
byte[] bytes = example.getBytes();

You need to put this in the tJava (or tJavaRow) and pass the result to BASE64Encoder.

Something like that:

byte[] b = out.Content.getBytes();
String s = new sun.misc.BASE64Encoder().encode(b);
row4.Content = s;

If it doesn't solve your problem, let us know.


TRF
Employee

Re: Convert String to base64

As per above. Use the String getBytes() function. Also, use tJavaRow instead of tJava since you are in a flow.