Multi-select picklists are stored as value1;value2;value3;etc
. Knowing that, you can get a List
of these values using the String split()
method. You can also view this string splitting example. To access it, you would then tweak your code as:
trigger AutoCreateInterviewer on Position__c (after insert) {
List<Interviewer__c> interviewers = new List<Interviewer__c>();
//For each position processed by the trigger, add a new
//interviewer record for the specified hiring manager.
//Note that Trigger.New is a list of all the new positions
//that are being created.
for (Position__c newPosition: Trigger.New) {
if (newPosition.Hiring_Manager__c != null) {
// split out the multi-select picklist using the semicolon delimiter
for(String hiringManager: newPosition.Hiring_Manager__c.split(';')){
interviewers.add(new Interviewer__c(
Name = '1',
Position__c = newPosition.Id,
Employee__c = (Id)hiringManager,
Role__c = 'Managerial'));
}
}
}
insert interviewers;
}
@isTest
public with sharing class AutoCreateInterviewerTriggerTest {
static testMethod void testGetAdvisor() {
// First, set up your test User.
User testUser = generateTestUser();
// Generate your position but don't perform DML yet
Position__c pos = new Position(Hiring_Manager__c = testUser.Id);
// Start your test and insert your position
Test.startTest();
insert pos;
Test.stopTest();
// Get the interviewers from the DB to ensure they were created
List<Interviewer__c> interviewers = [SELECT
Id
FROM
Interviewer__c
WHERE
Position__c = :pos.Id
];
// There should be 1 interviewer because only one user ID was provided
System.assert(1, interviewers.size(), 'One interviewer object is expected');
}
private User generateTestUser(){
// We use the System Admin profile because it will always be there
Profile sysAdmin = [SELECT
Id
FROM
Profile
WHERE
Name = 'System Administrator'
LIMIT 1
];
// Generate the user
User newUser = new User(
UserName = 'unit.tester@example.com',
LastName = 'Test',
FirstName = 'Jane',
Email = 'unit.tester@example.com',
phone = '555-555-5555',
MobilePhone = '555-555-5554',
Street = '123 Fake Street',
City = 'Los Angeles',
State = 'CA',
PostalCode = '12345',
CommunityNickName = 'unit.test',
Alias = 'abcd',
ProfileId = sysAdmin.Id,
emailencodingkey = 'UTF-8',
languagelocalekey = 'en_US',
localesidkey = 'en_US',
timezonesidkey = 'America/Los_Angeles'
);
// Insert that user
insert user;
return user;
}
}
I know this is old, but here's how I'm doing it.
$(function () {
// Create the tree inside the <div id="tree"> element.
$("#tree").fancytree({
source: { url: "/Home/GetData", cache: true }
, checkbox: true
, icons: false
, cache: true
, lazyLoad: function (event, data) {
var node = data.node;
data.result = {
url: "/Home/GetTreeViewData/" + node.key
, data: { mode: "children", parent: node.key }
, cache: true
};
}
, selectMode: 3
, select: function (event, data) {
}
, strings: {
loading: "Grabbing places and events…",
loadError: "Load error!"
},
})
});
Basically, if you were to browse to mysite/Home/GetData, it returns a json result that looks like this
[{"key":1,"title":"Accommodations","lazy":true,"parentId":null},{"key":5,"title":"Attractions","lazy":false,"parentId":null},{"key":6,"title":"Dining","lazy":false,"parentId":null},{"key":7,"title":"Entertainment","lazy":false,"parentId":null},{"key":18,"title":"1","lazy":true,"parentId":null},{"key":23,"title":"2","lazy":true,"parentId":null}]
Now say you expand the first node, it's ID in the database is 1, and any children underneath it have a column called parentId with a value of one. When you browse to mysite/Home/GetTreeViewData/1 you get this
[{"key":2,"title":"Hotels","lazy":false,"parentId":1},{"key":3,"title":"Bed \u0026 Breakfast","lazy":false,"parentId":1}]
So I just pull the node.key as my Id and use it to load the children. Hope it helps.
Best Answer
Your solution will mangle decimals. You need to include the
.
character as well. Normally you would have to escape it, but in character sets it is already a literal. Feel free to test it for yourself with/without the . included.You need:
Please note that Regex 101 has an Explanation panel in its UI that tells you how this regular expression works.
/[^0-9.]/gm
[^0-9.]
0-9
matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive).
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)It also has a helpful quick reference that explains various syntax.
[^abc]
- a character except: a, b, or c[^a-z]
- a character not in the range: a-zPutting it together, the recommended expression matches any character unless it is
.
(literal) or in the range1-9
. Note that it would match1.2.3.4.5
, so if you need more stringent validation you will need to go a more nuanced route.