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
subhajit13subhajit13 

Programatically creating Queue Records with Lead as Supported Object

I am trying to programmatically create a User Queue record that can own Lead records via a trigger . According to the documentation available for Group object

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_group.htm#topic-title

 

setting Group.Type = ‘Lead’  should achieve this . But, this is throwing an exception at runtime

 

Apex trigger insertSalesTeam caused an unexpected exception, contact your administrator: insertSalesTeam: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Type: bad value for restricted picklist field: Lead: [Type]: Trigger.insertSalesTeam: line 33, column 9

 

If , however , I give  Group.Type  =  ‘Queue’ , it perfectly creates a Queue record as expected , but I have to set ‘Lead’ as ‘Supported Object’ manually .

 

Have any of you faced this problem ? can you please let us know if there is some work around for this .

anan

If I understood correctly what you are trying to do it can be achieved creating first a Queue type Group object and then associating it to queue Sobject.

 

 

Group g = new Group(Type='Queue', Name='Queue name');
insert g;

QueueSObject q = new QueueSObject(SobjectType='Lead', QueueId=g.Id);
insert q;

 

I hope this helps, athough I would also like to know what group type 'Lead' actually means.