Testing User Knowledge With Flow – Part One: Laying the Groundwork


Have you ever wanted to test your users’ understanding of certain concepts?  This can easily be done with flow, but before we get into the flow, we have to talk about our business requirements and how we can accommodate this in salesforce.

The requirements the fictitious business Glorified Education made for the flow:

  1. Exams must track individual user scores.
  2. Exams must track overall pass/fail rates.
  3. Exams must allow for certain numbers of questions to be asked of users from a pool of questions.
  4. Questions must allow for one answer or multiple answers.
  5. Questions must be able to be deactivated to remove them from exams and to be maintained in historical exams.
  6. Questions must rotate order.
  7. Answers must rotate order.
  8. Exams must track individual user problem questions to suggest areas of improvement or for assessing gaps in training needs.
  9. Exams should only be visible by the individual users taking the exam, the users above that individual in the role hierarchy and the creators of the exams (system administrators).
  10. Exams must not allow retakes, must allow retakes or a certain number of retakes (to be covered at a later date.  We have enough above to cover, don’t you agree?).

The object model:

First thing’s first, the most important thing you can do in your org is to….

plan

plan

plan

before you build.  Using a tool, such as draw.io, you can make awesome documentation for your instance of salesforce or your business processes.

Before we build our data model into the org, we’re going to make an Entity-Relationship Diagram or ERD for short.  This allows you to document the relationship between salesforce objects in a meaningful way that helps you understand what’s going on and how the information relates.  For examples of salesforce’s standard object ERDs, please see this link: Salesforce ERDs.

 

exam ERD

 

Right now you might be thinking, “Wow, that’s a lot of pretty lines that mean absolutely nothing to me.”  That’s okay!

The first thing to note about an ERD is that the big boxes are entities (or objects in Salesforce terms).  These boxes could (but don’t in mine) have all of their attributes (or fields) listed.  This would allow you to see at a glance what fields are where and how you could get to them if you needed to (for example, by way of formula).  The second thing worth mentioning is that the little crow’s foot with the 0 on top of it means that it is a many relationship with it being optional.  Think of it this way, I have an object for storing jelly beans called a jar.   The jar was empty but I went to the store and filled it up.  After about 1 days time, I got gluttonous and decided to eat all of them (or delete them from the database) and now there are no more jelly beans.  That’s how an optional relationship works in an object.

However, you might also think, well exams are related to questions and questions are related to answers. How can you have one question but no answers?  Well, the answer is, you can’t!  That’s what the double bar indicates.  The relationship is mandatory to be able to have an object from the optional side exist.  In salesforce, this would be a master-detail relationship or a required lookup field.  Now that we have a lay of the overall structure, let’s talk….

 

Security:

So the first thought that might pop into your head looking at the above is that we want master-details for everything!  Well, not so fast!  Remember this requirement?

  • Exams should only be visible by the individual users taking the exam, the users above that individual in the role hierarchy and the creators of the exams (system administrators).

Let’s think about this for a second.  We wouldn’t want users to be able to see other user’s exams unless they were above them.  If they did, then that might encourage not so healthy behaviors.  For this reason, we must not make Exams with Users a master-detail. Since master-details inherit sharing from their parent object, this would mean that everyone would be ablelocks to see others’ exams and their scores.  Perhaps in some organizations, this may be acceptable, but in most, it is doubtful.

One thing that this means for the Exams objects is that we would not be able to leverage rollup summaries for passing/failing users and their scores.  Luckily there are a few tools that can be used to help with that, in the event you want to see the details at a glance on the individual record (I know I would!).  Though, you would be able to get this information in a report as well.

Check out:

The other important thing worth noting in our solution is that we are required to make answers visible to users for them to be able to reference them in flows.  So, in order to make sure that your users don’t print out all answers to the exam before they take it, make sure that Enable Reports is disabled on the object.  Additionally, make sure that the answers related list is only visible by users who should be able to see what is correct/incorrect.

 

Object Fields and Setup:

Exam:

  • Name – Auto-number
  • Display Name – Let’s be friendly to our users in flow and show them something that is reader friendly!
  • Number of Questions
    • Roll-Up Summary – COUNT of questions
  • Number of Questions To Ask
    • Remember our business requirement: Exams must allow for certain numbers of questions to be asked of users from a pool of questions.  This will allow for this in our flow.
  • Allow Retake (To be covered in a later post)
  • Number of Retakes Allowed (To be covered in a later post)

Question:

  • Name – Auto-number
  • IsActive
    • Allows for us to fulfill the requirement of deactivated questions and maintaining them for historical exams with users.
  • Number of Right Answers
    • Will allow for us to fulfill the requirement of having one or multiple answers.
  • Question Text
    • You gotta know what you’re being asked right?
  • Question Type
    • Shows the type of question being asked
    • Values: One Answer | Multiple Answer
    • This is populated automatically with a process stating that if the number of answers is greater than one, then it is a multiple answered question, otherwise it is a one answered question.
  • Random
    • This will allow for us to fulfill the requirement of making questions appear in a random order, we will use the same formula for answers.
IF(
/* Test to see if Mod = 0, and if it does, it means that we need to adjust the modulus since it may always be 0 e.x. 11, 22 for first clause */
   MOD(
     VALUE(RIGHT(Name, 5)) * DAY(TODAY()) * YEAR(TODAY()) / MONTH(TODAY())
     , 11) = 0
  , 
     MOD(
       VALUE(RIGHT(Name, 5)) * DAY(TODAY()) * YEAR(TODAY()) / MONTH(TODAY())
       , 12)
   , 
     MOD(
       VALUE(RIGHT(Name, 5)) * DAY(TODAY()) * YEAR(TODAY()) / MONTH(TODAY())
     , 11)
)

Let’s break this down, since it’s a really important and useful concept:

Since our questions and answers will be named with an auto-number, we are taking the right five digits VALUE(RIGHT(NAME,5)) and we then multiply this times today’s date, year and divide by the month.  What does that do?  This means two things:

  • The number returned will be very large.
  • The value returned will never be the same on any given day of the year.

Okay, with that, we have a very, very large number that will only increase.  So, what we do, to constrain it to a confined set of numbers is to use a modulo function.  This will divide the really large number by whatever we choose and then return the remainder.  Why did I choose 11, you might ask?  It really doesn’t matter which number I pick for the most part, as long as it will allow for the questions to rotate in relation to each other.  Take this example of three questions starting at the beginning of the month:

 

Autonumber Day 1 Day 2 Day 3
1 8 9 10
2 9 11 2
3 10 9 8

 

Questions that will appear first in order based on days:

  • First Day:  3 – 2 – 1
  • Second Day: 2 – 1 – 3
  • Third Day: 1 – 3 – 2

This isn’t random,  however, it is complex enough of a calculation that questions/answers will not appear in the same order every day in our flow.  If a user happens to reverse engineer this formula and can determine where questions and answers will be and when they will be there, without having known the formula in advance, I’d first buy him or her a drink and then say, “I want you on my team.”

 

Answers:

  • Answer Text
    • You have to have choices, right?
  • IsCorrect
    • Whether or not the answer was the right one
  • Question
    • Detail of Master-Detail to questions
  • Random
    • Same formula and concept outlined above

 

Exam With Users:

  • Exam
    • Lookup to Exam Object
  • Number of Problem Questions
    • Roll-up Summary of problem questions object
  • Score
    • Percentage of score
  • Pass/Fail
    • This is a simple formula that says if you’re over 75% you pass, under you fail, though you could do something much more complex
    • IF(Score__c > 0.75, “Pass”, “Fail”)
  • User
    • You have to know who took the exam right?

 

Lastly, Problem Questions, so we know what users are struggling with:

  • Exam With Users
    • Detail of Master-Detail to Exam With Users
  • Question
    • Detail of Master-Detail with Questions

 

That’s it!  We’ve laid the groundwork for our flow.  Please be sure to come back to see the next post on how to get the flow up and running!

Leave a comment

Your email address will not be published. Required fields are marked *