You need to sign in to do that
Don't have an account?

Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '"
I had someone edit a class and unfortunately they've gone missing and I'm getting an error when deploying:
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '", Failure Stack Trace: "Class.EstimateCommList.searchEsti: line 266, column 1 Class.TestEstimateCommListClass.DoListTest: line 114, column 1"
I'd appreciate some help in fixing this. I've attached the code for both classes below.
Thanks!
Failure Message: "System.QueryException: line 1:832 no viable alternative at character ' '", Failure Stack Trace: "Class.EstimateCommList.searchEsti: line 266, column 1 Class.TestEstimateCommListClass.DoListTest: line 114, column 1"
I'd appreciate some help in fixing this. I've attached the code for both classes below.
Thanks!
public without sharing class EstimateCommList { public list<Data_Estimated_Comm> LDEC {get;set;} public User user; public String curruserid; public String CId; public String sort_by {get;set;} public Date from_date {get;set;} public Date to_date {get;set;} public string fromdate{get; set;} public string todate{get; set;} public map<string,List<string>> JuniorContactsMap; public String User_Selection{get;set;} public Boolean IsEmptyList{get;set;} public List<string> cLst; public Boolean hasAgencyAccess{get;set;} public Boolean IsAgency{get;set;} public map<string,string> AccountMap; public Date StartingDate; public EstimateCommList() { curruserid = UserInfo.getUserId(); system.debug('curruserid:'+curruserid); //get user record with contact__c user = [Select u.Name, u.Id, u.ContactId,u.contact.accountid,u.contact.Agency_Commission_Access__c From User u where u.Id =:curruserid]; CId = user.ContactId; if(user.contact.Agency_Commission_Access__c==true){ hasAgencyAccess=true; } else{ hasAgencyAccess=false; } IsAgency=false; if(test.isrunningtest()){ User_Selection=CId; } system.debug('CId:'+CId); //Added for Datepicker variale convertion into date time. fromdate=string.valueOf(string.valueOf(System.today().month()+'/'+System.today().day()+'/'+System.today().year())); system.debug('@@@@@@@@@@'+fromdate); todate= string.valueOf(System.today().addmonths(6).month()+'/'+System.today().addmonths(6).day()+'/'+System.today().addmonths(6).year()); system.debug('@@@@@@@@@@'+todate); IsEmptyList=false; system.debug('**************'+IsEmptyList); JuniorContactsMap=new map<string,List<string>>(); for(contact g:[select id,name,ReportsToId from contact]){ if(JuniorContactsMap.containskey(g.ReportsToId)){ JuniorContactsMap.get(g.ReportsToId).add(g.id); } else{ list<string> temp=new List<string>(); temp.add(g.id); JuniorContactsMap.put(g.ReportsToId,temp); } } system.debug('################'+JuniorContactsMap); cLst=new List<string>(); cLst.add(CId); List<string> cLst1=new List<string>(); cLst1.add(CId); List<string> TList=new List<string>(); TList.add('Test'); while(TList.size() >=1){ system.debug('^^^^^^^^^^^^^^^^^'+cLst1); List<string> TempConList=Childcontacts(cLst1); if(TempConList.size()>0){ cLst.addall(TempConList); cLst1=TempConList; } else{ TList.remove(0); } } system.debug('***************'+cLst); StartingDate=date.newinstance(2014,7,1); system.debug('######'+StartingDate); list<Estimated_Commissions__c> LEC = [Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate, e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c, e.Insurance_Case__r.name, e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c, e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name, e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,e.Insurance_Case__r.Submitted_Date__c, e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c, e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name From Estimated_Commissions__c e where e.Agent__c =:CId AND e.Insurance_Case__r.Submitted_Date__c >=: StartingDate order by CreatedDate desc limit 1000 ]; system.debug('LEC:'+LEC); if(LDEC == null) LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c EC : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = EC.Agency__r.Name; DEC.Agent = EC.Agent__r.Name; DEC.Casesplit = EC.Case_Split__c; DEC.ExcessCommAmt = EC.Excess_Commission_amount__c; DEC.ExcessCommRate = EC.Excess_Commission_Rate__c; DEC.FYCAmt = EC.FYC_Amount__c; DEC.FYCRate = EC.FYC_Rate__c; DEC.Insurance_Commission_Name = EC.Name; DEC.PolicyNumber = EC.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = EC.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = EC.Insurance_Case__r.Carrier__r.Name; DEC.Product = EC.Insurance_Case__r.Product__r.Name; DEC.Client = EC.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = EC.Insurance_Case__r.Premium_Mode__c; DEC.Premium = EC.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = EC.Valid_From__c; //new changes DEC.InsuranceCase= EC.Insurance_Case__c; DEC.InsuranceCaseName= EC.Insurance_Case__r.Name; LDEC.add(DEC); } } public List<SelectOption> getSort() { List<SelectOption> options1 = new List<SelectOption>(); options1.add(new SelectOption('Valid_From__c','Date')); options1.add(new SelectOption('Agent__r.Name','Agent Name')); options1.add(new SelectOption('Insurance_Case__r.Carrier__r.Name','Carrier')); options1.add(new SelectOption('Insurance_Case__r.Line_of_Business__c','Line Of Business')); options1.add(new SelectOption('Insurance_Case__r.Product__r.Name','Product')); options1.add(new SelectOption('Insurance_Case__r.Policy_Number__c','Policy Number')); options1.add(new SelectOption('Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name','Client')); options1.add(new SelectOption('Insurance_Case__r.Premium_Mode__c','Premium Mode')); options1.add(new SelectOption('Insurance_Case__r.Target_Premium__c','Premium')); options1.add(new SelectOption('FYC_Rate__c','FYC Rate')); options1.add(new SelectOption('FYC_Amount__c','FYC Amount')); options1.add(new SelectOption('Excess_Commission_Rate__c','Excess Rate')); options1.add(new SelectOption('Excess_Commission_amount__c','Excess Amount')); return options1; } //Method which will call each time for inner hierarchy of contacts public List<string> Childcontacts(List<string> CurrentContactsIDList){ List<string> d=new List<string>(); for(string w:CurrentContactsIDList){ system.debug('%%%%%%%%%%%%%%%'+w+'-'+JuniorContactsMap.get(w)); if(JuniorContactsMap.containskey(w)){ for(string l:JuniorContactsMap.get(w)){ d.add(l); } } } return d; } //Method which will have all users list in hierarchy of user logged in public List<SelectOption> getAllusers() { List<SelectOption> options1 = new List<SelectOption>(); AccountMap=new MAp<string,string>(); integer i=0; List<contact> mylst=[select id,name,accountid from contact where id IN:cLst]; for(contact w:[select id,name,accountid from contact where id IN:cLst]){ AccountMap.put(w.id,w.accountid); if(w.id==CId){ contact q=mylst[0]; mylst[0]=mylst[i]; mylst[i]=q; } i++; } system.debug('###############'+AccountMap); for(contact c:mylst){ options1.add(new SelectOption(c.id,c.name)); } return options1; } public pagereference searchEsti() { List<Estimated_Commissions__c> LEC = new List<Estimated_Commissions__c>{}; //New chanages as part of input date picker format changes Datetime Dt1; string Dt2; Datetime Dt3; string Dt4; system.debug('##############'+fromdate+'-'+todate); if(fromdate !=null && fromdate !=''){ List<string> a=fromdate.split('/'); Dt1=Datetime.newinstance(integer.valueOf(a[2]),integer.valueOf(a[0]),integer.valueOf(a[1])); Dt2=Dt1.format('yyyy-MM-dd'); } else{ Dt2=null; } if(todate !=null && todate !=''){ List<string> b=todate.split('/'); Dt3=Datetime.newinstance(integer.valueOf(b[2]),integer.valueOf(b[0]),integer.valueOf(b[1])); Dt4=Dt3.format('yyyy-MM-dd'); } else{ Dt4=null; } system.debug('######'+Dt2+'-'+Dt4); String DB1 = 'Select e.Valid_From__c, e.SystemModstamp, e.Name, e.LastModifiedDate,'; DB1 += 'e.LastModifiedById, e.LastActivityDate, e.IsDeleted, e.Insurance_Case__c,e.Insurance_Case__r.name,'; DB1 += 'e.Id, e.FYC_Rate__c, e.FYC_Amount__c, e.Excess_Commission_amount__c, '; DB1 += 'e.Excess_Commission_Rate__c, e.CreatedDate, e.CreatedById, e.Case_Split__c,'; DB1 += 'e.Agent__c, e.Agency__c , e.Agent__r.Name , e.Agency__r.Name,'; DB1 += 'e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,'; DB1 += 'e.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name, e.Insurance_Case__r.Premium_Mode__c,'; DB1 += 'e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Submitted_Date__c, '; DB1 += 'e.Insurance_Case__r.Line_of_Business__c, e.Insurance_Case__r.Carrier__r.Name'; DB1 += ' From Estimated_Commissions__c e '; if(IsAgency==false){ DB1 += ' where e.Agent__c =\''+User_Selection+'\''; } else if(IsAgency==true){ //DB1 += ' where e.Agency__c =\''+AccountMap.get(User_Selection)+'\''; DB1 += ' where e.Agency__c =\''+user.Contact.accountId+'\''; } //New changes as part of input date chaanges DB1 += ' and e.Insurance_Case__r.Submitted_Date__c >= '+ StartingDate; if(Dt2!=null){ DB1 += ' and e.Valid_From__c >= ' + Dt2; } if(Dt4!=null){ DB1 += ' and e.Valid_From__c <= ' + Dt4; } DB1 += ' order by '+ sort_by + ' asc ' ; DB1 += ' limit 10'; system.debug('#################'+DB1); LEC = DataBase.query(DB1); system.debug('LEC:'+LEC); LDEC = new list<Data_Estimated_Comm>{}; for ( Estimated_Commissions__c est : LEC){ // Create a Data record and add it to the list Data_Estimated_Comm DEC = new Data_Estimated_Comm(); DEC.Agency = est.Agency__r.Name; DEC.Agent = est.Agent__r.Name; DEC.Casesplit = est.Case_Split__c; DEC.ExcessCommAmt = est.Excess_Commission_amount__c; DEC.ExcessCommRate = est.Excess_Commission_Rate__c; DEC.FYCAmt = est.FYC_Amount__c; DEC.FYCRate = est.FYC_Rate__c; DEC.Insurance_Commission_Name = est.Name; DEC.PolicyNumber = est.Insurance_Case__r.Policy_Number__c; DEC.LineOfBusiness = est.Insurance_Case__r.Line_of_Business__c; DEC.Carrier = est.Insurance_Case__r.Carrier__r.Name; DEC.Product = est.Insurance_Case__r.Product__r.Name; DEC.Client = est.Insurance_Case__r.Primary_Insured_or_Annuitant__r.Name; DEC.PremiumMode = est.Insurance_Case__r.Premium_Mode__c; DEC.Premium = est.Insurance_Case__r.Target_Premium__c; DEC.Valid_From = est.Valid_From__c; //new changes DEC.InsuranceCase= est.Insurance_Case__c; DEC.InsuranceCaseName= est.Insurance_Case__r.Name; LDEC.add(DEC); } return null; } }
/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */ @isTest(SeeAllData=false) private class TestEstimateCommListClass { static testMethod void DoListTest() { RecordType r = [Select Name, Id From RecordType where Name ='Carriers' ]; profile w = [Select Name, Id From profile where Name ='Authenticated Website' ]; Account a= new Account(); a.Name = 'atest'; a.Type = r.Name; a.RecordTypeId = r.Id; system.debug('a:'+a); insert a; contact con=new contact(lastname='test two',accountid=a.id,Email='client321@mixcimizer.com'); insert con; User u = new User(); u.Username = 'cooks@gmail.com'; u.LastName = 'mycook'; u.Email = 'client321@mixcimizer.com'; u.profileid = w.id; u.contactid = con.id; u.alias =u.LastName.substring(0,4); u.CommunityNickname ='4321new'; u.MobilePhone ='9875643456'; u.TimeZoneSidKey = 'Asia/Kolkata'; u.LocaleSidKey = 'en_IE_EURO'; u.EmailEncodingKey = 'ISO-8859-1'; u.LanguageLocaleKey = 'en_US'; u.IsActive = true; INSERT U; Carrier_Product__c p = new Carrier_Product__c(); p.Name = 'ptest'; p.Carrier__c = a.Id; p.Line_of_Business__c = 'Life Insurance'; p.Plan_Type__c = 'Term Life Insurance'; insert p; Insurance_Case__c ic = new Insurance_Case__c(); ic.Carrier__c = a.Id; ic.Product__c = p.Id; ic.X1035_Exchange_Amount__c = 1000; ic.X1035_Exchange_Carrier__c = 'test'; ic.Approved_Rating_Additional_Insured__c = 'test'; ic.Approved_Rating_Primary_Insured__c = 'test'; ic.Elimination_Period__c = ''; ic.Excess_Premium__c = 1000; ic.Face_Amount__c = 500; ic.Line_of_Business__c = 'Life Insurance'; ic.Lump_Sum_Amount__c = 500; ic.Modal_Premium__c = 1000; ic.Policy_Number__c = '123'; ic.Premium_Mode__c = 'Monthly'; ic.Premium_Payment_Method__c = ''; ic.Policy_Date__c = system.today(); ic.Proposed_Face_Amount__c = 100; ic.Proposed_Premium__c = 100; ic.Proposed_Type_Of_Insurance__c = ''; ic.Rating_Applied_For_Additional_Insured__c = ''; ic.Rating_Applied_For_Primary_Insured__c = ''; ic.Source_of_Funds__c = ''; ic.State_of_Issue__c = 'Alabama'; ic.Status__c = 'Inforce'; ic.Target_Premium__c = 1000; insert ic; ic.X1035_Exchange_Amount__c = 2000; ic.X1035_Received_Date__c = system.today(); ic.X1035_Received__c = true; ic.Lump_Sum_Amount__c = 400; ic.Lump_Sum_Received__c = true; ic.Lump_Sum_Received_Date__c = system.today(); update ic; Estimated_Commissions__c e = new Estimated_Commissions__c(); e.Insurance_Case__c = ic.id; e.agent__c=con.id; insert e; system.runas(u){ EstimateCommList ecl = new EstimateCommList(); ecl.getAllusers(); ecl.getSort(); ecl.sort_by='Valid_From__c'; ecl.searchEsti(); Data_Estimated_Comm Dec = new Data_Estimated_Comm(); EstimateCommList ec2 = new EstimateCommList(); ec2.getAllusers(); ec2.getSort(); ec2.sort_by='Valid_From__c'; ec2.searchEsti(); } } }
DB1 += ' and e.Insurance_Case__r.Submitted_Date__c >= :StartingDate' ;
All Answers
You are using dynamic SOQL. In dynamic SOQL you need to user SOQL Injection in your query.
For more details about SOQL Injection please follow this link
http://simplyforce.blogspot.in/2011/03/salesforce-applications-with-security_14.html
If you still not able to get rid of error than please ping your debug log
system.debug('#################'+DB1); at line no 265.
I compared the code of the version above with what has been previously deployed (successfully). The only changes are in the EstimateCommList class and not the test class.
Those changes are:
Line 22: public Date StartingDate;
Line 90: StartingDate=date.newinstance(2014,7,1);
Line 91: system.debug('######'+StartingDate);
Line 99: e.Insurance_Case__r.Target_Premium__c, e.Insurance_Case__r.Product__r.Name,e.Insurance_Case__r.Submitted_Date__c,
Line 104: where e.Agent__c =:CId AND e.Insurance_Case__r.Submitted_Date__c >=: StartingDate
Line 238: DB1 += 'e.Insurance_Case__r.Policy_Number__c, e.Insurance_Case__r.Submitted_Date__c, ';
Line 252: DB1 += ' and e.Insurance_Case__r.Submitted_Date__c >= '+ StartingDate;
I can't see where any of those changes would all of a sudden cause an issue with deployment.
My goal with the class is to simply add a WHERE statement to the query to retrieve records that have a date field equal or greater than a specific date (7/1/14). This is on line 104 as follows:
and on line 252
This class deployed successfully before we added the requirement to check the Submitted_Date__c versus that date (7/1/14). The previous developer tried to accomplish this by declaring StartingDate. But maybe it would be easier to specifically state the date instead such as (and I know this won't work):
where e.Agent__c =:CId AND e.Insurance_Case__r.Submitted_Date__c >= 07/01/14
Thanks for your help. We're supposed to be rolling this out over the weekend.
DB1 += ' and e.Insurance_Case__r.Submitted_Date__c >= :StartingDate' ;