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
suneel.patchipulusu@gmail.comsuneel.patchipulusu@gmail.com 

Please correct the error in SOQL statement

List<LQPricebook__c> lqp = new list<LQPricebook__c>();
//////////////////////////////////////////////////////
///6 PriceBook Check////////////////
//////////////////////////////////////////////////////
lqp = [SELECT ID, Name, ValidForm__c
FROM LQPricebook__c WHERE clm.Claim_Invoice_Date__c >= LQPricebook__c.ValidForm__c
                                                                    and (clm.Claim_Invoice_Date__c <= LQPricebook__c.ValidForm__c + ((365/12)* 3))
                                                            ]; 

if (lqp.size() != 0){

System.debug( 'exists' +lqp[0].ID);
clm.Pricebookno__c = lqp[0].ID ;
}else {

clm.Pricebookno__c = NULL;
}

 

 

In tthe above code I am getting an eror in SOQL statement. Could anyone can tell me whats the wrong in that??

 

I am getting an error like 'Unexpected token: LQPricebook__c.ValidFrom__c'

 

Thanks in advance

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Simple typo - clm needs a : in front of it to make it a bind variable:

 

FROM LQPricebook__c WHERE LQPricebook__r.ValidForm__c <= :clm.Claim_Invoice_Date__c

 

All Answers

bob_buzzardbob_buzzard

The right hand side of a condition in a where cause must be a literal, so having the following:

 

 clm.Claim_Invoice_Date__c >= LQPricebook__c.ValidForm__c

 

is not allowed because 'LQPricebook__c.ValidForm__c' is not a literal value, rather it is the value of another field.  I also can't see where 'clm' is coming from - it doesn't appear in the code or SOQL query.

 

 

Vinit_KumarVinit_Kumar

Can you be more clear,what you want top achieve and what is clm here.

 

 

suneel.patchipulusu@gmail.comsuneel.patchipulusu@gmail.com

List<Claim__c> stdClaims = new List<Claim__c>();

for(Integer i = 0; i < Trigger.new.size(); i++){
Claim__c clm = Trigger.new[i];

System.debug('trigger claim number: ' + i);

try{

List<LQPricebook__c> lqp = new list<LQPricebook__c>();
//////////////////////////////////////////////////////
///6 PriceBook Check///////////////
//////////////////////////////////////////////////////
lqp = [SELECT ID, Name, ValidForm__c
FROM LQPricebook__c WHERE clm.Claim_Invoice_Date__c >= LQPricebook__c.ValidForm__c
and (clm.Claim_Invoice_Date__c <=
LQPricebook__c.ValidForm__c + ((365/12)* 3))
//IsPublished__c =: True
//and Status__c = 'Active'
];

if (lqp.size() != 0){

System.debug( 'exists' +lqp[0].ID);
clm.Pricebookno__c = lqp[0].ID ;
}else {

clm.Pricebookno__c = NULL;
}

} Catch(Exception ee) {
System.debug('ClaimTrigger exception '+ee);
}

suneel.patchipulusu@gmail.comsuneel.patchipulusu@gmail.com

The above mentioned code is clear I guess 

 

But I am geeting an error still

 

suneel.patchipulusu@gmail.comsuneel.patchipulusu@gmail.com

What I need to get is like 

 

If the Claim date is between in the LQpricebook.validfrom__c and LQPricebook__c.ValidForm__c + ((365/12)* 3

 

then It will return the ID of the LQPricebook__c

Abhi_TripathiAbhi_Tripathi
Hey Suneel....
I think you are trying for related fields....if yes then use '__r'.

And if not then brief it what you want to do...specially after that FROM part.
bob_buzzardbob_buzzard

Your SOQL is the wrong way around.  You can use the clm variable on the right hand side, not the left, so you have to invert the operators e.g.:

 

LQPricebook__c.ValidForm__c <= clm.Claim_Invoice_Date__c

 

also, you can't apply calculations to the field value like:

 

LQPricebook__c.ValidForm__c + ((365/12)* 3))

 

You'll have to create a formula field that contains this value and then query against that.

 

suneel.patchipulusu@gmail.comsuneel.patchipulusu@gmail.com

As you said I changed like this

 

lqp = [SELECT ID, Name, ValidForm__c
FROM LQPricebook__c WHERE LQPricebook__r.ValidForm__c <= clm.Claim_Invoice_Date__c
//and (clm.Claim_Invoice_Date__c <=
//LQPricebook__r.ValidForm__c + ((365/12)* 3))
//IsPublished__c =: True
//and Status__c = 'Active'
];

 

This time I want to test only for one condition but I am getting the error this time on

 

Error:'Unexpected token clm.Clain_Invoice_Date__c'

 

I dont have any clue how to solve this???

Could u guys give some ideas 

 

Thanks in advance

 

 

bob_buzzardbob_buzzard

Simple typo - clm needs a : in front of it to make it a bind variable:

 

FROM LQPricebook__c WHERE LQPricebook__r.ValidForm__c <= :clm.Claim_Invoice_Date__c

 

This was selected as the best answer
suneel.patchipulusu@gmail.comsuneel.patchipulusu@gmail.com

Thanks

 

Super!!!!!!