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
MikeGillMikeGill 

Strange one - passing in string for includes query not working

Hi All,

 

Sorry this is long one - been hard at this since my last post. Very close, now stumped as something just doesn't added up!

 

 

This is strange - the following query works fine

 

 

select Id, Name, Accreditations__c 
 	 				
					from Account where 	Type = 'Dealer' 
 	 				
 	 				AND Country_ISO_Code__c = 'CH'
 	 				AND Accreditations__c includes ( 'RAP','REX' ) 
 	 				AND Accreditations__c != null

 

Note: Searching for RAP or REX.

 

Now inside my class I am doing this:

 

 

String stEndorsements;
	String stMulti;
	public String getStEndorsements(){
	
		stMulti = lead.All_Accreditation_Endorsements__c;
		stEndorsements = queryString();
		return stEndorsements;
	}
	

	
	public String queryString(){
		
		String[] newList = stMulti.split(';');
    	String newString = '';

   		for (Integer i = 0; i < newList.size(); i++){
      	
      		if (newList.size() != (i+1)){
      			newString +=  '\'' + newList[i] + '\',' ;
      		}
 
      		else {
        	newString +=  '\'' + newList[i] + '\'' ;
      		}


   		}
		return newString;
		
	}
	

 

 

Now this works fine too, checked through EA and using System.Debug

 

Here is where it's called

 

 

List<Account> accs = new List<Account>();
 	 		String prodcode = getProductCode();
 	 		
 	 		if (prodcode==null){
 	 		
 	 			getStEndorsements();
 	 			
 	 			String endor = stEndorsements;
 	 			
 	 			System.debug('DEBUG ERROR = '+endor);
 	 			
 	 			List<Account> fromLead = [select Id, Name, BillingCity, Country_ISO_Code__c, Owner.Name, Type, Accreditations__c 
 	 				
					from Account where 	Type = 'Dealer' 
 	 				
 	 				AND Country_ISO_Code__c =: lead.Country_ISO__c
 	 				AND Accreditations__c includes (: endor ) 
 	 				AND Accreditations__c != null
 	 				
 	 				LIMIT 1000];
 	 				
 	 				accs = fromLead;
 	 				
 	 		} 
 	 		

 

Here is the debug log

 

 

22:56:35.315|METHOD_EXIT|[85]|LeadExtensionController.queryString()
22:56:35.315|METHOD_EXIT|[165]|LeadExtensionController.getStEndorsements()
22:56:35.315|METHOD_ENTRY|[169]|System.debug(ANY)
22:56:35.315|USER_DEBUG|[169]|DEBUG|DEBUG ERROR = 'RAP','REX'
22:56:35.315|METHOD_EXIT|[169]|System.debug(ANY)
22:56:35.315|SOQL_EXECUTE_BEGIN|[171]|Aggregations:0|select Id, Name, BillingCity, Country_ISO_Code__c, Owner.Name, Type, Accreditations__c 
 	 				
					from Account where 	Type = 'Dealer' 
 	 				
 	 				AND Country_ISO_Code__c =: lead.Country_ISO__c
 	 				AND Accreditations__c includes (: endor ) 
 	 				AND Accreditations__c != null
 	 				
 	 				LIMIT 1000
22:56:35.357|SOQL_EXECUTE_END|[171]|Rows:0

 

 

The string I am passing in to the includes looks correct to me - can anyone spot what I am doing wrong.

 

Thanks

 

 

sfdcKevinCsfdcKevinC

Try making endor a List<String>

 

List<String> endor = new List<String>();
endor.add('RAP');
endor.add('RAX');

 

 

 

 

MikeGillMikeGill

Hi Kevin - thanks for response

 

Not sure I understand - I don't explicitly know the values

 

Do you mean replace this part with a String<List>

 

 

	public String queryString(){
		
		String[] newList = stMulti.split(';');
    	String newString = '';

   		for (Integer i = 0; i < newList.size(); i++){
      	
      		if (newList.size() != (i+1)){
      			newString +=  '\'' + newList[i] + '\',' ;
      		}
 
      		else {
        	newString +=  '\'' + newList[i] + '\'' ;
      		}


   		}
		return newString;
		
	}

 

Still stuck - here is the whole class

 

 

public class LeadExtensionController {
	
	/*
		Author: 	Mike Gill
		Version: 	1.0 (beta)
		Created:	22/12/2010
		Modified:	20/01/2011
		Client:		
		
		Features: Provide inline Channel partner selection on lead page
		
		TODO:

	*/
	
	// Create lead sObject
	private final Lead lead;
	
	// Enable inline extenstion
	public LeadExtensionController(ApexPages.StandardController stdController){
		this.lead = (Lead)stdController.getRecord();
	}

	
	// Lead Contact Id
	Id leadContactId;
	
	// Account Manager Id
	Id accountOwnerId;
	
	
	public void getContactsId(Id dealerId){
		List<Account> accContacts = [select Id, OwnerId, Lead_Contact__c from Account where Id =: dealerId limit 1 ];		
		accountOwnerId = accContacts[0].OwnerId;
		leadContactId = accContacts[0].Lead_Contact__c;

	}
	
	
	// Account Id
	Id dealerAccs;
	
	// Getter Method
	public Id getDealerAccs() {
            return DealerAccs;
        }
	
	// Setter Method
	public void setDealerAccs(Id dealerAccs) {
            this.dealerAccs = dealerAccs;
        }
	

	// Update Lead with selected dealer/channel account
	public PageReference UpdateLead(){
				
		
		
		Id dealerId = dealerAccs;
		lead.Channel_Account__c = dealerId;
		getContactsId(dealerId);
		lead.Account_Manager__c = accountOwnerId;
		lead.Assigned_To_Lead_Contact__c = leadContactId;
		
		update lead;
		PageReference pageRef = ApexPages.currentPage();
		return pageRef;
	}
	
	/*
	// Get Endorsements from lead
	String Endorsements;
	public String getEndorsements(){
		Endorsements = lead.All_Accreditation_Endorsements__c;
		return Endorsements;
	}
	*/
	
	// Change string from AND to OR
	String stEndorsements;
	String stMulti;
	public String getStEndorsements(){
	
		stMulti = lead.All_Accreditation_Endorsements__c;
		stEndorsements = queryString();
		return stEndorsements;
	}
	

	
	public String queryString(){
		
		String[] newList = stMulti.split(';');
    	String newString = '';

   		for (Integer i = 0; i < newList.size(); i++){
      	
      		if (newList.size() != (i+1)){
      			newString +=  '\'' + newList[i] + '\',' ;
      		}
 
      		else {
        	newString +=  '\'' + newList[i] + '\'' ;
      		}


   		}
		return newString;
		
	}

	// Get ProductCode from lead
	String ProductCode;
	public String getProductCode(){

		ProductCode = lead.Product_Code__c;
		return ProductCode;
	
	}
	
	// Get Accreditation from Product using Lead Product Code
	String Accreditations;
	public String getAccreditations(){
		
		String product = getProductCode();
		
		
		List<Product2> products = [select Id, ProductCode, Name, Accreditations__c from Product2 	
		where Accreditations__c != null and
		Name =: product limit 1]; 	

		if (products.size()!=0){
		return products[0].Accreditations__c;
		}
		else{
			return 'ZZZ';
		}

	}
	

	

	
	// Create SelectList/Options off dealer/channel accounts
 	public List<SelectOption> Dealers {
 		get{
 	 	List<SelectOption> options = new List<SelectOption>();
 	
 			
 			List<Account> accs = new List<Account>();
 	 		String prodcode = getProductCode();
 	 		
 	 		if (prodcode==null){
 	 		
 	 			getStEndorsements();
 	 			
 	 			String endor = stEndorsements;
 	 			
 	 			System.debug('DEBUG ERROR = '+endor);
 	 			
 	 			List<Account> fromLead = [select Id, Name, BillingCity, Country_ISO_Code__c, Owner.Name, Type, Accreditations__c 
 	 				
					from Account where 	Type = 'Dealer' 
 	 				
 	 				AND Country_ISO_Code__c =: lead.Country_ISO__c
 	 				AND Accreditations__c includes (: endor ) 
 	 				AND Accreditations__c != null
 	 				
 	 				LIMIT 1000];
 	 				
 	 				accs = fromLead;
 	 				
 	 		} 
 	 		
 	 		else {
 	 			
 	 			String accred = getAccreditations();

 	 			if (accred != 'ZZZ'){
 	 			List<Account> fromProd = [select Id, Name, BillingCity, Country_ISO_Code__c, Owner.Name, Lead_Contact__c, Type, Accreditations__c
 	 			
					from Account where Type = 'Dealer' 
					AND Country_ISO_Code__c =: lead.Country_ISO__c
 	 				AND Accreditations__c includes (:accred)
 	 				AND Accreditations__c != null	
 	 				
 	 				Limit 1000];
 	 					
 	 				accs = fromProd;
 	 				
 	 			}
 	 			
 	 			

 	 		}
 	 		
 	 		
 	 				if (accs.size()!=0){

		 	 			for (Account acc:accs){
		 	 			//TODO: Confirm string formatting with client
		 	 			String SelectPartner = acc.Name + '   City: ' + acc.BillingCity + '   Country ISO: ' + acc.Country_ISO_Code__c + '  Account Manager: '+ acc.Owner.Name;
			
		 	 			options.add(new SelectOption( acc.Id, SelectPartner ) );
		 	 	
		 	 			}
	 	 			
 	 				}
 	 				
 	 				else{
 	 					options.add(new SelectOption( 'None', 'No valid channel partners found' ) );
 	 				}
 

	 	 	return options;
 		}
 		private set;
  	}

}

 

 

 

sfdcKevinCsfdcKevinC

Make queryString() return a list of the strings (instead of one formatted string) that you want to use for your includes statements.

 

 

public List<String> queryString() {
...
}

List<String> stEndorsements;

public List<String> getStEndorsements() {
...
}

...

String endor = stEndorsements;
...

AND Accreditations__c includes :endor
...
hisrinuhisrinu

You need to add single quotes for each value and then add the ( (start)and ) (end) and send it via dynamic apex.

 

 

MikeGillMikeGill

Hi Kevin,

 

Only just getting back to this one

 

Not sure I understand & here is why

 

The line below causes an illegal assignment error e.g. String to List

 

 

String endor = stEndorsements; 

 

 

Do I need to convert this from string to list?

 

Also this is expecting a string value hence why I built out the string value

 

 

AND Accreditations__c includes :endor

 

May be I don't understand what you mean

 

MikeGillMikeGill

Hi Hisrinu,

 

Here is what my string looks like - 'RAP','REX'   in debugger, then passed in like this (:endor)  

 

Please can you expand on what you mean by  ( (start)and ) (end) e.g. formatting 

 

Thanks