{"id":5322,"date":"2016-02-15T04:20:02","date_gmt":"2016-02-15T04:20:02","guid":{"rendered":"http:\/\/www.jitendrazaa.com\/blog\/?p=5322"},"modified":"2016-02-15T04:33:43","modified_gmt":"2016-02-15T04:33:43","slug":"storing-secrets-or-passwords-in-salesforce-video","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/storing-secrets-or-passwords-in-salesforce-video\/","title":{"rendered":"Storing secrets or passwords using manage package in Salesforce &#8211; Video"},"content":{"rendered":"<p style=\"text-align: justify;\">Salesforce supports\u00a0<strong>Encrypted Field\u00a0<\/strong>out of the box on standard or custom objects. However, users with appropriate profile or permission set can easily view content of those fields. If we want to store secure information like passwords (of external systems), then there is no direct way to achieve this. If we think about passwords, no one should be able to view it. If we forget password, then instead of system sending old password, it forces us to reset it.<\/p>\n<p style=\"text-align: justify;\">We will create same behaviour in Salesforce where stored password cannot be viewed by anyone.<\/p>\n<figure id=\"attachment_5325\" aria-describedby=\"caption-attachment-5325\" style=\"width: 684px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Storing-Passwords-in-Salesforce.png?ssl=1\" rel=\"attachment wp-att-5325\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5325\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Storing-Passwords-in-Salesforce.png?resize=684%2C518&#038;ssl=1\" alt=\"Storing Passwords in Salesforce\" width=\"684\" height=\"518\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Storing-Passwords-in-Salesforce.png?w=684&amp;ssl=1 684w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Storing-Passwords-in-Salesforce.png?resize=300%2C227&amp;ssl=1 300w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/a><figcaption id=\"caption-attachment-5325\" class=\"wp-caption-text\">Storing Passwords in Salesforce<\/figcaption><\/figure>\n<p style=\"text-align: justify;\"><!--more-->We will need a developer org with any namespace. In my case, namespace is &#8220;Livecoding&#8221;. Namespace can be created from &#8220;Setup | Build | Create | Packages | Developer Settings | Edit&#8221;. We need namespace so that\u00a0<strong>manage package<\/strong> can be created. Idea is to have a\u00a0<strong>protected custom setting. <\/strong>Protected custom setting can only be accessed in manage package and we will create\u00a0<strong>global class,\u00a0<\/strong>which can be used in subscriber (Client) org to perform various operations related to storing and getting passwords.<\/p>\n<p style=\"text-align: justify;\">I have created custom setting by name &#8220;Livecoding__secrets__c&#8221; (Livecoding is namespace added by default in API name). Field of type text is created to store password by name &#8220;Livecoding__Password__c&#8221;.<\/p>\n<p style=\"text-align: justify;\">To perform various operations, below global class is created with three methods:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/**\r\n * \t@Author\t\t\t:\tJitendra Zaa\r\n * \t@Date\t\t\t:\t13-Feb-2016\r\n * \t@Description\t:\tVarious operations to be performed on passwords\t\r\n * \r\n * *\/\r\nglobal class Operations {\r\n    \r\n    \/**\r\n     * To store username and secret, use this method\r\n     * *\/\r\n    global static void addSecrets(String username, String password){\r\n        \r\n        Livecoding__Secrets__c obj = new Livecoding__Secrets__c(name = username, Livecoding__Password__c= password);\r\n        insert obj;\r\n    }\r\n\r\n\t\/**\r\n\t * This method checks if password entered is correct or not \r\n\t * *\/    \r\n    global static boolean isPasswordCorrect(String username, String password)\r\n    { \r\n        \/\/read custom setting using SOQL\r\n        List&lt;Livecoding__Secrets__c&gt; lstRecords = &#x5B;SELECT ID FROM Livecoding__Secrets__c WHERE Name = :username AND  Livecoding__Password__c =: password ];\r\n        \r\n        if(lstRecords.isEmpty())\r\n        {\r\n            return false;\r\n        }\r\n        return true;\r\n    }\r\n    \r\n    \/**\r\n     * Reset password of existing user \r\n     * *\/\r\n    global static boolean resetPassword(String username, String password){\r\n        \r\n        \/\/read custom setting without SOQL\r\n        Livecoding__Secrets__c userRecord = Livecoding__Secrets__c.getValues(username);\r\n         \r\n        if(userRecord == null)\r\n        {\r\n            return false;\r\n        }\r\n        \r\n        userRecord.Livecoding__Password__c = password ;\r\n        update userRecord; \r\n        \r\n        return true;\r\n    } \r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">To create manage package, we must need to have minimum 75% of test coverage. Below test class gives 100% test coverage to our manage package.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/**\r\n * \t@Author\t\t\t:\tJitendra Zaa\r\n * \t@Date\t\t\t:\t13-Feb-2016\r\n * \t@Description\t:\tTest class for &quot;Operations&quot;\r\n * *\/\r\n\r\n@isTest\r\npublic class OperationsTest {\r\n\t\r\n    \r\n    @testSetup \r\n    static void setupCustomSetting() {\r\n        Livecoding__Secrets__c obj = new Livecoding__Secrets__c(name = 'abc@livecoding.tv', Livecoding__Password__c= 'sample1');\r\n        insert obj;\r\n\t}\r\n    \r\n    \r\n    static testMethod void addSecrets_Test(){\r\n        Operations.addSecrets('xyz@livecoding.tv','xyz');\r\n        \r\n        List&lt;Livecoding__Secrets__c&gt; lstCustomSettings = Livecoding__Secrets__c.getAll().values();\r\n        System.assertEquals(lstCustomSettings.size(), 2);  \r\n    }\r\n    \r\n    static testMethod void isPasswordCorrect_No_Test(){\r\n        boolean retValue = Operations.isPasswordCorrect('abc@livecoding.tv', 'password') ;\r\n        System.assertNotEquals(retValue, true) ;        \r\n    }\r\n    \r\n    static testMethod void isPasswordCorrect_Yes_Test(){\r\n        boolean retValue = Operations.isPasswordCorrect('abc@livecoding.tv', 'sample1') ;\r\n        System.assertEquals(retValue, true) ;        \r\n    }\r\n    \r\n    static testMethod void resetPassword_No_Test(){\r\n        boolean retValue = Operations.resetPassword('abc@livecoding.com', 'password') ;\r\n        System.assertEquals(retValue, false) ;  \r\n    }\r\n    \r\n    static testMethod void resetPassword_Yes_Test(){\r\n        boolean retValue = Operations.resetPassword('abc@livecoding.tv', 'password') ;\r\n        System.assertEquals(retValue, true) ;  \r\n        \r\n        retValue = Operations.isPasswordCorrect('abc@livecoding.tv', 'password') ;\r\n        System.assertEquals(retValue, true) ;    \r\n    }    \r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">In above test class, we have used\u00a0<strong>@testSetup<\/strong> method. It is used to create a common test records being used by all\u00a0<strong>testmethod<\/strong>. This method is implicitly called before each testmethod in class.<\/p>\n<p style=\"text-align: justify;\">It&#8217;s time to create\u00a0<strong>Manage package<\/strong> now. Navigate to &#8220;Setup | Build | Packages | New&#8221;. This manage package will have below three components<\/p>\n<ol>\n<li>Protected public setting<\/li>\n<li>Global Apex class to perform operations on Custom Setting<\/li>\n<li>Test class for Apex to cover minimum 75%<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">If we need to store password in any org, we can install above manage package in that\u00a0org.\u00a0To perform operations related to password, we can use any of three global methods available in manage package.<\/p>\n<p><strong>Other resources:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/login.salesforce.com\/packaging\/installPackage.apexp?p0=04to0000000Wp7r\">Manage package (discussed in this post) to install in client org<\/a><\/li>\n<li><a href=\"https:\/\/www.livecoding.tv\/video\/how-to-store-secrets-in-salesforce-2\/\">Livecoding video<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Designing application to store passwords or secrets in Salesforce using Manage packages<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[362,143],"class_list":["post-5322","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-live-coding","tag-manage-package"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2892,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-migration-tool-ant\/","url_meta":{"origin":5322,"position":0},"title":"Complete Salesforce Deployment Guide using Ant Migration Tool","author":"Jitendra","date":"June 5, 2012","format":false,"excerpt":"Step by Step tutorial of Salesforce Migration using ANT tool with Proxy settings and retrieving content from Salesforce Organization. Also fix some common errors like java.lang.OutOfMemoryError or unable to find tools.jar","rel":"","context":"In &quot;Configuration&quot;","block_context":{"text":"Configuration","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/configuration\/"},"img":{"alt_text":"Salesforce Get ANT version ","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/06\/Salesforce-Get-ANT-version-Original.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/06\/Salesforce-Get-ANT-version-Original.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/06\/Salesforce-Get-ANT-version-Original.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":4276,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/continuous-integration-in-salesforce-using-jenkins-and-git-video-tutorial\/","url_meta":{"origin":5322,"position":1},"title":"Continuous integration in Salesforce Using Jenkins and Git | Video Tutorial","author":"Jitendra","date":"March 23, 2015","format":false,"excerpt":"As your Salesforce Organization undergoes heavy customization and frequent builds, moving changes from one Sandbox to other sandboxes starts taking longer time and effort. Also, in normal Salesforce project, there are chances that you will have minimum three sandboxes likely Developer Sandbox, QA Sandbox and UAT Sandbox. After some time\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce - Jenkins Git Polling Log","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4559,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/top-google-chrome-extensions-for-salesforce\/","url_meta":{"origin":5322,"position":2},"title":"Top Google chrome extensions for Salesforce","author":"Jitendra","date":"June 12, 2015","format":false,"excerpt":"Checkout if your favorite Google Chrome extension made it in Top extensions for Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Dev tools - Chrome Extension","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Devtools-Chrome-Extension.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Devtools-Chrome-Extension.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/06\/Salesforce-Devtools-Chrome-Extension.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":5562,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/summer-16-top-features\/","url_meta":{"origin":5322,"position":3},"title":"Salesforce Summer 16 &#8211; My favorite top 20 features","author":"Jitendra","date":"June 28, 2016","format":false,"excerpt":"List of Salesforce Summer 16 features","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"User Switcher in Salesforce Summer 16","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/06\/User-Switcher-in-Salesforce-Summer-16.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":7127,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/solve-for-common-errors-in-unlocked-packages\/","url_meta":{"origin":5322,"position":4},"title":"Solve for Common Errors in Unlocked Packages","author":"Jitendra","date":"June 29, 2020","format":false,"excerpt":"How to solve most frequent and common errors in unlocked packages","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3192,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/how-to-debug-manage-package-in-salesforce\/","url_meta":{"origin":5322,"position":5},"title":"How to Debug Manage Package in Salesforce","author":"Jitendra","date":"February 6, 2013","format":false,"excerpt":"Many times as a developer we need to debug the manage package for possible run time error. For example , while uploading contacts using Import wizard we get \"Internal Server Error\"\u009d and when we try to look into debug log there is no clear indications. However in my experience i\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Debug Manage Package in Salesforce Using Developer Console","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/02\/Debug-Manage-Package.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/02\/Debug-Manage-Package.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/02\/Debug-Manage-Package.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=5322"}],"version-history":[{"count":8,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5322\/revisions"}],"predecessor-version":[{"id":5331,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5322\/revisions\/5331"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=5322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=5322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=5322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}