• jldenning
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies
I'm trying to construct a query for use in a trigger that uses a multi-select picklist field in the WHERE clause.  I started by hardcoding the choices in the where clause and that worked fine.  I then tried to dynamically get the choices and put them in a string called DeleteDepartmentsString.  The 2 strings DynamicQuery and HardCodedQuery (see below), appear to be identical according to the debug logs.  However, when I change Database.query(HardCodedQuery) to Database.query(DynamicQuery), I get the error System.QueryException: unexpected token: ')'

Can't figure it out what's different about the query strings.  What is the proper way to choose multiple selections from a multi-select picklist in the WHERE clause?  Thanks in advance.

Relevent code is below(debug log lines in bold).

System.debug(DeleteDepartmentsString);
15:14:20.276 (276302000)|USER_DEBUG|[101]|DEBUG|'Intellectual Property', 'Information Technology'

  String DynamicQuery = 'SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = \'a5fA00000004EJ2IAM\' AND Name__r.Department_MultiSelect__c INCLUDES ('+  DeleteDepartmentsString + ') AND Name__r.Department_MultiSelect__c EXCLUDES (\'Executive\') AND Course_Status__c = \'Enrolled\'';

  String HardCodedQuery = 'SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = \'a5fA00000004EJ2IAM\' AND Name__r.Department_MultiSelect__c INCLUDES (\'Intellectual Property\', \'Information Technology\')  AND Name__r.Department_MultiSelect__c EXCLUDES (\'Executive\') AND Course_Status__c = \'Enrolled\'';
 
  List<Partner_Course__c> CD = Database.query(HardCodedQuery);
15:14:20.276 (276700000)|SOQL_EXECUTE_BEGIN|[111]|Aggregations:0|SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = 'a5fA00000004EJ2IAM' AND Name__r.Department_MultiSelect__c INCLUDES ('Intellectual Property', 'Information Technology')  AND Name__r.Department_MultiSelect__c EXCLUDES ('Executive') AND Course_Status__c = 'Enrolled'
15:14:20.308 (308539000)|SOQL_EXECUTE_END|[111]|Rows:6

 
System.debug(DynamicQuery);
15:14:20.308 (308676000)|USER_DEBUG|[113]|DEBUG|SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = 'a5fA00000004EJ2IAM' AND Name__r.Department_MultiSelect__c INCLUDES ('Intellectual Property', 'Information Technology') AND Name__r.Department_MultiSelect__c EXCLUDES ('Executive') AND Course_Status__c = 'Enrolled'
  System.debug(HardCodedQuery);
15:14:20.308 (308694000)|USER_DEBUG|[114]|DEBUG|SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = 'a5fA00000004EJ2IAM' AND Name__r.Department_MultiSelect__c INCLUDES ('Intellectual Property', 'Information Technology')  AND Name__r.Department_MultiSelect__c EXCLUDES ('Executive') AND Course_Status__c = 'Enrolled'

I have a button on a VF page that calls a web service to create a record.  I would like to check if that record already exists, and if it does, display a message to the user.  I cannot get the message to display.  Could someone clue me in on what I need to do?

 

Code for the Button

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

sforce.apex.execute("WSClass", "runCourseAdd", 
{
DocId:"{!Controlled_Document__c.Id}" ,
}
);
window.location.reload();

 Pertinent Class Code

public void addCourse()
{
    if (Course != null)
    {
     String errMessage = 'Course already exists for Revision ' + Course.Revision__c;
     if (ApexPages.currentPage() != null) 
     { 
         ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errMessage ));
     }
    }
}

 VF page

<apex:page standardController="Controlled_Document__c" title="Document Auto Log" sidebar="true" setup="false" >
   <apex:pageMessages />
   <apex:detail />
</apex:page>

 

I have 2 custom components that each include a select box.  I would like to have the first pass its value to the second so that it can change the choices based on the value it is passed.  How would I go about passing the value to the second component?

I am trying to pass the Campaign description field (Long Text Area) to javascript.  It works fine for simple text, but doesn't display anything whenever there is a <br> tag in the description field.  How do I parse the description or pass it so that it displays properly?

Is it not possible to compare 2 Id values using basic == <> operators in a validation rule?


The background.....

 

We have a custom object with lookups on both a Lead and Account so that the user may use it for either one.  

We also have a trigger that when the lead is converted to an account, the convertedAccountId value is copied into the Account field of the custom object.

 

I am trying to create a validation rule that if both the lead and account fields are populated for the custom object, the Account Id must match the convertedAccountId from the lead. The rule below evaluates to true when trying to convert a Lead and prevents the Lead from being converted.  When I turn the rule off the conversion works fine and manual comparison of the ConvertedAccountId and Account__c shows they are the same.  

 

 

AND(NOT(ISBLANK(Lead__c )),

 NOT(ISBLANK(Account__c )),   

 Lead__r.ConvertedAccountId  <>  Account__c  )

We have a required filter on the Account field in opportunity that only lets one type of account be selectable for the opportunity.  I wrote a trigger on Leads (after update) to change the record type of the account that was created to the correct account type via a SOQL update. When the opportunity is generated after lead conversion I get the error:

 

Error: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [AccountId] (System Code) External entry point 

 

This sounds like the opportunity is trying to be created before the trigger can update the account record to the correct type.  Is there a way around this so that I can update account fields before SFDC tries to create the opportunity?

I'm trying to construct a query for use in a trigger that uses a multi-select picklist field in the WHERE clause.  I started by hardcoding the choices in the where clause and that worked fine.  I then tried to dynamically get the choices and put them in a string called DeleteDepartmentsString.  The 2 strings DynamicQuery and HardCodedQuery (see below), appear to be identical according to the debug logs.  However, when I change Database.query(HardCodedQuery) to Database.query(DynamicQuery), I get the error System.QueryException: unexpected token: ')'

Can't figure it out what's different about the query strings.  What is the proper way to choose multiple selections from a multi-select picklist in the WHERE clause?  Thanks in advance.

Relevent code is below(debug log lines in bold).

System.debug(DeleteDepartmentsString);
15:14:20.276 (276302000)|USER_DEBUG|[101]|DEBUG|'Intellectual Property', 'Information Technology'

  String DynamicQuery = 'SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = \'a5fA00000004EJ2IAM\' AND Name__r.Department_MultiSelect__c INCLUDES ('+  DeleteDepartmentsString + ') AND Name__r.Department_MultiSelect__c EXCLUDES (\'Executive\') AND Course_Status__c = \'Enrolled\'';

  String HardCodedQuery = 'SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = \'a5fA00000004EJ2IAM\' AND Name__r.Department_MultiSelect__c INCLUDES (\'Intellectual Property\', \'Information Technology\')  AND Name__r.Department_MultiSelect__c EXCLUDES (\'Executive\') AND Course_Status__c = \'Enrolled\'';
 
  List<Partner_Course__c> CD = Database.query(HardCodedQuery);
15:14:20.276 (276700000)|SOQL_EXECUTE_BEGIN|[111]|Aggregations:0|SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = 'a5fA00000004EJ2IAM' AND Name__r.Department_MultiSelect__c INCLUDES ('Intellectual Property', 'Information Technology')  AND Name__r.Department_MultiSelect__c EXCLUDES ('Executive') AND Course_Status__c = 'Enrolled'
15:14:20.308 (308539000)|SOQL_EXECUTE_END|[111]|Rows:6

 
System.debug(DynamicQuery);
15:14:20.308 (308676000)|USER_DEBUG|[113]|DEBUG|SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = 'a5fA00000004EJ2IAM' AND Name__r.Department_MultiSelect__c INCLUDES ('Intellectual Property', 'Information Technology') AND Name__r.Department_MultiSelect__c EXCLUDES ('Executive') AND Course_Status__c = 'Enrolled'
  System.debug(HardCodedQuery);
15:14:20.308 (308694000)|USER_DEBUG|[114]|DEBUG|SELECT Id FROM Partner_Course__c WHERE Controlled_Document__c = 'a5fA00000004EJ2IAM' AND Name__r.Department_MultiSelect__c INCLUDES ('Intellectual Property', 'Information Technology')  AND Name__r.Department_MultiSelect__c EXCLUDES ('Executive') AND Course_Status__c = 'Enrolled'

I have a button on a VF page that calls a web service to create a record.  I would like to check if that record already exists, and if it does, display a message to the user.  I cannot get the message to display.  Could someone clue me in on what I need to do?

 

Code for the Button

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

sforce.apex.execute("WSClass", "runCourseAdd", 
{
DocId:"{!Controlled_Document__c.Id}" ,
}
);
window.location.reload();

 Pertinent Class Code

public void addCourse()
{
    if (Course != null)
    {
     String errMessage = 'Course already exists for Revision ' + Course.Revision__c;
     if (ApexPages.currentPage() != null) 
     { 
         ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errMessage ));
     }
    }
}

 VF page

<apex:page standardController="Controlled_Document__c" title="Document Auto Log" sidebar="true" setup="false" >
   <apex:pageMessages />
   <apex:detail />
</apex:page>

 

I have 2 custom components that each include a select box.  I would like to have the first pass its value to the second so that it can change the choices based on the value it is passed.  How would I go about passing the value to the second component?

Is it not possible to compare 2 Id values using basic == <> operators in a validation rule?


The background.....

 

We have a custom object with lookups on both a Lead and Account so that the user may use it for either one.  

We also have a trigger that when the lead is converted to an account, the convertedAccountId value is copied into the Account field of the custom object.

 

I am trying to create a validation rule that if both the lead and account fields are populated for the custom object, the Account Id must match the convertedAccountId from the lead. The rule below evaluates to true when trying to convert a Lead and prevents the Lead from being converted.  When I turn the rule off the conversion works fine and manual comparison of the ConvertedAccountId and Account__c shows they are the same.  

 

 

AND(NOT(ISBLANK(Lead__c )),

 NOT(ISBLANK(Account__c )),   

 Lead__r.ConvertedAccountId  <>  Account__c  )

I have a Date  filed name "Contract End Date" in my Asset Object.

 

I need this field to be synchronize with a date field ( Max Support)  on my account tab. So the account field is just a copy off the field in the asset.

 

I try to create a formulas like

 

 Max Support (Date) =$asset.Contract_End_date__c

 

but always get : Error: Field $asset.Contract_End_date__c does not exist. Check spelling.

 

thanks

  • October 29, 2010
  • Like
  • 0