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
giri rockzzzzgiri rockzzzz 

comparing dynamic id in apex code....plz help

unexpexted token error is shown for the following code:

My id comes dynamically how can i write the query.....plz help

 

public class proitem{

    public String getPro() {
       

        String id = 'a0890000000BLihAAG';
       it=[select name from item__c where product__c =id];
        
       return it;
    }

}

Best Answer chosen by Admin (Salesforce Developers) 
sgm_forcesgm_force

Are you getting the ID from a Visualforce Page?

If you are, then you can use ApexPages.currentPage().getParameters().get('id')

 

Else , try modifying the query as follows :

 

it=[select name from item__c where product__c = :id];

 

 

 

Hope it will be of some help!

All Answers

sgm_forcesgm_force

Are you getting the ID from a Visualforce Page?

If you are, then you can use ApexPages.currentPage().getParameters().get('id')

 

Else , try modifying the query as follows :

 

it=[select name from item__c where product__c = :id];

 

 

 

Hope it will be of some help!

This was selected as the best answer
SSRS2SSRS2

Hello   giri

  Here is the code stuff for creating string Query sample and i think It may help for your scenario.

 String id = 'a0890000000BLihAAG';
//it=[select name from item__c where product__c =id];
String it = 'select name from item__c where product__c =\'' + id + '\'';
/*Dynamic query for above string
item__c item = Database.query(it);
*/

 

-Suresh

 

giri rockzzzzgiri rockzzzz

hello,

thanx for you help...even ur code works thank you very much