<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cheney Shreve on Medium]]></title>
        <description><![CDATA[Stories by Cheney Shreve on Medium]]></description>
        <link>https://medium.com/@cheney.shreve?source=rss-8ea386265f24------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pgsUOLHzccHM91JXZbDmig.jpeg</url>
            <title>Stories by Cheney Shreve on Medium</title>
            <link>https://medium.com/@cheney.shreve?source=rss-8ea386265f24------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:23:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cheney.shreve/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Working with forms and modals in the Aura framework]]></title>
            <link>https://medium.com/@cheney.shreve/working-with-forms-and-modals-in-the-aura-framework-600f3b5190f3?source=rss-8ea386265f24------2</link>
            <guid isPermaLink="false">https://medium.com/p/600f3b5190f3</guid>
            <category><![CDATA[modal]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[aura]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[Cheney Shreve]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 00:10:46 GMT</pubDate>
            <atom:updated>2019-03-18T00:10:46.615Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BSX61CxShyqW7oT7Kgc8Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/XMFZqrGyV-Q?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fabian Grohs</a> on <a href="https://unsplash.com/search/photos/developer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I really like the open source Aura framework used in Salesforce Lightning. I like earlier Visualforce as well; it reminds me a lot of Ruby-on-Rails and makes customizing the UI fun and fast. I don’t get to do as much programming in Aura as I’d like, as many clients are predominantly utilizing Visualforce, so this morning I brushed up on modals and forms in Aura. I wanted to hit on a few points that are maybe less obvious the first time you work with forms and modals, so this demo covers:</p><p>· Using compound fields like name and address</p><p>· Multiple examples of performing input field validation</p><p>· Making reusable functions</p><p>· Manually defining picklists vs. dynamically fetching picklist values</p><p>· Using lightning notifications library to display error messages on top of the modal</p><p>You can find the complete code on <a href="https://github.com/cheneyshreve/lightning_forms_demo">github</a>. I’ve added comments to the code regarding the points above.</p><p><em>Side note</em>: there are other ways to accomplish the same task here, such as record create functionality so check the developer docs!</p><p>Here is a demo of how to wire-up the Quick Action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7J5-DO7WBCgQCJxVj6eaww.gif" /></figure><p>Here’s a demo of what the form looks like inside the modal, and what the field validation looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7H0DXMQifi4xUGh3-8riQ.gif" /></figure><p>The fun part was finding a great <a href="http://regexlib.com/(X(1)A(0_Ko3nQsaSuP8i8EpynMr5o5oWuohcSu4ms6X7GNGe-Z_uVEAENRctEiHRKlgKpo1YA7gOe0aehmryaST7N7e2pYYtdnzNzUi2L-bJv2e3DBR0tRS_mBn1o-gaLoNH6N_xzz4Zm9-_bw6q6luwSgOEMSOkUSIUpavznN4xVuzRKuvvpwh8yYWVXvB7DMHGsa0))/Search.aspx?k=phone&amp;c=-1&amp;m=-1&amp;ps=20">regular expression library</a> to help with customizing validation for phone numbers. You could easily modify it to include or exclude spaces, slashes, 1s, country codes, etc.</p><p>Another thing I came across was a workaround for addressing a known issue with error notifications, e.g. that they appear behind the modal, yikes! I’ve used the lightning notifications library to display the error messaging on top of the modal. In keeping with good practice, I also added in code for custom error handling based of this <a href="https://developer.salesforce.com/blogs/2017/09/error-handling-best-practices-lightning-apex.htm">Salesforce developer blog</a>.</p><p>This was a laid-back Sunday morning code, so I didn’t focus on styling and did a first pass round of testing and debugging. Find a bug or want to contribute? Submit a PR to the repository on <a href="https://github.com/cheneyshreve/lightning_forms_demo">github</a>. Don’t know how? No worries, if you want to learn, I’m happy to help, or you can also create a public github gist with no git skills required. I always strive to reference other resources I use or get inspiration from along the way, I hope you find them useful too! Happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=600f3b5190f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Traversing the declarative and programmatic divide: The same task with 3 different Salesforce Tools]]></title>
            <link>https://medium.com/@cheney.shreve/traversing-the-declarative-and-programmatic-divide-the-same-task-with-3-different-salesforce-tools-b4df73d29537?source=rss-8ea386265f24------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4df73d29537</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[workflow-rule]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[process-builder]]></category>
            <category><![CDATA[salesforce-developer]]></category>
            <dc:creator><![CDATA[Cheney Shreve]]></dc:creator>
            <pubDate>Sun, 17 Mar 2019 03:29:10 GMT</pubDate>
            <atom:updated>2019-03-17T03:29:10.783Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*igeimPX-Ueu4ioqiAxL1sw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/G9XMLUAjETM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Suhyeon Choi</a> on <a href="https://unsplash.com/search/photos/three?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>As a Salesforce developer, you might think you’d be doing that thing, coding, all day long. You’ve studied Java or JavaScript and Apex and you’re pretty comfortable with life, then reality hits: your client doesn’t want it done with code, they want it done declaratively, so you need to learn it today. Or you’re a Salesforce Administrator, a master of declarative tools, and all of the sudden, your client doesn’t want the solution 100% declarative, they want a hybrid or a code-based solution and yeah, you’ve got to learn it today! Back up a second, what do I mean by “declarative”? Essentially, code-free Salesforce tools that let you tap into Salesforce functionality to further customize your org (e.g. your Salesforce universe).</p><p><a href="https://trailhead.salesforce.com/en/trails">Trailhead</a> is a training oasis for administrators and developers alike. Okay, it’s more than just a learning oasis, it’s a community, a support network, and…it’s free! However, there aren’t many trails for “Admin/Developers” or “Developer/Admins” — a trail for when you have a few hours to do something and you need to try out different solutions: declarative, code-based, or hybrid, so I’m hoping to help fill that gap.</p><p>So, let’s start with something simple, here’s our business case:</p><blockquote>The client wants 2-business days added to a custom field called “Shipping Date” on the Case object when the Case Status changes to “Approved”.</blockquote><p>What this tutorial covers, the same task using 3 different Salesforce tools:</p><p>· Declarative approach: Using Workflow Rules</p><p>· Hybrid approach: Using Process Builder &amp; Calling An Invocable Apex Method</p><p>· Code-based approach: Using a Trigger</p><h4>Setup: Add custom field to the Case object with the following criteria, reference the gif below if you are unsure of how to do this.</h4><blockquote>Type: Date</blockquote><blockquote>Field Label: Shipping Date</blockquote><blockquote>Field Name: Shipping_Date</blockquote><blockquote>Description: Field to store the shipping date.</blockquote><blockquote>Visibility: All profiles</blockquote><blockquote>Page Layouts: Select all available</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OJO60gfEXzzeJBTMfCHPmQ.gif" /></figure><h4><strong>Setup</strong>: Customize the “Business Hours”.</h4><p>No one really wants to work weekends, right? Why are we messing with Business Hours? Because this is a great resource that we’ll tap into later when we’re looking at hybrid and code-based solutions. Business Hours lets us simplify by providing a template where we can add in holidays, extended hours for different workdays, etc. If you try to do that either purely declaratively or programmatically, it gets nasty fast, so use Business Hours!</p><blockquote>Business Hours Name: Tutorial Business Hours</blockquote><blockquote>Business Hours: leave default with weekends blank</blockquote><blockquote>Add a holiday: April 1st</blockquote><p>You do have to activate the Business Hours, so make sure the “Active” checkbox is checked. Don’t know how to do this step, check out this GIF below to walk you through:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9pm2IjDfJU95u6S7COdzTQ.gif" /></figure><h4>Part I: Declarative Approach Using Workflow Rules</h4><p>We could use workflow rules or process builder to do this step. <em>Tip</em>: there are benefits/limitations to workflow rule vs. process builder, you will be asked about these on the Platform Developer I exam.</p><p>Create a new workflow rule with the criteria below. If you need help with this step, check out the gif.</p><blockquote>Name: Populate Shipping Date</blockquote><blockquote>Description: Workflow rule to calculate and populate the Shipping Date custom field when Case Status changes to Approved.</blockquote><blockquote>Evaluation Criteria: created, and any time it’s edited to subsequently meet criteria</blockquote><blockquote>Rule Criteria: criteria are met</blockquote><blockquote>Field: Case</blockquote><blockquote>Operator: equals</blockquote><p>Value: Approved</p><p>=&gt; Save, then you can add workflow actions.</p><blockquote>Immediate workflow actions: Field update</blockquote><blockquote>Name: Calculate the Shipping Date</blockquote><blockquote>Unique Name: Calculate_the_Shipping_Date</blockquote><blockquote>Data Options: Use a formula to set a new value</blockquote><p>Formula:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f39e114c949257f9f2fc597ce1a8f8df/href">https://medium.com/media/f39e114c949257f9f2fc597ce1a8f8df/href</a></iframe><p>=&gt; Click “Save”. <em>Tip</em>: Google Salesforce calculate business hours and you’ll see so many hits, it’s a very common question/application. You can check out example formulas in the <a href="https://help.salesforce.com/articleView?id=formula_examples_dates.htm&amp;type=5">Salesforce docs</a>, trailhead, or numerous blogs. We could’ve written the above formula at least a dozen different ways, find one that works for your use-case!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3vVfpCRHd_ipC-eCnsrptw.gif" /></figure><p><strong>Testing:</strong> First, make sure you’ve got the “Shipping Date” field added to the Page Layout. I’m using the “Case Layout” as my org default. If you’re using something else as the default, make sure you’ve added “Shipping Date” to the record. See gif below if you’re unsure how to implement this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TgH3QXdZH_zS7JoexZnFPg.gif" /></figure><p>Okay, cool, that was pretty fast! Let’s test it out. Create a new Case record with Status = New and Case Origin can equal anything from the picklist (dropdown menu). Save the record. The Shipping Date field will be blank. Update the record to Status = Approved. The Shipping Date field will populate to today + 2-business days. See the gif below if you’re unsure how to implement this step. <em>Tip</em>: make sure you activate your workflow rule! Click on “Activate” next to the name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZM1uBN0fkz7W_KPcrFOiw.gif" /></figure><h4><strong>Cleanup time</strong>: Don’t forget to <strong>deactivate the workflow rule</strong> before we move on to the next step!</h4><h4>Part II: Hybrid Approach Using Process Builder and Invocable Apex</h4><p>First we’re going to go ahead and create a couple Apex classes.</p><p>Open the Developer Console and create a new Apex class named “BusinessDays”. Copy and paste in the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2155f7f57d87c53871bd0cb70f55a6d4/href">https://medium.com/media/2155f7f57d87c53871bd0cb70f55a6d4/href</a></iframe><p>Create another class called “CalculateShippingDate”. Copy and paste in the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21895db53d9ed43df66c88f022bc3baa/href">https://medium.com/media/21895db53d9ed43df66c88f022bc3baa/href</a></iframe><p>Create another class for testing called “CalculateShippingDateTest”. Copy and paste in the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f862347ea7494071edb24b5f9d210cbd/href">https://medium.com/media/f862347ea7494071edb24b5f9d210cbd/href</a></iframe><p><em>Tip</em>: Be sure to run your test either through the Developer Console or from Setup, enter “apex test execution” and select the test class to run. You should have 100% coverage for the CalculateShippingDate class.</p><h4>Wire it up with Process Builder! Create a new flow with the following criteria, if you are unsure of this step, check out the gif below:</h4><p>Object: Case</p><blockquote>Start the process: when a record is created or edited</blockquote><blockquote>Criteria</blockquote><blockquote>Criteria Name: Status = Approved</blockquote><blockquote>Criteria for Executing Actions: Conditions are met</blockquote><blockquote>Set Conditions</blockquote><blockquote>Field: [Case].Status</blockquote><blockquote>Operator: Equals</blockquote><blockquote>Type: Picklist</blockquote><blockquote>Value: Approved</blockquote><blockquote>Conditions: All of the conditions are met (AND)</blockquote><p>Immediate Actions</p><blockquote>Action Name: Calculate the Shipping Date</blockquote><blockquote>Apex Class: add two business days</blockquote><blockquote>Field: inputCase</blockquote><blockquote>Type: Field Reference</blockquote><blockquote>Value: [Case]</blockquote><p>Note: we want the Case record that started the process</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ObDg8-E_wFKG1vtsE0kbJw.gif" /></figure><p><strong>Test it</strong> — go create a new case and then update the Status to approved, you should see the Shipping Date populate. If you need a reminder on how to do this, check out the gif below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RlY7diV1rmjxtjN6gTr2TA.gif" /></figure><h4>Cleanup time: Don’t forget to <strong>deactivate the Process Builder </strong>before we move on to the next step!</h4><h4>Part III Code-based Approach: Using an Apex Trigger on Case</h4><p>It’s trigger time! What is an Apex trigger? In a nutshell, it’s just a special class that gets invoked after certain events occur on a record. We won’t dig too much into trigger details here, but I will throw in some good practice tips like putting the trigger logic in an Apex class. This helps keep the code clean when you get dozens of triggers on the same object.</p><p><em>Tip</em>: Make sure you have deactivated both the workflow rule and the process builder we created before you do this step!</p><p>Open the Developer Console. Create a new trigger named CaseTrigger. Copy and paste in the code below and save.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca08928479083e4adc1c8ba9ff92549f/href">https://medium.com/media/ca08928479083e4adc1c8ba9ff92549f/href</a></iframe><p>Create a new Apex class named CaseTriggerHandler. Copy and paste in the code below and save.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed7cb8b78c6ce98d64507fd6b84d60ac/href">https://medium.com/media/ed7cb8b78c6ce98d64507fd6b84d60ac/href</a></iframe><p>Create a new Apex class named CaseTriggerHandlerTest. Copy and paste in the code below and save.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1a1d0636b4a4ecab5a206c309fc2aba/href">https://medium.com/media/d1a1d0636b4a4ecab5a206c309fc2aba/href</a></iframe><p><strong><em>Tip</em></strong>: Run your Apex test class, either through the developer console or from Setup -&gt; Apex test execution. If you get a failure, make sure your trigger is active. Go to Object Manager → Case → Triggers → click on the trigger name and edit. Make sure the teeny, tiny “Is Active” checkbox is checked, see the gif below. You should have 95% test coverage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jU8K4mY5T_8NQe47cRN6kw.gif" /></figure><p><strong>Test the trigger.</strong> Create a new record and see if the Shipping Date gets populated when the status equals Approved. Try creating a new Case with Status = Approved, check that the functionality works. Try making a new case where Status does not equal Approved, then updating it so the Status does equal Approved, check that the functionality still works.</p><h4>Clean up: <strong>Deactivate that trigger!</strong> You do not need extra (active) triggers in your org, not even your developer edition. You’ve still got governor limits, baby!</h4><p>Wrap up, okay, that was a lot! You did amazing. You’re a natural.</p><p>To sum up, working through all 3 of these exercises in one fell swoop, you can get an idea of the pros/cons:</p><p>Workflow rule</p><p>=&gt; Time: warp speed!</p><p>=&gt; Potential limitations: our formula works pretty well, but we didn’t tap into the functionality of the BusinessHours Class in Apex, so we miss out on skipping stuff like holidays in our calculations</p><p>Process Builder</p><p>=&gt;Time: moderate, we had to write a bit of Apex, but not too much</p><p>=&gt; Potential limitations: a bit more complex to understand for an admin/developer or developer/admin, but not so bad! Lets’ us tap into the BusinessHours class functionality.</p><p>Apex trigger</p><p>=&gt; Time: well, that depends on your experience and the complexity of the org. Things might be super-fast in your developer edition, you may not have hundreds of workflow rules or dozens of actions being called in one trigger. In a client’s org, you most likely will! Be sure you budget in time for this when implementing this solution for a client.</p><p>=&gt; Potential limitations: Code is great, but it’s also less accessible to the client in general. <strong>If you can do it declaratively, you should always do that first. </strong>If you can’t, try a hybrid or code-only approach!</p><p>Okay, we’re all done! Time to enjoy that second breakfast now. I hope this tutorial was useful for you. Please let me know in the comments below if you have any questions or feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4df73d29537" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Salesforce for the rest of us]]></title>
            <link>https://medium.com/@cheney.shreve/salesforce-for-the-rest-of-us-b69fe94ba07d?source=rss-8ea386265f24------2</link>
            <guid isPermaLink="false">https://medium.com/p/b69fe94ba07d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[career-change]]></category>
            <dc:creator><![CDATA[Cheney Shreve]]></dc:creator>
            <pubDate>Sun, 17 Feb 2019 20:34:10 GMT</pubDate>
            <atom:updated>2019-02-17T20:34:10.305Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SxBklOnK3-94b7bB02Q-Sg.png" /></figure><p>My purpose in starting this story thread is to create a space for developers who are new to Salesforce, Admins looking to move into development, career changers, and hopefully, to get some more experienced devs, to chime in about their experiences.</p><p>I got into Salesforce completely by accident. My earlier career was in academic research, and I had just finished a boot camp to learn some more modern programming languages to transition into tech. I started working for a startup, mainly on AWS projects, then later, Salesforce. I currently work remotely as a Salesforce developer so I can offer insight on changing careers, starting out as a junior developer in tech, and hopefully, providing insight into Salesforce for job seekers.</p><p>Salesforce bought Heroku back in 2010 and you can also incorporate Ruby, React and other frameworks in various ways, so some of the code I’ll go over touches on that. I’ll provide project examples that demonstrate what kind of activities you might be engaged in as a Salesforce developer so that you can get a better idea of whether or not Salesforce development is for you.</p><p>As for me, I’m hoping to gain feedback to hear about how folks do things differently, and what you enjoy about Salesforce. If there is a particular trailhead you’re struggling with or project, let me know and I’ll see if I can help!</p><h4>What is Salesforce?</h4><p>Salesforce is a Customer Relationship Management platform or CRM based in the cloud. The database is object-based, which is pretty cool. You write the server-side code in a language called <a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dev_guide.htm">Apex</a> which is very similar to Java. Haven’t done Java before? That’s okay. If you have a good working knowledge of object-oriented programming from another language like Ruby, JavaScript or Python, that will certainly help speed up the learning process. The front-end can be the classic version of Salesforce, using what’s called Visualforce, and putting it all together, that combo essentially equates to a Model-View-Controller or MVC design pattern.</p><p>There’s also an updated version of Salesforce called the Lightning framework. The Lightning framework has similarities with React; you’re constructing a Single Page Application (SPA), it’s a component-based architecture, you’re only updating the variables on the page when they change, but it’s different. So, oversimplifying a bunch, as a programmer, it feels like you define some variables in your component along with event handlers, a JavaScript controller (essentially, a bunch of functions) to do some stuff when these changes occur, which may or may not include passing values to the server-side controller (also a bunch of functions) to do some other stuff. It’s built on the open source <a href="https://github.com/forcedotcom/aura">Aura framework</a>.</p><p>Technical jargon aside, I would never have predicted that Salesforce would be a thing I came to love. Coming from a Ruby/JavaScript/R background, I had no prior experience with Java or the Aura framework before starting Salesforce. Where frameworks like React and Vue kind of meld together, Aura, not so much, so there is a bit to learn.</p><h4>What is Trailhead?</h4><p>I won’t lie, at first I was not a fan of <a href="https://trailhead.salesforce.com/en/trails">trailhead</a>, which is Salesforce’s free online learning platform. They give you a developer license and you can practice and build whatever you want. Want to use their AI to analyze images of kittens, there’s a <a href="https://trailhead.salesforce.com/en/content/learn/projects/predictive_vision_apex">trailhead</a> for that? In comparison, AWS gives you 1-year free and sorry, AWS, but your technical docs and tutorials need some TLC; they aren’t beginner friendly.</p><p>The reason I didn’t like Trailhead at first, I’m <strong>100%</strong> converted now, is basically just because I had to get over not being immersed in my VS Code, Atom console, and command line 100% of the time. It feels noisy to move out of a code editor, the clean sleek lines of code, into pretty much any other software. <em>Tiny violins</em>.</p><p>It’s a bit jarring at first to be immersed in the Salesforce platform because there is <strong><em>so</em></strong> much you can do, but it is also absolutely brilliant and quickly becomes familiar. How many developers work in the software they build every day instead of just coding it? As a developer, it forces you to understand exactly what your clients are working with, working in. It made me realize how selfish I had been up to that point, I wasn’t thinking so much of the end user when I was writing code, I was only thinking about what I wanted to build, or how I wanted it to look or what skills to showcase for a portfolio. In general, I’m less interested in how stuff looks and more interested in how stuff works; though I recognize that both are essential.</p><p>I think one of the reasons Salesforce is so successful is because it forces developers to put the client first. You live in their software. Yeah, you write code, but you have to know the platform intimately to understand how to write effective code, how to really elevate what you build for the client.</p><p>I’m fortunate to work at a company where the business is run in Salesforce, so I’m literally immersed in it all day and it’s a great platform! Speaking of which, you get to work with a really diverse clientele because everyone from Fortune 500 companies to Google to the Gates’ Foundation to small non-profits is using the platform. It’s a great time to dive in!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b69fe94ba07d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with “ugly” data]]></title>
            <link>https://medium.com/@cheney.shreve/working-with-ugly-data-a9cac9bd9623?source=rss-8ea386265f24------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9cac9bd9623</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[gender-equality]]></category>
            <category><![CDATA[public-health]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[rails-5]]></category>
            <dc:creator><![CDATA[Cheney Shreve]]></dc:creator>
            <pubDate>Mon, 06 Aug 2018 01:42:01 GMT</pubDate>
            <atom:updated>2018-08-06T01:42:01.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LI9TzwDU1l6IyJFBRcULw.jpeg" /><figcaption>Photo Credit: Franki Chamaki Unsplash</figcaption></figure><p>Nearing the close of my training in software development at Bloc, one assignment we’re given is to start our own open source project on GitHub. It’s a bit of a muddle, as we begin this assignment before we start contributing to other, well-established, open source projects. I’m pretty sure the intent is largely to get us thinking about the energy that goes into managing an open source project; from the license and contributing guidelines, installation details, testing frameworks, listservs or other modes of communication, and most importantly, the energy and care that goes into mentoring new contributors.</p><p>(Hu)manning an open source project is not for the faint of heart. Despite the tools for automated testing, linting, and the like, one bad PR from a well-intentioned newcomer could really throw a wrench in your project. There’s no doubt in my mind that project maintainers have to painstakingly, patiently review each commit. If you’re lucky, as I have been, they give you good, constructive feedback too, but that’s a different blog.</p><p>For my first open source project, I’m making all the mistakes that I can, trying out different design patterns and technologies, and yes, I chose to work with “ugly” data.</p><h3>Why?</h3><blockquote>In short, why not? Now’s the time to learn and fail fast, when there’s no client on the other end or major shipping deadline.</blockquote><p>Like most boot camps, I’ve spent a fair amount of time at Bloc building a portfolio of social media apps like chat rooms, music players, wikis, to-do lists, analytics trackers, etc. I’ve learned some useful and practical skills from these projects like how to manage user authentication and authorization, user roles, subscriptions, building APIs, database fundamentals, etc. I like these trendy apps as much as the next person, but I care more about the greater purpose, and yes, the empowerment, that software can provide. I want to build software that lets you do things that you couldn’t do so easily before, that lets you think about data differently, that gives you different insights, that empowers you to use data to <em>your </em>benefit.</p><blockquote>Full disclosure: I am not there yet. If you hire me and give me time, and I will make these things with you.</blockquote><p>As an ecofeminist with a background in physical sciences and human development coming into tech, one thing that really irks me is the collection and management of data on social and environmental equity. This data is the evidence base that underpins international frameworks and development goals. It’s what economists and policymakers use to decide if we invest more in education or health. Platforms like UN Gender Statistics have made tremendous leaps and bounds in terms of presenting this kind of data through visually pleasing, responsive graphics; a technical feat I am not going to replicate on my own in the short time span of this project, but don’t I wish! But we need this data to be more personalized, more accessible, more relevant to our everyday lives.</p><p>Despite limitations of my current circumstances, I want more. I want analysis tools, a “do science” button, something with teeth that lets me connect with the data, bend it to my will, to put it to work for me. You see, I believe that people start to care about science, about data, when they’re in the driver’s seat. When people can create narratives relevant to them, their city, their watershed, their kid’s school, with data and use that to support equal pay, better environmental standards, better gun policy, etc. then people are actually benefitting <em>from</em> the data.</p><p>I’m digressing by talking more about why I want to be a software developer and less about what I’m learning. From a purely technical perspective, working on this project has introduced me to design patterns other than MVC, to integrating new libraries in a frontend built with React, like Axios, Html2Canvas and Victory, to using the new Rails-5 API on the backend, and lest we forget, coming to terms with “ugly” data, and dealing with government APIs, which sadly, aren’t always that performant.</p><p>What do I mean by “ugly” data? Non-homogeneous, hundreds of categories, thousands of indicators, data gaps, heinously long category names, and less performant APIs, you know, the kind that don’t always send you back data, or send it back fast by today’s standards. The end result, as you can imagine, is the user has to wait a few seconds for data to load. The other end result is that there’s no easy way to display the data — how does one easily display hundreds or thousands of indicators with tons of different categories? Lists, click-by-country, etc.? I’m not quite sure. Here’s as far as I’ve gotten, it’s not pretty yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*tljLU63ymDTIjpt72zLTfA.gif" /></figure><p>What have I learned? I’ve gained new opinions, I prefer the Victory library put out by Formidable because it’s a lot easier to manipulate display variables compared to react-vis, which is what I started with. I do not have a gift for design, well, actually, I knew that already. I’ve recognized gaps in most of the visualization libraries I’ve experimented with, mainly, they don’t have export options, ouch! As a quick fix, I used Html2Canvas, which will let you save the contents of a div as an image. The catch is you can only do it for one div per “page”, therefore I had to put my graphs on different pages. To my knowledge, highcharts is the only library I could find that does have a baked in export function, so one of my next steps will be to migrate to highcharts.</p><p>In the interim, I’m more interested in the analysis piece. I’ve been testing out different libraries and resources for basic ML and statistical analyses (who says you can’t do <a href="https://github.com/mljs/ml">ML with JavaScript</a>?) to some more in-depth analyses with my old friend R, and researching the best ways to integrate that data with my current project.</p><p>Ultimately, I want to empower the user to learn more from the data, to be a bit more curious, to be more critical. A click or two to show which countries or regions have an increasing trend in maternal or infant mortality rates, push a button and get a projection for 2020 rates, or the like, then go complain to your senator. For example, why is the US one of few more affluent nations seeing an increase in maternal mortality rates since 1990? I have a few ideas, but that’s for a different post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*1QSkCTmioC0RJugSSfybFA.png" /><figcaption>Trends in estimates of maternal mortality ratio (MMR; maternal deaths per 100,000 live births) 1990–2015 USA Data Source: WHO, UNICEF, UNFPA, World Bank Group and UNPD (MMEIG) — November 2015</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9cac9bd9623" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tiptoeing into algorithms and data structures: Make a stack function like a queue]]></title>
            <link>https://medium.com/@cheney.shreve/tiptoeing-into-algorithms-and-data-structures-make-a-stack-function-like-a-queue-3f75dd95cbd1?source=rss-8ea386265f24------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f75dd95cbd1</guid>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[Cheney Shreve]]></dc:creator>
            <pubDate>Sun, 13 May 2018 00:55:07 GMT</pubDate>
            <atom:updated>2018-05-13T00:55:07.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glUVRCC66KteKBjCxJXh5Q.jpeg" /><figcaption>Photo credit: Abbie Bernet, Unsplash</figcaption></figure><p>For many like myself, who are transitioning into software development through a non-traditional education, e.g. a 9-month boot camp versus a 4-year computer science degree, speeding through data structures and algorithms in a few weeks can feel a bit overwhelming. Conceptually, sure, it’s not that bad comprehending arrays, linked lists, hashes, trees, or graphs, or even thinking about how and when to use them; boot camps force you to build first, proving to you that you can do it (develop software apps), then you dive into the philosophy of why and how later. Later being just a few short weeks before interview time!</p><p>So, it’s easy to understand why students feel nervous. How it can make you question if you’ll <em>ever</em> be ready, or if you even know how to write a single line of code! If you’re feeling this way, take heart; you <strong><em>can</em> </strong>do this. <strong>We</strong> can do this, together.</p><p>I’ll only jabber on a little bit longer before diving into the code, but I just want to say to readers out there, if you’re feeling disheartened during this phase of your journey into development, get out there and meet people. Go to a Meetup group, dive into a friendly online forum, I recommend site that I was recently told about <a href="https://www.askquestions.tech/">AskQuestions.Tech</a> and be vulnerable; ask for help.</p><p>Here’s what I learned today, at a 9 AM Saturday morning “Algorithms Practice on a Whiteboard” Meetup. I didn’t know how to do this going in, but after discussing concepts with the group, I walked out at the end of the meeting, sat down and was able to write the code myself. While I admit I was disappointed that I didn’t know it right off the bat, that’s one of the things I appreciate about tech; I’m humbled every single day. Many days, I’m not just humbled, I’m down right <em>uncomfortable</em> and I’m happy about it. I’m happy because I know that I’m learning. Learning <strong>is </strong>a little bit uncomfortable, but in a good way; you know you’re growing, and that is the reward.</p><p>Every time I go to a Meetup, I feel stronger, regardless of whether or not I ‘got the problem’. I feel stronger because I voiced my uncertainty, I asked questions, I tried things, I failed, I watched others succeed, I listened to others, I learned. If you’re feeling anxious, dip your toes in, you’ll feel better, it will get better!</p><p>So, here’s your potential interview question: You’re given a stack, how do you make it function like a queue?</p><p>Let’s assume that our stack and our queue are both built on arrays. Recall that stacks are LIFO, or last-in-first-out. Think of the lunch tray analogy, say your job is to stack the lunch trays; the one you stack first will go on the bottom and the stack will build upward so the first one you take off will be the last one that go placed onto the stack (last in, first out, or LIFO). Now consider a queue, which is the opposite. A queue is more like a line at a coffee shop; the first person into the line is the first person to get served coffee and leave the line, assuming you haven’t been making enemies with the baristas!</p><p>So how do we make a single stack act like a queue without using another data structure, such as another array? The trick is using recursion, though I’m sure there are other ways you can think of to do it to. Let me show you the code I wrote in Ruby, then I’ll step you through what it’s doing. The numbering does not indicate any sort of ordering, I’m just using it to identify methods within my class.</p><pre># 0 <br>class StackAsQueue<br> # 1<br>   def initialize(stack)<br>     @stack = stack<br>   end<br> <br> # 2<br>   def enqueue(item)<br>     @stack.push(item)<br>   end<br> <br> # 3<br>   def dequeue<br>     if !@stack.empty?<br>       self.recurse<br>     else <br>       return “Error, stack is empty.” <br>     end<br> end<br> <br> # 4<br>   def recurse<br>     if @stack.length == 1<br>       return @stack.pop<br>     else<br>       currVal = @stack.pop<br>       result = self.recurse<br>       @stack.push(currVal)<br>     end <br>    return result<br>   end</pre><pre>end</pre><p>At #0, I’ve defined a class called StackAsQueue and initialized an instance variable for my stack at #1. In plain English, I’m setting up my class, which is just a blueprint for making objects with similar methods (think behaviors) like a string or an array, and by initializing it with stack, I’m specifying that the program will accept a parameter, stack, when I call it. At #2 I’m defining a method to add an item to the stack, or reproduce the enqueue functionality of a queue, e.g. a new person comes into the coffee shop line and they go onto the end of the line. This method is pretty simple since I’m just adding them to the back of my array using Ruby’s .push method. At #3 I’m defining a method to dequeue, or take an element out of my queue; our person has their coffee and is ready to leave! But wait, the business logic for dequeue looks a little weird, what’s going on? First, I’m checking to make sure there is a line, e.g. I’m using Ruby’s .empty? method with the bang operator in front, which negates the statement, to ask, hey, is this array (line) empty? If the line is not empty, we’re calling our recurse method on the current object using self, otherwise we’ll return a message; we could have raised an error here. Finally, we get to #4, the recurse method. What is recursion, anyway? It simply means that a method is calling itself. Let’s ditch the coffee shop analogy for a minute and pick apart this method.</p><pre>def recurse<br> # 1<br>   if @stack.length == 1<br> # 2<br>     return @stack.pop<br>   else<br> # 3<br>     currVal = @stack.pop<br> # 4 <br>     result = self.recurse<br> # 5 <br>     @stack.push(currVal)<br>   end <br> # 6<br>   return result<br> end</pre><p>Okay, so we started with a stack, let’s say it was [1,2,3,4] where 1 was the first tray we placed on the stack and 4 was the last. If we were just thinking of stack functionality, we’d apply the .pop method and hand the hungry person waiting (or decaffeinated person depending on our analogy) tray 4, but nope, we want queue functionality, e.g. we want to hand that hungry person tray # 1.</p><p>I bet you’ve already spotted the trick to this, yep, you guessed it, you honed right in on lines 1 and 2 that say if the length of the stack is one, then hey, we’ve reached the bottom and we’re going to pop off that tray, but what else is going on?</p><p>If we look at line #3, we’re assigning a variable called currVal, which is equal to the last element on our stack, so in our case, the first time we go through that recursion, currVal will equal 4. At line #4, we’re defining a variable called result and setting it equal to self.recurse, I’ll get to that in a minute. At line #5, we’re pushing currVal back onto our stack. Wait, <strong><em>what</em></strong> are we doing? Well, we can’t just recurse through our trays (or coffees, I’m mixing analogies left and right here) and then throw them all out, we have to keep the ones that aren’t 1 (e.g. 2,3,4,5) and return the 1, the “first in”. So at line 5, after we call recurse, we’re pushing the currVal back to the stack. We keep calling recurse until the length of our stack is one, then we return that item.</p><p>So, let’s think on it some more. <br>Input:<br>@stack = [1,2,3,4]</p><p>We call the enqueue method, say to add the item “5”, here’s what our stack looks like now:</p><p>@stack = [1,2,3,4,5]</p><p>We call the dequeue method and expect to get back 1! So how does that work, exactly? We have to think about how dequeue and recurse are working together.</p><pre>def dequeue<br> # 1<br>   if !@stack.empty?<br> # 2 <br>     self.recurse<br>   else <br> # 3 <br>     return “Error, stack is empty.” <br>   end<br> end</pre><p>Dequeue is called, this is what our stack looks like:<br>@stack[1,2,3,4,5]</p><p>The length of our stack is 5 so it’s not empty, which means we call the recurse method.</p><pre>def recurse<br> # 1<br>  if @stack.length == 1<br> # 2<br>     return @stack.pop<br>  else<br> # 3<br>     currVal = @stack.pop<br> # 4 <br>     result = self.recurse<br>  # 5 <br>     @stack.push(currVal)<br>   end <br>     return result<br> end</pre><p>Our stack length is 5 starting out, so our currVal gets set to 5, and our result calls recurse again. We still have access to currVal at # 5 because it’s in the memory of our program (while it runs) as a variable so we push that back onto the stack, meanwhile our new currVal, because recurse is called again, is 4. This keeps repeating until we finally meet our condition, e.g. the length of the array is 1 and, low and behold, we return our happy customer their lunch tray #1, or latte with 3/4 sprinkle cinnamon, two puffs of foam and a unicorn on the side. But wait? What does our stack look like now?</p><p>@stack = [2,3,4,5]</p><p>If we call dequeue again, we’ll go through that same process, only this time, our stack is one item shorter.</p><p>So, what would be the run time of our new StackAsQueue class? If we had one person standing in the line for coffee, we’d have a constant runtime, O(1). Otherwise, we’d have to recurse through all those trays, or people in line, until we found the first one, so that’d be O(n) or linear run time.</p><p>Okay let’s do some testing. I did this quickly in a <a href="http://repl.it/">repl</a> for convenience, but if I were doing this in a dev context, I’d go ahead and write some RSpec tests, but here’s our tests for now, a simple print out.</p><pre>queue = StackAsQueue.new([1,2,3,4])<br>p queue.enqueue(5)<br>p queue.enqueue(6)<br>p queue.dequeue<br>p queue.dequeue<br>p queue.dequeue<br>p queue.dequeue<br>p queue.dequeue<br>p queue.dequeue<br>p queue.dequeue</pre><p>results in:</p><pre>[1, 2, 3, 4, 5] # yay, we added 5 to the queue<br>[1, 2, 3, 4, 5, 6] # oh look, we added 6 too<br># now we’ve asked it to dequeue<br>1 # woot, we got one back<br>2 # we asked it to dequeue again, we got 2 back<br>3 # we kept on calling dequeue<br>4<br>5<br>6<br>“Error, stack is empty.” # until there was nothing left</pre><p>It still feels a little odd for us, right? Why not just insert the element into the front of the stack when you add it, then shift it, but remember we’re told we are taking a stack and making it <strong>function like</strong> a queue, we’re not writing a queue class, although that’s another fun exercise. So there we have it, it’s still a brute force method to implement this class at a high level, but it’s a start.</p><p>I highly recommend this video by <a href="https://www.youtube.com/watch?v=71kEvXsEKYQ">Irfan Baqui</a> and his YouTube channel where he goes over interview questions. I learned about it today in the algorithms Meetup, I’m just saying, good things can happen when you put yourself out there.</p><p>If you have any feedback, I’d love to hear it — did I make a mistake? Please give me a shout out and help me get it right. Do you know a different way or a better way? Have you implemented this in JavaScript, Java, or another language? I’d love to hear your ideas in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f75dd95cbd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Devise with Gmail, SendGrid, Rails and Heroku: Tips to save time debugging]]></title>
            <link>https://medium.com/@cheney.shreve/using-devise-with-gmail-sendgrid-rails-and-heroku-tips-to-save-time-debugging-626546118358?source=rss-8ea386265f24------2</link>
            <guid isPermaLink="false">https://medium.com/p/626546118358</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[gmail]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Cheney Shreve]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 02:04:47 GMT</pubDate>
            <atom:updated>2018-03-29T02:04:47.774Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrpjZ-7-RnxdcNJGUl7Fzg.jpeg" /><figcaption>Photo Credit: Austin Schmid, Unsplash</figcaption></figure><p>I recently completed several backend projects as a part of the Bloc curriculum using Ruby-on-Rails version 5.1.5 and the devise gem to manage user authorization and authentication. Getting devise installed is relatively simple, there’s a great information on <a href="https://github.com/plataformatec/devise">Github</a>.</p><p>While it was fast to get devise incorporated into my app and running locally, I spent more time than I expected debugging errors when I pushed the apps into production on Heroku. Looking back, the majority of the errors I encountered were related to getting the environment variables set, however, the error logs in Heroku’s console weren’t always intuitive.</p><p>Here is a workflow that’s helped me streamline this process and avoid errors when I deploy to Heroku. I’m assuming here that you’ve already set up your rails app and GitHub repository, but that you have <strong>not yet made your first commit or push to GitHub or to Heroku</strong>.</p><blockquote><strong>No fuss environment set-up .</strong></blockquote><p>Okay, you’ve got your rails app setup, you’re in your project folder and you’ve opened up your project in your favorite text editor, I use Atom.</p><p>At a minimum, add the figaro, devise, better_errors, pg, rails_12factor gems to your GEMFILE:</p><pre>gem ‘devise’<br>gem ‘figaro’</pre><pre>group :production do<br> # Use pg as the production database for Active Record<br> gem ‘pg’, ‘~&gt; 0.20’<br> gem ‘rails_12factor’<br>end</pre><pre>group :development, :test do<br> gem ‘sqlite3’<br> gem ‘rspec-rails’, ‘~&gt; 3.7’<br> gem ‘rails-controller-testing’<br> gem ‘better_errors’<br>end</pre><p>Heroku requires PostgresSQL as the database and for Rails 5.1.5, you’ll also need the raills_12factor gem. There are lots of details on that in the <a href="https://devcenter.heroku.com/">Heroku Dev Center</a>, so I won’t go over much of that here. Figaro is great for helping you get the environment varibles set up easily. <a href="https://github.com/charliesome/better_errors">Better errors</a> is <strong>amazing</strong> for debugging when you run rails locally because it provides a full stack trace and an interactive console; this gem is a true gem! I use Rspec for Test Driven Development and I’d highly recommend it too.</p><p><strong>Still not ready to push to GitHub… </strong>Great, you’ve got your gems installed. Don’t forget to update:</p><pre>$ bundle install</pre><p><strong>Nope, don’t push yet!</strong></p><p>Open up your /config/secrets.yml and lets’ get your credentials secure.</p><ul><li>In your config directory, make a file called application.yml if there isn’t one already. Figaro gem lets you use this file to store your environment variables. We will still need our secrets.yml, but we won’t store any private information in it on Github.</li><li>open up your .gitingore file in the root directory and add /config/application.yml. Anything that goes in .gitignore <strong>will not be pushed to Github </strong>so this is where you keep any of your private credentials. You will <strong>not</strong> need to have /config/secrets.yml in .gitignore, so delete this if it is already listed in your .gitignore</li></ul><p>Before your edits, your /config/secrets.yml will look something like this, but with different keys. Copy that information as is into your /config/application.yml file for now:</p><pre>/config/secrets.yml<br>development:<br> secret_key_base: 9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb</pre><pre>test:<br> secret_key_base: 9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb</pre><pre>production:<br> secret_key_base: 9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb</pre><p>Okay, now that you’ve pasted the secret values into /config/application.yml, you can go ahead and edit your /config/secrets.yml file like so:</p><pre>/config/secrets.yml</pre><pre>development:<br> secret_key_base: &lt;%= ENV[&quot;SECRET_KEY_DEV&quot;] %&gt;</pre><pre>test:<br> secret_key_base: &lt;%= ENV[&quot;SECRET_KEY_TEST&quot;] %&gt;</pre><pre>production:<br> secret_key_base: &lt;%= ENV[&quot;SECRET_KEY_BASE&quot;] %&gt;</pre><p>Notice we’ve named our environment variables SECRET_KEY_BASE, SECRET_KEY_TEST, SECRET_KEY_DEV so we need to now go edit that in /config/application.yml.</p><pre>/config/application.yml</pre><pre>development:<br> SECRET_DEV_KEY:9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb<br> <br>test:<br> SECRET_KEY_TEST:9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb<br> <br>production:<br> SECRET_KEY_BASE: 9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb</pre><p>Okay, now <strong>double check</strong> that you have included /config/application.yml in your gitignore file! Then open up the rails console and test that your environment variables are defined properly, e.g.:</p><pre>$ rails c<br>$ p ENV[‘SECRET_DEV_KEY’]<br>$ p ENV[‘SECRET_KEY_TEST’]<br>$ p ENV[‘SECRET_KEY_BASE’]</pre><p>If you don’t see the appropriate key pop up, something’s wrong and your app will crash.</p><p>So far, we haven’t set the environment variables for SendGrid, or for Gmail, fortunately, the process is very similar. First, be aware with Gmail that you’ll need to modify your security credentials in your Gmail account to provide access to “<a href="https://support.google.com/accounts/answer/6010255?hl=en">less secure applications</a>”. I set up an account purely for development.</p><p>Next, set up your Gmail credentials.</p><pre>/config/application.yml<br>development:<br> GMAIL_USERNAME: yourusername@gmail.com<br> GMAIL_PASSWORD: your_password_goes_here<br> <br>test:<br> GMAIL_USERNAME: yourusername@gmail.com<br> GMAIL_PASSWORD: your_password_goes_here<br> <br>production:<br> GMAIL_USERNAME: yourusername@gmail.com<br> GMAIL_PASSWORD: your_password_goes_here</pre><p>If you haven’t already, you need to create your Heroku app and add the <a href="https://devcenter.heroku.com/articles/sendgrid">SendGrid </a>add-on. SendGrid is great for production because it can handle sending a bunch of emails and has a reasonable free tier. There’s a great <a href="http://rpayo.com/rails-sending-automated-emails-with-devise-and-sendgrid-on-heroku/">blog</a> on set-up here. Here’s the short version if you’re already up and running with Heroku’s command line interface in your git directory:</p><pre>$ heroku create<br>$ heroku addons:create sendgrid:starter</pre><p>Now get your SENDGRID_USERNAME and SENDGRID_PASSWORD because we’ll add those to our environment file. Your values will be different.</p><pre>$ heroku config:get SENDGRID_USERNAME<br>$ appXYZ@heroku.com</pre><pre>$ heroku config:get SENDGRID_PASSWORD<br>$ your_password</pre><p>Now we need the SendGrid API key. Go <a href="https://app.sendgrid.com/login?redirect_to=%2Fsettings%2Fapi_keys">here</a>, sign in, click create API key button in the corner, name it after your app (or something meaningful), allow default read/write permissions, copy the value. Return to your console, and set the API key in Heroku:</p><pre>heroku config:set SENDGRID_API_KEY=paste_your_API_KEY_HERE</pre><p>Okay, we’re getting there! Go back to /config/application.yml and add in your SENDGRID information. This isn’t 100% necessary since you can access it through Heroku CLI, but it’s a good mental check to remind you that you’ve done this step.</p><pre>/config/application.yml<br>development:<br> GMAIL_USERNAME: yourusername@gmail.com<br> GMAIL_PASSWORD: your_password_goes_here<br> SENDGRID_USERNAME: your_sendgrid_username_here<br> SENDGRID_PASSWORD: your_sendgrid_password_here<br> <br>test:<br> GMAIL_USERNAME: yourusername@gmail.com<br> GMAIL_PASSWORD: your_password_goes_here<br> SENDGRID_USERNAME: your_sendgrid_username_here<br> SENDGRID_PASSWORD: your_sendgrid_password_here<br> <br>production:<br> GMAIL_USERNAME: yourusername@gmail.com<br> GMAIL_PASSWORD: your_password_goes_here <br> SENDGRID_USERNAME: your_sendgrid_username_here<br> SENDGRID_PASSWORD: your_sendgrid_password_here</pre><p>We’ve made some progress, we’ve set up our environment variables, but we next need to set up /config/initializers and /config/environments.</p><h3><strong>Setting up the initializers</strong></h3><p>Open up /config/initializer/devise.rb and edit:</p><pre>/config/initializer/devise.rb</pre><pre>config.mailer_sender = ENV[‘GMAIL_USERNAME’]<br>config.reconfirmable = false # unless you are using reconfirmable!</pre><p>Now set up our /config/environments to use gmail, SendGRID, and Heroku. Note, I’m only showing the portion relevant to mail configuration here.</p><pre>/config/environments/development.rb</pre><pre># ActionMailer config<br> config.action_mailer.default_url_options = { :host =&gt; ‘localhost:3000’ }<br> config.action_mailer.perform_deliveries = true<br> config.action_mailer.delivery_method = :smtp<br> config.action_mailer.default :charset =&gt; “utf-8”<br> config.action_mailer.raise_delivery_errors = false<br> config.action_mailer.default_options = { from: “edit_your_email_here@gmail.com” }</pre><pre>config.action_mailer.smtp_settings = {<br> address: “smtp.gmail.com”,<br> port: 587,<br> authentication: “plain”,<br> enable_starttls_auto: true,<br> user_name: ENV[‘GMAIL_USERNAME’],<br> password: ENV[‘GMAIL_PASSWORD’],<br> openssl_verify_mode: ‘none’<br> }<br> config.action_mailer.perform_caching = false</pre><p>Save that and move to /config/environments/production.rb. Tip, if you don’t remember your Heroku app url, type Heroku app:info in the command line.</p><pre>/config/environments/production.rb<br> # ActionMailer Config<br>config.action_mailer.default_url_options = { :host =&gt; ‘<a href="https://edit_this_to_reflect_your_app.herokuapp.com&/#39;">https://edit_this_to_reflect_your_app.herokuapp.com&#39;</a>}</pre><pre>ActionMailer::Base.delivery_method = :smtp<br>ActionMailer::Base.smtp_settings = {<br> address: ‘smtp.sendgrid.net’,<br> port: “25”,<br> domain: ‘heroku.com’,<br> user_name: ENV[“SENDGRID_USERNAME”],<br> password: ENV[“SENDGRID_PASSWORD”],<br> authentication: ‘plain’,<br> enable_starttls_auto: true<br>}</pre><p>Okay, <strong>one more </strong>edit to /config/environments/test.rb:</p><pre>/config/environments/test.rb</pre><pre># Disable request forgery protection in test environment.<br> config.action_controller.allow_forgery_protection = false<br> config.action_mailer.perform_caching = false</pre><pre># Tell Action Mailer not to deliver emails to the real world.<br> # The :test delivery method accumulates sent emails in the<br> # ActionMailer::Base.deliveries array.<br> config.action_mailer.delivery_method = :test<br> config.action_mailer.default_url_options = { :host =&gt; ‘localhost:3000’ }<br> config.action_mailer.default_options = { from: “edit_to_reflect_your_gmail@gmail.com” }<br> config.action_mailer.smtp_settings = {<br> address: “smtp.gmail.com”,<br> port: 25,<br> authentication: “plain”,<br> enable_starttls_auto: true,<br> user_name: ENV[‘GMAIL_USERNAME’],<br> password: ENV[‘GMAIL_PASSWORD’],<br> domain: ENV[‘DOMAIN_NAME’],<br> openssl_verify_mode: ‘none’,<br> }</pre><p>We’re done with the initial set-up and you can push to GitHub, then push to Heroku, yay!</p><pre>$ git push <br>$ git push heroku master</pre><p>There’s likely more troubleshooting to do if you add features to your application via devise, e.g. if you add confirmable to users, or make other changes to your database, so be sure that you run the command below after you push to Heroku:</p><pre>$ heroku rake db:migrate </pre><p>I hope these tips help you to get set up with rails, gmail, SendGrid, and Heroku error free. I’ve collected them after several debugging experiences.</p><p>Have other tips or advice? Let me know in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=626546118358" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>