0

I want write down query to fetch value depend on Channel. when user select Channel value is equal to Partner(pick list value) and then display value in dependent pick list for Partner Level which have multi pick list values (Diamond , Gold). how can write down correct query for same. I have written below like :

String squery = 'SELECT Id, Channel__c,Partner_Level__c 
                 FROM MessageAlert__c 
                 WHERE Partner_Level__c 
                 INCLUDES (' + slist + ')';
  • have you linked your picklist (Channel) to the multipicklist (Partner Level) fields using dependent picklist option - help.salesforce.com/… – Vamsi Krishna Gosu Aug 20 '14 at 9:46
  • yes. controlling field : channel – user10584 Aug 20 '14 at 10:02
  • dependent field : Partner Level – user10584 Aug 20 '14 at 10:02
  • are you trying to display these 2 fields in a visualforce page? then you don't need to run a query, you can use inputField to show both the fields and the values will change based on the mapping you defined between their values. here's a reference - salesforce.com/us/developer/docs/pages/Content/… – Vamsi Krishna Gosu Aug 20 '14 at 10:05
  • I want to fetch data based on both fields. – user10584 Aug 20 '14 at 10:21
1

If you want to query MessageAlert records based on the picklist and multipicklist fields, then you can use a query like this

List<MessageAlert__c> = [SELECT Id,Name, Channel__c,Partner_Level__c 
                        FROM MessageAlert__c 
                        WHERE Channel__c = 'Partner' AND
                        Partner_Level__c INCLUDES ('Diamond , Gold')];

and if you want to build the query string dynamically, you can use something like

String queryStr = 'SELECT Id,Name, Channel__c,Partner_Level__c 
                   FROM MessageAlert__c 
                   WHERE Channel__c = \'' + YourPartnerPicklistValue + '\'' + 
                   'AND Partner_Level__c INCLUDES (\'' + 
                   YourPartnerLevelMultiPicklistValues +  '\')';

Note : replace YourPartnerPicklistValue and YourPartnerLevelMultiPicklistValues with your actual variables

  • Gettin g error .... unexpected token: ; – user10584 Aug 20 '14 at 16:00
  • when user select Channel value is equal to Partner(pick list value) and then displayed value in dependent pick list for Partner Level which have multi pick list values (Diamond , Gold). now depend upon Partner Values , we want to show different different message for each so particular Partner level user can see own message alert , not others. plz modify the below query . If possible can use string / boolean kind of concept. – user10584 Aug 20 '14 at 16:08
  • Depend upon Partner level, message will be filter out – user10584 Aug 20 '14 at 16:11
  • I have updated my answer based on your comments. let me know if that works or for any other changes – Vamsi Krishna Gosu Aug 21 '14 at 3:40
  • Getting error message. MALFORMED_QUERY: unexpected token: – user10584 Aug 21 '14 at 6:51
-1

If you want to select records that have those values, you should use IN instead of INCLUDE.

String squery = 'SELECT Id, Channel__c,Partner_Level__c'+ 
             ' FROM MessageAlert__c'+
             ' WHERE Partner_Level__c IN :slist'+
             ' AND Channel__c = \'Partner\' ';

Note the blank spaces at the beginning of each line.

That'll select all Message Alerts with Channel Partner and Partner_Level__c in the slist (I'm considering that slist is a list of strings).

P.s.: make sure that each value on the slist is a string with no blank spaces or extra characters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.