Jump to content

Recommended Posts

Posted

Sample Code:

 

  1. trigger AccountTrigger on Account ( after insert ) {  
  2.   
  3.     Set < String > setBillCountries = new Set < String >();  
  4.       
  5.     for( Account acc : trigger.new ) {  
  6.       
  7.         if ( acc.BillingCountry != null )   
  8.             setBillCountries.add( acc.BillingCountry );  
  9.       
  10.     }  
  11.       
  12.     if ( setBillCountries.size() > 0 ) {  
  13.       
  14.         Map < String, String > mapTopicNameId = new Map < String, String >();  
  15.           
  16.         for ( Topic objTopic : [ SELECT Id, Name FROM Topic WHERE Name IN: setBillCountries ] )  
  17.             mapTopicNameId.put( objTopic.Name, objTopic.Id );  
  18.   
  19.         for( Account acc : trigger.new ) {  
  20.           
  21.             if ( acc.BillingCountry != null && mapTopicNameId.containsKey( acc.BillingCountry ) )  {  
  22.                         
  23.                 ConnectAPI.Topic objTopic = ConnectAPI.Topics.assignTopic( null, String.valueOf( acc.Id ), mapTopicNameId.get( acc.BillingCountry ) );  
  24.                   
  25.             }  
  26.               
  27.         }  
  28.       
  29.     }  
  30.   
  31. }  

 

Note: 

Each assignTopic() counts against DML limit. 

Use assignTopicByName() to avoid SOQL and use Topic Name instead of Id.

 

 

https://expertwebcode.blogspot.com/2019/10/how-to-auto-assign-topics-to-records-in.html

  • Moderators
Posted (edited)

And this has exactly what to do with AutoIt?

                                                     ***In case you were wondering, this is a Mod stepping into a thread***

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...