Currently, I am trying to create some Case Tags for my Case during an after insert event.
Essentially, all I am doing is taking a legacy field and splitting it, getting all the distinct tags. However, I don't know how to create a new CaseTag
record.
Here is the code I have so far for my handler:
public static void CreateCaseTagsFromLegacyTags(List<Case> casesWithTags)
{
List<CaseTag> newCaseTags = new List<CaseTag>();
for(Case caseWithTag : casesWithTags)
{
//I pre-filtered the records prior, so this value is never null
//or empty
List<String> tags = caseWithTag.LegacyTags__c.split(' ');
for(String tag : tags)
newCaseTags.add(new CaseTag(/* What goes there? */));
}
INSERT newCaseTags;
}
So has anyone created a tag through apex before? I don't see why that not. I tried finding any example on how to do that and I could not find a single case where it was done (pun intended). So if there is any way to make this possible, please let me know.