javaniceday.com

  • Home
  • AboutAbout me
  • Subscribe
  • SalesforceSalesforce related content
  • Node JSNodejs related content
  • JavaJava related content
  • Electric Vehicles
  • Autos Eléctricos
  • Estaciones de carga UTE
  • Mapa cargadores autos eléctricos en Uruguay
  • Salesforce CLI – SFDX – Cannot read properties of undefined (reading ‘id’)

    July 6th, 2022
    When running the command that makes the login against our Sandbox org, it redirects to a localhost URL and then it display an error that doesn’t give us so much information
          sfdx auth:web:login -a myuser@abc.com --instanceurl=https://xxxxx--xxxxx.my.salesforce.com
        

    The error

    Cannot read properties of undefined (reading ‘id’)
    This is most likely not an error with the Salesforce CLI. Please ensure all information is accurate and try again.
    This error can be related to the enhanced domain enabled or just the wrong URL typed in the login command. Read more about
    Enhanced Domain enabled https://help.salesforce.com/s/articleView?id=sf.domain_name_enhanced_enable.htm&type=5

    Solution

    To fix this error, add just “sandbox” to the URL so the pattern must be “xxxxxx–xxxx.sandbox.my.salesforce.com”

          sfdx auth:web:login -a myuser@abc.com --instanceurl=https://xxxxxx--xxxx.sandbox.my.salesforce.com
        
    Source: https://github.com/forcedotcom/cli/issues/1588
    Photo by Markus Spiske on Unsplash

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • How to delay an execution in Salesforce Apex

    June 19th, 2022

    Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Salesforce platform. It was developed by Salesforce and runs natively on their platform. Apex can be used to create custom business logic, automate processes and workflows, and integrate with external systems.

    In short, Apex is a programming language for Salesforce that enables developers to build custom applications, automate business processes, and perform other tasks not possible with just point-and-click tools. It can be used to build custom triggers, classes, and interfaces to perform various functions on the Salesforce platform.

    In Java, we can use Thread.sleep(1000) to delay the execution by one second. In Apex is not that easy since Salesforce is a multi-tenant environment. By Delaying the execution in the main thread we not only impact the users of our organization but also other Salesforce customers 🤯. That’s why we don’t have that sentence in Apex.


    In a multi-tenancy environment, multiple customers share the same application, running on the same operating system, on the same hardware, and with the same data-storage mechanism. The distinction between the customers is achieved during application design, thus customers do not share or see each other’s data.

    With some tricks, we can delay the execution without impacting our organization’s resources. Salesforce provides one mechanism to schedule an algorithm for one time or in a recurrent manner.

    global class MyScheduler implements Schedulable {
        
        private final Id recordId;
        
        public MyScheduler(Id recordId){
            this.recordId = recordId;
        }
        
        global void execute(SchedulableContext sc){
            System.debug('**** recordId: '+this.recordId+'   date: '+Date.today());
    
            // ****** Do your logic here ******
    
            // abort to execute it only once
            System.abortJob(sc.getTriggerId()); 
        }
        
        public static void schedule(){
            String hour = String.valueOf(Datetime.now().hour());
            String min = String.valueOf(Datetime.now().minute() + 1); 
            String ss = String.valueOf(Datetime.now().second());
            
            //parse to cron expression
            String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';
            
            MyScheduler sc = new MyScheduler('0018F00000ABA3AQBX');
            
            String name = 'Submited at: '+String.valueOf(Datetime.now())+ ' next: '+nextFireTime;
            System.debug(name);
    
            System.schedule(name, nextFireTime, sc);
            
        }
    }

    How to use it

    MyScheduler.schedule();

    Related posts

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • Webstorm does not have write access to /applications/webstorm.app/contents

    March 26th, 2022

    Open a terminal and just execute:

    sudo chmod -R 775 /Applications/WebStorm.app/Contents

    Close the window and check for updates again. The error should disappear and you should be able to update Webstorm

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • First-time shipped implementation is like going into technical debt

    February 22nd, 2022

    As a starting point, we can say roughly that technical debt is all those decisions we make during software development that narrow down our capacity as a team to create new features that add value to the business.

    In the same way we say every printed document is automatically obsolete we can say that first-time shipped implementation is like going into technical debt

    Technical debt is often asymptomatic, making it difficult to prioritize, but once the symptoms appear, it may be too late and the associated costs may be much higher.

    Table of contents

    • Sort of technical debt
    • What about the good technical debt?
    • What are the consequences of technical debt?
    • Are defects technical debt?
    • Is the development environment configuration technical debt?
    • Technical debt and product management
    • How much technical debt do I have?
    • How to estimate the impact of technical debt
    • Final thoughts

    Sort of technical debt

    I’m sure the following list is familiar for you. Don’t worry, you are not alone.

    • Known tolerable bugs
    • Bad user experience
    • Tolerable security issues
    • Obsolete release process
    • Missing automated backups
    • Missing or bad configured alerts
    • Performance issues
    • Legacy systems
    • Unreadable code
    • Missing or poor automated tests
    • Outdated documentation (if any)

    And likely there are much more, even different flavors of the same item

    What about the good technical debt?

    Not all is negative when we talk about technical debt, there is also good technical debt. Think for example when you borrow some money to achieve a goal such as buying a car.
    In software development, we are all experts on “borrowing money”. Our problem comes when we accumulate technical debt in the same way we accumulate money debt in our life.

    Let’s say then that we want to deliver something quick to close a deal or tolerate bad performance because the hardware is cheap. For a couple of months that can be good technical debt but if we scale and we do not start over again, that will be the bad one

    What are the consequences of technical debt?

    People don’t want to work with spaghetti code or in a project that is not well organized. So a big consequence is team rotation which comes with more frequent onboarding periods which generates low team productivity. Also, these kinds of projects make people think they are not adding value to their own careers and feel stuck all the time which makes them feel unmotivated.

    Delayed delivery. Every new feature will be delayed because of technical debt due to our time will be consumed on troubleshooting existing issues or because of a poor release process. Instead of making analysis or coding, our team is dedicated to resolving that performance issue that is making our users stop using our product

    User experience is everywhere. Technical debt related to the poor user experience could cause a gradual decline in the use of our product by users.

    Are defects technical debt?

    The short answer is: it depends. Let’s say users are unable to make payments or unable to add products to the shopping cart. That’s a huge bug and cannot be considered debt because your business depends on it.
    On the other hand, if the shopping cart has a button whose style does not 100% respect the company’s branding, that is something that could be considered technical debt. Unless the button’s color represents the branding of our competitor 🙂

    An example where seems to be a gray area and needs to be addressed

    While most will agree that known, unaddressed vulnerabilities are a type of technical debt, it is questionable if a newly discovered vulnerability is also technical debt. The key here is whether the security risk needs to be addressed and, for that answer, we can look at an organization’s service level agreements (SLAs) for vulnerability management. If an organization sets an SLA that requires all high-level vulnerabilities to be addressed within one day, then we can say that high vulnerabilities older than that day are debt.

    Measuring Technical Debt

    Is the development environment configuration technical debt?

    Yes it is!
    It doesn’t affect directly business but it affects new team members’ ramp up or existing members’ reconfiguration for example when a computer has broken. We should have a clear guide about development environment configuration. It must describe all the steps necessary to start adding new code and test it locally. Also, the development environment shouldn’t so complex, It cannot take an entire day to get up and running

    These kind of things should be described in your guide (ideally the default readme file in your repo)

    • Necessary software pre-installed needed such as JRE, Node.js, etc
    • Recommended IDE(s) the team uses. I know this should be agnostic but the team can collaborate better
    • Environment variables o be set. There are some default and non sensitive variables that can be share in the repo. For the sensitive ones please provide direction (a contact, a team role) about how to get them
    • Docker configuration if the useam uses it

    Technical debt and product management

    One of the most difficult things as software engineers is to argue about technical debt. Many times the arguments are made more difficult when there are conflicts between the development team and the product manager. Mistrust between work teams is always the enemy of any valid argument

    The following exchange should be familiar. The product manager describes the next feature they want to be added to the product. Developers give a high estimate for the time it takes to implement, which is seen as too long. The developers talk about having to deal with the implications of making changes to lots of hard-to-understand code or working around bugs in old libraries or frameworks. Then the developers ask for time to address these problems, and the product manager declines, referring to the big backlog of desired features that need to be implemented first.

    Managing Technical Debt in a Microservice Architecture

    Provide context and be sincere about why we arrived at this point is the best bet to get that time you need to fix or improve that annoying piece of code.

    Most persons involved with software development have faced difficulties trying to get product or project managers to agree to let them spend time fixing their project’s technical debt.

    Managing Technical Debt in a Microservice Architecture

    How much technical debt do I have?

    Adding new functionality in a product with little technical debt as in a product with several development sprints and a lot of accumulated technical debt.

    Here is where a good bunch of tests can save us from headaches. Unit tests with good code coverage and integration tests are the minimum to increase chances of success, otherwise adding new code will become harder and harder.

    Knowing how much technical debt you have will allow you to think better about the impact of adding new features and new members in case of delivery delays. But remember that 9 Women Can’t Make a Baby in a Month. Sometimes adding new members is not the best decision.

    How to estimate the impact of technical debt

    If adding a new feature in a context of huge technical debt, imagine how hard can be to reproduce and fix a bug. That’s why is important to know how much time and money we spend on tasks related to a specific technical debt.

    Estimation is not an easy tasks but at least we can narrow down our cost to have an idea. Here we have some clues:

    (…) we can therefore calculate the cost for this type of debt relatively easily by looking at the cost of support activities related to the issue and adding that to the impact on productivity for the development of new code. The cost of the debt can also be easily calculated by looking at the time and resources required to fix the problem.

    Measuring Technical Debt

    As an estimate, let’s say this work would cost $10,000 to mitigate. Comparatively, due to the issue, the entire team, incident management and operations center took one to two hours per week remediating the impact. Let’s estimate this cost at $2,000/week. Based on this high-level analysis, it is clear that the ROI for fixing this defect would be realized five weeks after fixing the bug.

    Measuring Technical Debt

    Final thoughts

    A project can fail for many reasons: miscommunication, lack of expertise, bad business decisions, poor management, unclear scope, etc. Technical debt is an ingredient that, combined with others, can help things go wrong in the long run. It is like the excess of sugar or salt for our body, we can live with them for a while but if we do not control them in time, the consequences could be terrible.

    If you are from the dev team, try to always have the technical debt under your radar and under control. Try to avoid vague implementations that can become quickly in technical debt. Communication is the best tool to tackle it on time.

    If you are someone from product, you should know that technical debt is something impossible to avoid because that’s the nature of software development, mixed with business decisions and sometimes with something crueler: time to market.

    Resources

    • Measuring Technical Debt
    • Managing Technical Debt in a Microservice Architecture

    Feature photo by Alice Pasqual on Unsplash

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • AWS AppFlow error conflict executing request connector profile is associated with one or more flows

    February 14th, 2022
    AWS AppFlow is a fully managed cloud integration solution for moving data between SaaS applications. It enables customers to model and configure flows to synchronize data between applications with just a few clicks. When setting up a flow, customers may encounter an error that says “conflict executing request connector profile is associated with one or more flows”.

    This error occurs when a connector profile used in a flow is associated to one or more other flows either in the same or another account. While the dependability of the flow connector

    Let’s say you have a Salesforce connector (it is valid for any other available) and the token expired. The only way so far is to delete and recreate the connection again. Would be nice to keep the same connection and run the handshake again but it is impossible nowadays.

    If we try to delete a connector from the AWS console and it is associated with one or many flows, it will display this error:

    Conflict executing request: Connector profile: xxxxxxx is associated with one or more flows. If you still want to delete it, then make delete request with forceDelete flag as true. Some of the associated flows are: [xxxxx, xxxxxx]

    The trick is to delete the connector from AWS CLI thus:

    aws appflow delete-connector-profile --connector-profile-name xxxxxxx --force-delete

    After that you will be able to recreate the connection again

    More useful AWS CLI commands for AppFlow

    aws appflow describe-flow --flow-name xxxxxx
    aws appflow list-flows
    aws appflow describe-connectors --connector-types Salesforce

    Resources

    • AppFlow CLI docs

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • AWS suspended error AppFlow

    February 11th, 2022

    If you’re an AWS user, you’ve likely encountered the dreaded “AWS suspended error” in AppFlow at some point. This error can result from various issues, but if you are using a Salesforce connector, it can be due to the Salesforce daily limit being exceeded. So you consumed all your daily API requests for the day.

    You’re not alone if you’ve experienced this error. Many AWS users encounter this message while trying to retrieve data or update resources. So, what can you do if you run into this error?


    AWS AppFlow suspended status error is sown for many reasons. You have to click on the Suspended word in the AWS console to see the extended error. Another option is to see it through the CLI

    The error

    This is an example error you could get:

    The flow has been suspended due to an error in Salesforce when subscribing to the event. Here's the detailed error message: The request failed because the service Salesforce returned the following error: Details: Subscribing to topic /data/xxxxxxxx__ChangeEvent with replayId -1 failed due to com.amazon.sandstonebridge.connector.exception.ClientSubscriptionException: Cannot subscribe to topic /data/xxxxxxxxx__ChangeEvent, replay from -1, with error 403::Organization total events daily limit exceeded (Service: null; Status Code: 400; Error Code: Client; Request ID: xxxxxxxxxx; Proxy: null).

    And this is the main reason:

    Organization total events daily limit exceeded

    How to fix it the Salesforce daily limit exceeded error

    Option 1

    Just wait a couple of hours and reactivate the flow again. The main reason is Organization total events daily limit exceeded which means we reached our Salesforce daily limit for events

    Option 2

    Another option is to increase that limit (through Salesforce support) but that will depend on many reasons. However, you should find the root cause, especially if that limit exceeded doesn’t make sense with your Salesforce implementation.

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • MIXED_DML_OPERATION error and Apex unit tests (how to fix it)

    February 9th, 2022

    This is a common error when we start to work with testing or manipulating some particular objects: setup and non-setup objects. During test setup, we have to create some data to be used by the test because we don’t have access to the real org’s data unless we use the flag
    SeeAllData=True
    which is not recommended.

    Table of contents

    • The error
    • The solution
    • The full example
    • Resources

    The error

    Let’s say you want to create an Account and later a User. If you try to do it in the same transaction you will get this error (or similar):

    System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Account, original object: PermissionSetAssignment: []

    Why?

    The Salesforce documentation is pretty clear and basically, it says you cannot do a DML (insert or update) operation at the same time with objects that involve access-lever permissions

    DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction.

    Salesforce Documentation

    sObjects That Cannot Be Used Together in DML Operations

    The solution

    Let’s see how to fix the MIXED_DML_OPERATION error

    One option is to use @future method but since that’s for running in background, we cannot query that data in the next line due to it could be created or not.

    Another solution is to insert setup objects such as User using the current user during the execution. We choose this one since we can access the user later in the test

          
    System.runAs(new User(Id = UserInfo.getUserId())){ createUser(); }
       
        

    The full example

          
    
      @isTest
      public class TestTest {
    
      @isTest static void itDoesNotWork() {
      createUser();
      createAccount();
      }
    
      @isTest static void itWorks() {
      System.runAs(new User(Id = UserInfo.getUserId())){ createUser(); }
      User user = [SELECT Id FROM User WHERE UserName LIKE 'admin%' LIMIT 1];
      createAccount();
    
      }
    
      private static void createAccount(){
      String random = String.valueof(DateTime.now().getTime());
    
      Account acc = new Account(Name = random);
      acc.CurrencyIsoCode = 'USD';
      acc.BillingCity = 'New York';
      acc.BillingCountry = 'United States';
      acc.BillingState = 'New York';
      acc.BillingStreet = 'abc 1234';
      acc.Website = 'www.google.com';
    
      insert ACC;
    
      }
    
      private static void createUser(){
      String random = String.valueof(DateTime.now().getTime());
    
      Profile profile = [SELECT Id FROM Profile WHERE Name='System Administrator'];
    
      User user = new User();
      user.Email = 'random@random.com'+random;
      user.UserName = 'admin@random.com'+random;
      user.LastName = 'random'+random;
      user.Alias = 'random';
      user.ProfileId = profile.Id;
      user.EmailEncodingKey='UTF-8';
      user.LanguageLocaleKey='en_US';
      user.LocaleSidKey='en_US';
      user.TimeZoneSidKey = 'America/Los_Angeles';
    
      insert user;
      }
      }
    
      
      

    As you can see, the first test failed and the second one worked (the one running as the current user)

    Resources

    • https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm
    • https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_seealldata_using.htm

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • Dark Reader: A Chrome plugin to enable dark mode

    February 5th, 2022

    What is it

    Dark Reader is a Chrome plugin to start seeing instantly all the web pages in dark mode. It works pretty well with most of the sites

    Chrome Store
    The plugin can be disabled at any time in case the web page your visiting doesn’t look good with the plugin’s dark mode
    Dark Reader options

    How it works

    As a user, you just navigate and the plugin changes for you the theme automatically.

    Here you can see some examples where you can see how the web page looks like originally and how it looks like with the plugin enabled
    Before
    The Wall Street Journal with original theme
    After

    Before

    After

    However, Salesforce doesn’t work so well. Probably there will be more sites that behave in the same way.


    How to install it

    It can be installed as any other Google Chrom plugin. Go to

    https://chrome.google.com/webstore/detail/dark-reader/eimadpbcbfnmbkopoojfekhnkhdbieeh/related?hl=en

    Photo by Breno Machado on Unsplash

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • Get Record Type id by name in Apex – Salesforce

    January 25th, 2022

    Based on this query we are going to build a method that gets the record type id by its name

          
    SELECT Id, Name, DeveloperName FROM RecordType WHERE SobjectType= 'Opportunity'
          
        

    The method

          
     static Id getRecordTypeIdByName(String sobjectType, String recordTypeName){
            RecordType rt =  [SELECT Id FROM RecordType WHERE SobjectType= :sobjectType AND DeveloperName = :recordTypeName LIMIT 1];
            return rt.Id;
        }
          
        

    How to use it

          
    Id recordTypeId = getRecordTypeIdByName('Opportunity', 'My Record Type');
          
        
    Photo by Bruno Martins on Unsplash

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
  • Salesforce inspector: a Salesforce data explorer and exporter

    January 20th, 2022

    Salesforce Inspector is a powerful Salesforce data explorer and exporter designed to help Salesforce admins and developers quickly explore and export Salesforce data. This easy-to-use data exploration and export tool gives you the power to gain insights from your Salesforce data that cannot be found in the standard Salesforce reporting interface.

    Using Salesforce Inspector, you can quickly connect to your Salesforce org and explore any object within it. 

    It is a productivity tool for Salesforce administrators and developers to inspect data and metadata directly from the browser without compromising security and privacy. It’s an extension available for Chrome and Firefox that leverages the Salesforce session from the browser to make its own request to the org to run SOQL queries and import data. I specifically use it for running queries and exploring fields since when you start typing, it suggests you Objects and Fields

    More info at https://github.com/sorenkrabbe/Chrome-Salesforce-inspector

    How to install Salesforce inspector plugin

    Install it like any other Chrome or Firefox extension, here you have two shortcuts:

    Add to Chrome

    Add to Firefox

    After installing it, you have to access your org as you usually do. You will see the plugin´s icon at the left of your screen once you step in your Salesforce’s org browser tab. This icon will be available only when you step into the org’s browser tab. Click on Data Export to start running SOQL queries

    Share this:

    • Click to share on X (Opens in new window) X
    • Click to share on LinkedIn (Opens in new window) LinkedIn
    • Click to share on Reddit (Opens in new window) Reddit
    • Click to email a link to a friend (Opens in new window) Email
    Like Loading…
←Previous Page
1 … 10 11 12 13 14 … 25
Next Page→

  • LinkedIn
  • GitHub
  • WordPress

Privacy PolicyTerms of Use

Website Powered by WordPress.com.

  • Subscribe Subscribed
    • javaniceday.com
    • Already have a WordPress.com account? Log in now.
    • javaniceday.com
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d