Jira Attachments: Getting an attachment from a Jira

I previously did a post on writing Jira Attachments from Salesforce, and the question has come up of how to write Jira Attachments into Salesforce.  This is actually WAAAAY easier than it was to write attachments out.  The way that the data is structured from the Jira, we can get a list of all the attachments and the link to it’s content directly from the Jira GET request.  This makes for way fewer calls to get the actual content of the attachment.

Writing Jira Attachments to an object

In the code below, we’ll hit a publicly available Jira, get a list of the Jira attachments and then download that data into a Salesforce Attachment.  With this code, we are only getting the first attachment, but this could easily be modified to iterate over each of the Jira attachments and write them out to the parent.  For the use of this example, we’ll be hard-coding the parent Id and will not be using authentication.  If you have to use authentication, you can either use the same basic auth from the previous post, or you can look at Named Credentials to do this.  Also, I make use of JSON deserialization here.  Because the Jira contains way more information than I care about, this is a non-strict deserialization and only has the bare minimum data required.

Id parentId = 'xxxxxxxx';
String jira_host = 'https://jira.atlassian.com';
String issue = 'JRASERVER-65408';

String url = jira_host + '/rest/api/latest/issue/' + issue;

public class Jira_Attachment {
    public String filename;
    public String content;

public class Jira_Fields {
    public List<Jira_Attachment> attachment;

public class Jira_Issue {
    public String id;
    public String key;
    public Jira_Fields fields;

HttpRequest req = new HttpRequest();

Http h = new Http();
HttpResponse res = h.send(req);
Jira_Issue i = (Jira_Issue) JSON.deserialize(res.getBody(), Jira_Issue.class);

res = h.send(req);

Attachment attach = new Attachment();
attach.Body = res.getBodyAsBlob();
attach.Name = i.fields.attachment.get(0).filename;
attach.ParentId = parentId;
insert attach;

After running this, we can see that the attachment is written out to our object

Jira Attachments

Posted in Development, Salesforce | Leave a comment

Milestone Trigger Time Calculator

I recently stumbled upon a “new” feature in Salesforce that allows you to use an Apex class to calculate your milestone trigger time for entitlement processes.  Given a new feature that I’m working on for our entitlement process, I thought to myself that this could be a good chance to play with it and see what I could do.  If you’re not familiar with the entitlement process in Salesforce, take a chance to look over (or run through) my hands-on training for entitlements so that you’re familiar with the terminology and the concepts since I’ll be jumping right in.

Continue reading

Posted in Development, Salesforce | Tagged , , | Leave a comment

VPN Setup and Auto Connect from Command-line

New servers mean new things to play with and new setups that have to be done.  I set up a new VM that I wanted to always be connected to a VPN and for that VPN to come up whenever the system is started.  The biggest “problem” here is that this VM is running in runlevel 3 so no GUI is available.  So let’s jump into setting up an OpenVPN client using network manger’s command line interface

NOTE: While these instructions are written for Fedora 25, they should work on any system using NetworkManager.  You will have to figure out what packages you need and how to install them if you are not using an RPM (and probably Red Hat based) system.

Continue reading

Posted in Computers, Linux | Leave a comment

Javascript and Visualforce: Tips and Tricks

In the web 7.0 or whatever version of the web we’re in, Javascript is king. Now, there’s lots of stuff you can do directly with Visualforce (like dynamic picklists) but sometimes for the best user experience you’ll want to use Javascript to make it even better. There are lots of Javascript tutorials out there and there are lots of Visualforce tutorials out there (don’t forget Trailhead) so I’m going to talk about some tricks that people should know when working with Javascript on Visualforce

Continue reading

Posted in Development, Salesforce | Tagged , , | Leave a comment

Managing reports and dashboards programatically

One of the challenges you get when you have a special snowflake org is lots of people want to write lots of reports and lots of dashboards for each of their special use cases.  Now, lots of times reports aren’t the right way to go with this so you have to educate your users on the right way to do this and their old reports get abandoned.  Or a user will create a one off report and never look at it again.  As it stands right now, we have several thousand reports that haven’t been looked at in more than 90 days.

Continue reading

Posted in Development, Salesforce | Tagged , , , | Leave a comment

List of objects for POST in Apex REST


A while ago, someone posted on the developer boards a question about how to bulk create tasks for contacts via REST.  I thought it was an interesting enough problem to cover how to do it and how to format the data correctly to use it.


Before we can bulk create tasks for a contact, we need to know how to identify those contacts.  To do this, I create an unique external Id field called External_Id__c.  As long as your contacts are uniquely identifiable then it doesn’t matter what field you use.  For this example I have two contacts under different accounts “Andy Young” with an external Id of “ayoung” and “Edna Frank” with an external Id of “efrank”

Continue reading

Posted in Development, Salesforce | Tagged , , | Leave a comment

Table Header in PDFs with Visualforce

Table header in PDF
One of the problems I had with the way that we generated the PDFs in previous Battle Station Invoice posts was that the table header wasn’t repeated for long lists of supplies or resources that continued on the next page.  There’s a simple way to add the table header for PDFs generated in Salesforce using the flying saucer mark-up but that won’t generate the table header correctly for us.  It seems that the -fs-table-paginate tag does not play well when combined with a Visualforce component so we’ll need to take a bit more of a native CSS approach.

NOTE: If you are doing this with plain Visualforce and apex:pageBlockTable, the -fs-table-paginate is the way to go.

Continue reading

Posted in Development, Salesforce | Tagged , , | Leave a comment

GlobalPicklist changes in Winter ’17

Like many companies, we have a deployment process in place to handle changes in seasonal releases in Salesforce so that when a sandbox is ahead of production, we can still deploy to both without having to wait for production to be updated.  Then, after both the release hits production, we go through a manual process of updating the API (primarily the ant-salesforce.jar) and the metadata to the most recent API version.  Typically this just involves updating the jar and updating the API version in the request, pulling down the updated metadata and writing it to SCM.  However, with the Winter ’17 release we saw a problem trying to deploy our GlobalPicklist files after updating the API.

Continue reading

Posted in Development, Salesforce | Tagged , , | Leave a comment

Japanese Users and Reports

There are lots of times where working with Salesforce would be so much easier if it weren’t for the users.  But, they’re the reason I still have a job, so you’ve got to put up with them.  One of the problems with users is they tend to like to live all over the world and they all have their own ways of working and cultural eccentricities.  One of the ones that has caused us grief in the past (both in Apex and in reports) is the fact that Japanese users in Salesforce default to “Lastname Firstname” when using the Name field on Users.   Now, this in and of itself is not really a problem because lots of reports are written for a single user or for a relatively small group of users (such as others in the same geographical location).  Where this becomes a problem is when locales get mixed with reports and all hell breaks loose.

Continue reading

Posted in Development, Salesforce | Tagged , , | Leave a comment