Custom Settings Fun
Custom Settings are one of the great ways a developer can give admins power to update logic, settings, and the behaviour of code and really make code more flexible.
This is just a quick reference of all the cool ways you can pull those settings back out without having to use a SOQL statement.
This method loads all of the custom settings in to a list:
list<Customer_Setting_Name__c> buList =Customer_Setting_Name__c.getall().values();
This method loads a record using the name as a filter. This of course assumes you are not loading duplicate names:
Customer_Setting_Name__c aplo =Customer_Setting_Name__c.getValues(filter_string); // filter_string is just a string passed in
And finally, this method loads all of the custom settings in to a map with the name as the key:
Map<String,Customer_Setting_Name__c> buMap =Customer_Setting_Name__c.getAll();
The great thing is that these do not take a SOQL hit and admin can update these.
Some of the uses I use this for:
- Mapping Business Unit settings for Lead Queue's, record types, groups, etc.
- Multi-dimensional Pick lists that need to shared across objects, enabled/disabled (Global Picklists have taken the place of a lot of these), and that require additional attributes but maybe don't warrant the need for a full custom object IE security.
- For 'quick disable' functionality for when I want to put code in production that might need to be quickly disabled
Test Classes with Global Picklists
Global Picklists or as Salesforce.com likes to refer to them, "Picklist Value Sets" from the menu or "Global Value Sets" in change sets, are not new but my dealings with them are. Specifically in Apex and test classes with a parent/child relationship using Global Picklists.
Global picklists btw do not have the same limitations normal picklists have in terms of the 1,000 character limitation that previous you had to use record types or a custom solution to get around.
So when you get the following error message in your test class testings: "INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field". What this means is that under the user you are running the test under is not configured to use the values you have populated in the test class. Usually because the test is running under system and is using the master record type that does not have the field mappings. That is my guess at least.
Two ways to fix:
- Set the RecordTypeId in the test data either statically or dynamically through a variable and a soql lookup using the name/developer name
- Use the System.runAs(thisUser) method to either run as the user running the test or create a user with a specifically assigned profile that has the correct privileges and set up.
Below are examples:
Adding New Opportunity Record Type to Wave Sales App
We created a new Opportunity Type over the weekend and I assumed that it would just magically get added to the Opportunity dataset that the default Wave Sales App builds out but no, the dataflow/dataset was missing all the records related to the new record type. Creating a new dataset showed the data so I knew it was the dataflow somehow.
This is a braindead post to remind folks that if you create a new Opportunity record type and use the Salesforce.com default Wave App that you have to go in and update the dataflow JSON in about 4 places depending on the options you picked when you created the App.
These are the nodes:
- Opportunity_Custom_Filter_Flag
- Activity_Custom_Filter_Flag
- Pipeline_Trending_Custom_Filter_Flag
- Opportunity_Products_Custom_Filter_Flag
I recommend just downloading and updating the sections using a JSON editor like this one.
Silly Admin Trick: Extracting Names and Emails from Groups and Permission Sets
Filed away in the "Why is this so hard?", extracting a list of users related to a Public Group, Queue, or Permission Set in Salesforce.com is harder than it should be. Not in reporting and a pain with Dataloader and XLS. There are lots of workarounds and methods for doing this but it should be easy!
So here's another workaround using public group as the example:
- Get the ID of the Group
- Fire up Workbench (https://workbench.developerforce.com/login.php)
- Queries drop down --> SOQL Queries
- Pick User to see the list of fields for reference
- Put the following in Notepad or whatever you use for scratch
- SELECT Name, FirstName, LastName, Business_Unit__c,Title, EMAIL FROM USER WHERE IsActive = TRUE AND ID IN (SELECT UserOrGroupId FROM GroupMember WHERE GroupId = 'Group_ID')
- If you get an error make sure your single quotes are not apostrophe's, Evernote loves to switch those on you without asking.
- Under 'View As' select Bulk CSV so you can easily download/export the entire list
Nothing to interesting but doing the SOQL join can be tricky, left inner join for those keeping score.
Fixing Salesforce.com Developer Console Jerking Back Up or Snapping Back
A strange issue I have had with Salesforce.com Developer Console on Chrome for a couple of (don't laugh) a couple of months is that as I scroll down the page will jerk back up to the previous page. In scanning altslash.org I saw this headline:
Chrome Now Uses Scroll Anchoring To Prevent Those Annoying Page Jumps
Ok, so fast forward through the usual blah blah blah. I disabled this in chrome (chrome://flags/#enable-scroll-anchoring) and either this issue got fixed or this setting fixed the issue I was having with the page jerking back or snapping back anytime I scrolled rapidly down the an apex class. Console is basically a streaming app that is constantly updating and listening for changes so it doesn't surprise me that it was impacted by this but what was so frustrating was that I just could not find anything on the Internets to point me in the direction of how to fix or even identify the problem until just now. Happy Days!
The work around in case someone has this issue is to not scroll with your mouse in the middle of the page but instead to position your mouse on right where the scroll bars are and the system will allow you to scroll with out snapping back to the previous page.
Wave Replication and Data Accuracy
In order to support custom dataflows you have to turn on 'Data Replication' and you want to create custom dataflows in order to allow better control over schedules, development, debugging, and insulation against dataflow failures due to changes, data, etc.
That being said you will want to disable incremental updates. Troubleshooting has several times come back to the Replication Object has stale data even though the data was changed hours or days before working the issue with replication and the dataflows running.
Some things to note:
- New Records are picked up immediately
- Changes could take an hour before getting picked up
- Replication counts against the 24 dataflow limit
This might come across as negative but I am not sure why the replication settings give you the option to run hourly if it's going to cause a limits issue. I have 5 Dataflows plus replication and can only run a refresh once a day.
Use this resource to disable replication: Extract Data Incrementally in Replication
Or basically add this to your dataflows right before the fields: "incremental": false,
Wave Component in editor is un-selectable.
In Salesforce.com Wave Analytics in the new 2.0 Wave Designer, if you find that a component is un-selectable or after selecting your browser freezes here are two things to help resolve:
- Check your XMD File
- When doing custom formatting through the XMD, adding percents and dollars specifically, you do not need to add a label and in some cases this will actually confuse the system so remove it. You can access your XMD from dataset -> edit -> download and then looking at it in a JSON viewer.
- Check your Widget title vs. measureField
- I had an issue where I added a Number field and after adding had to go to the widget section and update the measureField. This was specifically a pigql measure that had multiple columns and somehow it had picked the wrong one.
Measure me if you have your editor freeze up, I might have some more tips but generally rechecking that all the components and any XMD modifications you have made fixed my issue.
Data Loader Error Message Fix: Failed to parse detail
If you have gotten the following message:
Failed to parse detail: START_TAG seen ...</sf:exceptionMessage><sf:upgradeURL>... @1:752 due to: com.sforce.ws.ConnectionException: unable to find end tag at: START_TAG seen ...</sf:exceptionMessage><sf:upgradeURL> ... @1:752
Or something like that while trying to load in to Salesforce.com Data Loader, try upgrading your version. I had 35.00 and 37.00 both fail where a fresh copy of 38.00 worked.
Click the image below for fullsize:
Silly Admin Trick: Avoid Tables going across Page Break
When doing PDF's in Salesforce.com one thing that can be tricky is dynamic content caught between the page break. Signature block being a good example of something that you want kept together on the page. Using the CSS 'page-break-inside' can work 100% the first time or if you have a busy page with lots of formatting and CSS you might run in to issues especially when using 'renderas=pdf' as your HTML and CSS are rendered on the backend and not using your latest/greatest browser. At least that was what I found when my CSS worked great in Chrome and IE but bombed when doing a download/renderas=PDF.
One solution I found that worked 100% is wrapping your table in question in an apex:outputpanel like so:
<apex:outputPanel layout="block" style="page-break-inside: avoid;">
I would like to take credit for this but as usual this was a google find: https://developer.salesforce.com/forums/?id=906F0000000AjSfIAK