You need to sign in to do that
Don't have an account?
Linda 98
trigger to get values from multi-select picklist to SOQL
Having a trigger to fire when a value is changed.
On update of the field, it should consider multi-select picklist values(List of roles-As it's multi-select datatype, may have one role is chosen or multiple chosen) and use them in a query to contact(Multi-select picklist field). Further, I would like to use those contact ids to create records in another custom object.
I saved the roles on record(trigger.new) into a list. But when I try to query to contact, I am not able to get the values.
For instance,
Values on Record 1-
checkbox -checked to true(which fires trigger)
Roles- Manager; Owner; Supervisor
Contact records-
contact 1-
Roles :Manager;Supervisor
Contact 2-
Roles-Owner
Contact 3:
roles-Manager;Architect
Contact 4-
Roles-Manager
Contact 5-
Roles: Analyst;Architech
In the above example, I would like to get all the contact IDs except contact 5. I even want Contact 3 even his roles include Architect which is not in our record roles list. As he is having a manager role, I would like to collect it too.
I used
Split(',') doesn't seem to work, What am I doing wrong?
On update of the field, it should consider multi-select picklist values(List of roles-As it's multi-select datatype, may have one role is chosen or multiple chosen) and use them in a query to contact(Multi-select picklist field). Further, I would like to use those contact ids to create records in another custom object.
I saved the roles on record(trigger.new) into a list. But when I try to query to contact, I am not able to get the values.
For instance,
Values on Record 1-
checkbox -checked to true(which fires trigger)
Roles- Manager; Owner; Supervisor
Contact records-
contact 1-
Roles :Manager;Supervisor
Contact 2-
Roles-Owner
Contact 3:
roles-Manager;Architect
Contact 4-
Roles-Manager
Contact 5-
Roles: Analyst;Architech
In the above example, I would like to get all the contact IDs except contact 5. I even want Contact 3 even his roles include Architect which is not in our record roles list. As he is having a manager role, I would like to collect it too.
I used
conroles=[select id,Roles__c,Title from contact where Roles__c IN :Roleslist]; Roleslist=List of roles on Record. But its only fetching first roles contact's.
Split(',') doesn't seem to work, What am I doing wrong?
Using some ideas from Alain (thanks), i created the following trigger that should give you the complete idea on how to solve your issue.
Contact_linkage__c is just a custom object with Contacts as a related list. Contact has a field linking to the custom object. I'm only dealing with a single record, so this trigger would not survive a bulk insert of the Contact_Linkage object.
HTH
Andrew
All Answers
multi-select picklist values?
It is not a comma but a semicolon.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_multiselect_picklists.htm
You can test your query directly by usng the developer console.
i didn't see your filter at the beginning with the semicolons: Manager; Owner; Supervisor
But that was commas here indeed.
It is just "includes" instead of "in".
The following code works (dynamic SOQL).
The following syntax doesn't work indeed:
List<Contact> cnt = [select id,name from contact where role__c includes (:roleids)];
Using some ideas from Alain (thanks), i created the following trigger that should give you the complete idea on how to solve your issue.
Contact_linkage__c is just a custom object with Contacts as a related list. Contact has a field linking to the custom object. I'm only dealing with a single record, so this trigger would not survive a bulk insert of the Contact_Linkage object.
HTH
Andrew
I also bulkified it to create multiple records. I am now trying to filter the result and then capture the contact id. That is, I am trying to check the size of contacts, if they are more than 10, then I would like to check contact level(Custom picklist field) on the list of contacts and choose only first 10 contacts whose contact_level__c is 'top'
If no contact has it then just need to include those contacts.
How can I do that??
Please guide me with this thank you!!
Depending on how you have bulkified your trigger, you could use the LIMIT n
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_limit.htm
If that doesnt work based on the bulkification, if you use the ORDER BY in soql you may be able to loop using a counter
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_select_order_by_with_limit.htm
psuedo code
Regards
Andrew