You need to sign in to do that
Don't have an account?
GGill31
Unexpected token in SOQL query
Hi there,
What can be possible problem in the following code ? Its giving me unexpected token on barcodeID.
My requirement is to fetch the record from Item custom object on the basis of the Barcode_ID and populate the Borrow custom object record using the information from Item object. Borrow object has lookup relationship with Item object. The values for barcode_id and employee_id are coming from the visualforce page.
public class BorrowController {
public String employeeID {get; set;}
public String barcodeID {get; set;}
public BorrowController(){}
public void createBorrowRecord() {
Item__c item = [SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c = barcodeID];
if(item != null) {
Borrow__c b = new Borrow__c();
b.Employee_ID__c = employeeID;
b.Item_ID__c = item.Item_ID__c;
b.Barcode_ID__c = barcodeID;
b.Item_Price__c = item.Price__c;
b.insert;
}
}
public PageReference recordCreation() {
createBorrowRecord();
}
}
Any help would be greatly appreciated!
What can be possible problem in the following code ? Its giving me unexpected token on barcodeID.
My requirement is to fetch the record from Item custom object on the basis of the Barcode_ID and populate the Borrow custom object record using the information from Item object. Borrow object has lookup relationship with Item object. The values for barcode_id and employee_id are coming from the visualforce page.
public class BorrowController {
public String employeeID {get; set;}
public String barcodeID {get; set;}
public BorrowController(){}
public void createBorrowRecord() {
Item__c item = [SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c = barcodeID];
if(item != null) {
Borrow__c b = new Borrow__c();
b.Employee_ID__c = employeeID;
b.Item_ID__c = item.Item_ID__c;
b.Barcode_ID__c = barcodeID;
b.Item_Price__c = item.Price__c;
b.insert;
}
}
public PageReference recordCreation() {
createBorrowRecord();
}
}
Any help would be greatly appreciated!
Change the query to
[SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c =: barcodeID];
I think you missed the ":".
Regards,
Krishna Avva
All Answers
Change the query to
[SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c =: barcodeID];
I think you missed the ":".
Regards,
Krishna Avva
This is what i'm trying to do. Its giving me a 'StringException Id: E-0001'. I have this autonumber employee id in my employee records.
Item__c i = [SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c =: 'K0L7N'];
Borrow__c b = new Borrow__c();
b.Employee_ID__c = 'E-0001';
b.Item_ID__c = i.Item_ID__c;
b.Barcode_ID__c = 'K0L7N';
b.Item_Price__c = i.Price__c;
insert b;
Item_ID is also an autonumber field in Item Object and lookup field in Borrow object.
you don't need colon (:) for values, only used for variables, such as below
string barcodeID='K0L7N';
Item__c i = [SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c =:barcodeID];
try below
Item__c i = [SELECT Name, Item_ID__c, Price__c, Status__c from Item__c where Barcode_ID__c = 'K0L7N' limit 1];
Borrow__c b = new Borrow__c();
b.Employee_ID__c = 'E-0001';
b.Item_ID__c = i.Item_ID__c;
b.Barcode_ID__c = 'K0L7N';
b.Item_Price__c = i.Price__c;
insert b;
is there is an error again, this could be data types