Skip to main content


Showing posts from 2018

Test.loadData on Pricebook, Product, PriceBookEntry and RecordType

I remember when I was writing test class; Pricebook and the gang (Pricebookentry, Product) always giving me headache before I able to grab the concept. I also try to experiment on how to populate test data using Test.loadData on those object and quickly gave up as I was chasing for the dateline. When I have a dateline, I always finding myself to choose familiar road although it can be slow because I know I   can choose either to walk or run instead trying other new road which I unsure whether I able to walk or run or maybe eaten by monster. *who knows*   I was once asked question here  , the answer give me a hope that Test.loadData seem possible to be try on those object. After doing some experiments, here my conclusion : 1. Define relationship with Id and the Id is not necessary all integer.  If you notice in my previous post , you will notice that I use all number to represent Id BUT it does not mean that we need to use all number. For Id, we can use alphanumeric so

Experiment : Test.loadData . Upload test data with static resources

Test.loadData  is a method that enables us to create test data by using Static Resource. This was released quite sometimes but I haven't use it intensively. I experienced using it to load data in bulk because I wanted to test governor limit. Recently we plan to use this on our project instead of using test data factory.Pushing test data using csv files are much easier compare to code insertion and define relationship. I did some simple proof of concept using code below : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 @isTest private class DataUtil { static testmethod void testLoadData () { // Load the test accounts from the static resource List<sObject> ls = Test. loadData (Account. sObjectType , 'AccountData'); // Verify that all 3 test accounts were created System. assert (ls. size () == 3 ); // Get first test account

Process Builder is not fired when field update is called from Approval Process

Scenario In Final Approvals section ; in Approval Process we have field update to update Status field. In Process Builder , we have some action that need to be done when Status field is updated in Approval Process.However this process builder is not fired. Solution To handle this, in Field Update in Approval Process , check Re-evaluated Workflow Rules after Field Change as picture below. What happen if field updated from Approval Process. Workflow - does not fires untill Re-evaluate workflow checkbox is ticked on your field update Process Builder - does not fires untill Re-evaluate workflow checkbox is ticked on your field update Trigger - will fire if conditions are matched This is explained in article here  . Field Updates That Re-evaluate Workflow Rules If  Re-evaluate Workflow Rules After Field Change  is enabled for a field update action, Salesforce  re-evaluates all workflow rules on the object if the field update results in a change to the value of the fi

What happen on Content Document Link if we upload Salesforce Files from record?

This entry specifically to know more about ContentDocumentLink which are not represented in diagram below.I happen to know more about this object after I experimenting on content's trigger(in future post). To understand how the content relationship works please refer to diagram below .  content objects diagram version 44. refer to  Salesforce  for latest diagram The highlight of this article is to identify ContentDocumentLink object that not appear in the diagram above. ContentDocumentLink is Represents the link between a Salesforce CRM Content document or Salesforce file and where it's shared. Field Label API Field Name Type Length Precision Scale ContentDocumentLink ID Id id 15 Document ContentDocumentId reference 15 Is Deleted IsDeleted boolean Linked Entity LinkedEntityId reference 15 Share Type ShareType picklist 40 System Modstamp SystemModstamp datetime Visibility Visibility picklist 40 Experiment : Upload a file from Opportunity record.Once u

Dynamic Routing Approval

Use Case  When Sales Rep submits Opportunity it requires different approver for different approval stage for different region. Solution  Create object to store approver details such for stage and region.Create Opportunity field to store approver for that particular Opportunity, these fields can be referred in Approval process. Using trigger query the approvers record and populate it in Opportunity based on specific criteria. Meanwhile you can take a look in Appexchange, there an apps named Dynamic Approval Routing. It is unmanaged package so we can view and modify the code to suit our need.The apps actually is a sample on how we can define approver for specific object.Its rule defined in the code and you might have different approver criteria and different object.The concept is to have one object to store approver details and create fields on object that going to be approved. create trigger on object that going to be approved to populate approver fields. Design struc

Dynamic SOQL with SubQuery using SObject class

Requirement to have dynamic query that enable to retrieve the child of the parent objects.For example query the Opportunities field while querying Account instead of run separate query for each object. For this post, I hard code object name and field name which actually can be done dynamically. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 String childF = 'Name'; String childO_1 = 'Opportunity'; String childF_1 = 'Name'; if (childO == 'Contact'){ childO = 'Contacts'; } if (childO_1 == 'Opportunity') { childO_1 = 'Opportunities'; } // create dynamic SOQL query string String query = 'SELECT id, (select ' +childF+ ' from ' +childO+') ,(select '+childF_1 + ' from '+childO_1+') FROM ' +parentO; // query and store results in variable p

Paused and Waiting Interviews : Salesforce warns about inactive user

We receive an email from Salesforce saying Every waiting flow interview has an associated user — the person who caused the interview to start waiting. If that user is inactive, the interviews can't resume.John Doe (005xxxxxxxxxxxx) is inactive, so please delete the following flow interviews. Without thinking too much I went straight away to the Process Builder to check if it uses hardcode Id referring to the inactive user and I found none. The process builder is fine. The email was sent is to inform us that there some process builder on the waiting list and not able to get fired because it was created by an inactive user. The user left the company for quite some time, how is possible for him to fire the process builder? What is Paused and Waiting Interview?  Paused and Waiting interview only applies on schedule action process builder or time-dependent action. You can check Paused and Waiting Interview at  Setup | Create | Workflows & Approvals | Flows and

Showing and hiding the tab in Salesforce Lightning Design System in Visualforce page using basic javascript

I am not yet familiar with Salesforce Lightning Design System (SLDS) however I need to start it somewhere.There some requirement come in and it does not have specification on what the UI look likes so I thought why not give SLDS a try. Before SLDS comes into picture, I experienced using Bootstrap and JQuery. It's simple and easy to use however because it is external javascript library it need to have extra precautions.Sometimes we got issue when the css is conflict. Still after SLDS , developer need to code javascript in order to enhance user experience for example changing the tab, make the inactive button visible after click as SLDS does not have code for that.It only provide you the CSS how active and disable button looks like.I notice in some demo they use React JS or JQuery. I love it because it's neat and elegant but I found it hard to customize the theme if our organization has different color scheme from Salesforce. It can be customized using Design Token using S

Trapped in Process fails with error 'The flow failed to access the value because it hasn't been set or assigned' WHILE IT IS NOT

If you have no idea about Known Issue : Process fails with error 'The flow failed to access the value because it hasn't been set or assigned ' , it's worth to check it first then you might want to read this entry. Issue : The user reports that when using Mass Edit to edit Opportunity it will prompt error Can't Save Record That's it. No sweet lovely sentence, no flowery and it's leave the mystery for us to dig out the root cause.Typical communication breakdown in love story. Luckily we have email system whereby we got chance to get the exception email straight in our inbox.Here the error : Error element myDecision (FlowDecision). The flow failed to access the value for myVariable_current.Owner.UserRole.DeveloperName because it hasn't been set or assigned. Just to clarify , yes we use process builder and we are aware of issue above whereby we need to put condition checking in proper order whenever our condition need to check value from

Pricebook, Pricebook Entry and Product : Adding custom pricebook in Salesforce

Lately I worked on these object a lot and learned a lot of new things. Some issues that we face around these object : Some exceptions during data upload  such as : FIELD_INTEGRITY_EXCEPTION .Message : field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id) No Standard Price defined Not able to retrieve standard price in test class Understand the relationship of these object Ignore Opportunity and Opportunity Line Item- these two object are using Price Book entry .Image credit to ForceTalk forum PriceBook Pricebook object store a list of products and services for sale. A pricebook can be used in one or more different opportunities. A pricebook has one or more different price entries. Pricebook can be divided into type which are :  Standard Price Book which is the master list of all the products and their default standard price . Custom Price Book is separate list

Add Fault Connector in Salesforce Flow Autolaunch

Fault Connector is very useful because now we able to handle the error. We can trace who perform the transaction and what record that cause the error. The connector is indicated with FAULT like image below. In some occasion you might face into issue that Fault Connector is not working like below : Here is the hack. We need to add another element after it because for unknown reason Fault Connector will not appear in the last element . So we need to create another element temporarily like below. Tips : Use Copy and Paste button to copy from existing element so you don't have create dummy element from start. Now we can add Fault Connector to the element that we want to.As you can see in the image below, when we drag the connector 'Fault' label appear. Now we can delete the dummy element. That's it. Now it should works. More about Flow can be refer to  here  . Have a nice day.