Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
13 votes

Connect apex and Google API using JWT to retrieve Oauth 2.0 token

As of Winter '17 there are new JWT methods baked in to Apex. One hoop you have to jump through is getting your key from Google into a Java keystore (JKS) file. Some general info on getting a JKS file ...
jon_wu's user avatar
  • 777
8 votes
Accepted

Unable to read ANSI file in apex code?

I hacked a Apex Charset encoder/decoder util, check gist Charset.cls /** * Convenience method that decodes bytes in charset into a string of Unicode * characters. * <p> * @param input ...
nxtr's user avatar
  • 96
5 votes

Connect apex and Google API using JWT to retrieve Oauth 2.0 token

For a properly formatted JWT to be generated, it's important to note that this line of code: JWT = JWT.replaceAll('=',''); Needs to be changed to this: JWT = JWT.replaceAll('=',''); JWT = JWT....
AngularNerd's user avatar
4 votes
Accepted

How to pass API endpoint URL containing \ to

I strongly suspect that something is going sideways because you're not properly escaping the non-safe URL characters (like \ and [); in a URL, they must be in a certain style known as "percent ...
sfdcfox's user avatar
  • 494k
3 votes

Convert application/octet-stream in E-mail Processing class

There are multiple things that can cause this behavior. 1) You might have set the email service to accept attachments in only 'Binary attachments only'. If you that is the case then your issue may ...
AtulRajguru9's user avatar
  • 9,120
3 votes
Accepted

HmacSHA256 encoding in salesforce

Apparently I made a mistake in the conversion. So here's the right conversion method. The issue was that the HMC was a string representation of a HEX so I had to parse it down Here's the correct ...
raym0nd's user avatar
  • 886
2 votes
Accepted

Encoding and Decoding BLOB due to error 'BLOB is not a valid UTF-8 string'

Encoding and decoding is just wasting time; the transformation is lossless and won't wipe out invalid characters. It's possible that you have an extra attachment incoming (e.g. if you have an inline ...
sfdcfox's user avatar
  • 494k
2 votes
Accepted

File saved using ContentVersion appears distorted or low quality

`EncodingUtil.urlDecode((String)data.get('file'), 'UTF-8')` wasn't necessary. decoding just this (String)data.get('file') was the right way.
SfdcBat's user avatar
  • 4,811
2 votes
Accepted

Attachment content is empty

This file looks like a legitimate PNG file fragment when saved and downloaded. Reading through the file, we see: tag length data Magic 8 iVBORw0KGgo= // PNG HEADER IHDR 13 Width = 1678, Height = ...
sfdcfox's user avatar
  • 494k
1 vote

how to 'encode' the body in an HTTP body?

In Apex Code, \ is a source code escape character. That means to get a literal \, you need to type \\ instead. For this reason, among others, I always prefer to use JSON.serialize; it takes more code, ...
sfdcfox's user avatar
  • 494k
1 vote

Encoding and Decoding BLOB due to error 'BLOB is not a valid UTF-8 string'

Same as previous answer, but added other BOM: Blob csvBlob = [...]; // Remove BOM // String encoded = EncodingUtil.convertToHex(csvBlob); Blob decoded = EncodingUtil.convertFromHex( encoded ....
Antonio's user avatar
  • 11
1 vote

How to get Base64 String from Binary String or UTF-8 String

You can't start with a UTF-8 string in Apex; by then, the damage has already been done by UTF-8 string conversion. Instead, use FileReader readAsDataURL to get a base-64 encoded version of the file, ...
sfdcfox's user avatar
  • 494k
1 vote
Accepted

HttpRequest Converting > to?

.replaceAll('=','%3D') should instead be EncodingUtil.urlEncode(... ,'utf-8'). This will make sure that all characters are properly encoded.
sfdcfox's user avatar
  • 494k
1 vote
Accepted

Comparing Message Authentication Codes in Apex

Just use EncodingUtil.base64Encode on both Blob values and compare them as (case-sensitive) strings. String ourMac = EncodingUtil.base64Encode(Crypto.generateMac(...)); String theirMac = ...; Boolean ...
sfdcfox's user avatar
  • 494k

Only top scored, non community-wiki answers of a minimum length are eligible