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
dev2014dev2014 

Apex Trigger Assigning a specific type of lead to a specific Queue

Hi All,

While  working on Salesforce point & click functionalities , we are trying to complete the final  part of the logic  of our Apex trigger for a client .

The final part of the business logic we are trying to implement now is to automatically take leads with "Annual Revenue" amount of  above 500k  and a pick list value of "finance"  for the "vertical"  field  and assign it to the "Financial  expertise"  team Queue :

if (l.AnnualRevenue >= 500000 & l.Vertical__c == 'Finance') { 

then

Assign lead to the "Financial Expertise" Queue

I created a pick list based "vertical "field on the Lead  object and a created  Queue named "Financial Expertise" based on the Lead  object for this purpose.

I would appreciate your code input on this use case or code reference to similar use case where you assign the lead to a specific Queue. This is my first Salesforce project so I appreciate your input and help on this.

I guess I would have  to assign a lead owner value to the "Finance Expertise" Queue ID. what would be the queue assignment code input for this if statement:

if (l.AnnualRevenue >= 500000 & l.Vertical__c == 'Finance') { 


Assign lead owner to the the "Financial Expertise" Queue ID  ?

Thanks. This is my first Salesforce project so I appreciate your  input.

 

logontokartiklogontokartik
Hi, 

you can maybe try something like below. 
trigger AssignLeadsToQueue on Lead (before insert, before update){
    
   Group financialExpQueue = [Select Id from Group where Type = 'Queue' AND Name = 'Financial Expertise' LIMIT 1];

   for(Lead l : Trigger.new){
       if (l.AnnualRevenue >= 500000 & l.Vertical__c == 'Finance') {
           l.OwnerId = financialExpQueue.Id;
       }

   }

}
Here is the documentation for Group 

https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_group.htm