function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ellospiderellospider 

Consolidate Tag on custom object

Greetings All !

We have a requirement to copy all public tags belonging to a custom object as comma seperated string on a custom field on master.  

eg.  
select id, name from cust_object__tag where type = 'Public' and itemId = 'a0SV600000JBbRRMAK' returns 

      ID                        Name
0t0000000008cjkSST              tag1
0t0000000008cjlSGH              tag3
0t0000000008cjlSGT              tag3

A long text field on cust_object  to be populated with 'tag1, tag2, tag3'.  What is the best approach to achieve this? 

Would really appreaciate any suggestions or code samples. 

Ramu_SFDCRamu_SFDC
Fetch the results into a map variable Map<id,Cust_Object_tag> maps=new map<id,Cust_Object_tag> and loop through the values of map for(string str:maps.values()) and enter the results into a long text field using string concatenations methods.

Does this help ?
ellospiderellospider
Thank you Ramu ! I will try and will let you know. 
ellospiderellospider
I am getting  Save error: Invalid initial type LIST<sfdcrec__Candidate__c> for MAP<Id,sfdcrec__Candidate__Tag>

Map<ID,sfdcrec__Candidate__tag> mytag_map = new Map<ID,sfdcrec__Candidate__tag>([Select ID, (Select ItemId, Name from Tags) from sfdcrec__Candidate__c ]);
Any idea? 

Ramu_SFDCRamu_SFDC
When you write a select query within a select query it expects a list to store the data. In the current map structure you defined a single object which cannot hold the list data(inner query) hence the error. Change the map structure to Map<ID,List<sfdcrec__Candidate__tag>> mytag_map = new Map<ID,List<sfdcrec__Candidate__tag>>([Select ID, (Select ItemId, Name from Tags) from sfdcrec__Candidate__c ]);

let me know if this helped.