+ Start a Discussion
Puja ChoudharyPuja Choudhary 

passing id of a record in url (its taking null)

I have a custom object Order__c with fields Tables__c(Table No) and Status__c(Picklist-In Progress/Completed). 
Another object Table__c having table no.
In the first page i have a lookup saying enter table number.....once i select a table no. and click next then from Order__c object i want to check if there is a record in custom order object with the table no. which i selected and status is equal to "In Progress".
if yes I want to store the existing order id in a variable 'existingorderid' and pass it in URL.
if no then set the existing order id as null.
Code-:
public with sharing class ctr_firstController {
 
       Public String tout { get; set;}
       Public String tablen{get;set;}
       Public  Tables__c  Table{get;set;}
       Public  Tables__c  Table1{get;set;}
       
       Public List<Order__c> eoid{get;set;}
       Public String exoid {get;set;}
       public String existingorderid {get;set;}
       
    public  ctr_firstController(){        
       Table = new Tables__c();
             
   }
   
   public Tables__c getTables() {
        return Table1;
    }

    public PageReference go() {
        
        String tableno =Table.TablesLU__c; 
       Table1 =  [select id, Name, Reserved__c from Tables__c where id=:tableno limit 1];
       Table1.Reserved__c= True;
       update Table1;
       
       eoid = [select id, name, Tables__c ,Status__c from Order__c where Tables__c=:Table1.Name and Status__c=:'In Progress' limit 1];
       if(eoid.size()>0)
           existingorderid = eoid[0].id;
       else
           existingorderid = null;

        pagereference ref = new pagereference('/apex/vfp_Home?exoid='+existingorderid+'&tablen='+tableno+'&tout=false');
        ref.setredirect(true);
        return ref;
        
        
    }




WHEN I AM USING THIS CODE ,THE NEXT PAGE URL IS SHOWING(exoid=null) instead of showing the id
https://c.cs58.visual.force.com/apex/vfp_Home?exoid=null&tablen=a050l000000FyRAAA0&tout=false
Best Answer chosen by Puja Choudhary
Waqar Hussain SFWaqar Hussain SF
Hello Puja,

Please debug the table name and be sure you are getting table1 name and getting records in list.
 
public with sharing class ctr_firstController {
 
       Public String tout { get; set;}
       Public String tablen{get;set;}
       Public  Tables__c  Table{get;set;}
       Public  Tables__c  Table1{get;set;}
       
       Public List<Order__c> eoid{get;set;}
       Public String exoid {get;set;}
       public String existingorderid {get;set;}
       
    public  ctr_firstController(){        
       Table = new Tables__c();
             
   }
   
   public Tables__c getTables() {
        return Table1;
    }

    public PageReference go() {
        
        String tableno =Table.TablesLU__c; 
       Table1 =  [select id, Name, Reserved__c from Tables__c where id=:tableno limit 1];
       Table1.Reserved__c= True;
       update Table1;
       
	   system.debug('table name:: '+Table1.Name);
       eoid = [select id, name, Tables__c ,Status__c from Order__c where Tables__c=:Table1.Name and Status__c='In Progress' limit 1];
	   
	   system.debug('records:: '+eoid);
	   
       if(eoid.size()>0)
           existingorderid = eoid[0].id;
       else
           existingorderid = null;

        pagereference ref = new pagereference('/apex/vfp_Home?exoid='+existingorderid+'&tablen='+tableno+'&tout=false');
        ref.setredirect(true);
        return ref;
        
    }
}


 

All Answers

Waqar Hussain SFWaqar Hussain SF
Hello Puja,

Please debug the table name and be sure you are getting table1 name and getting records in list.
 
public with sharing class ctr_firstController {
 
       Public String tout { get; set;}
       Public String tablen{get;set;}
       Public  Tables__c  Table{get;set;}
       Public  Tables__c  Table1{get;set;}
       
       Public List<Order__c> eoid{get;set;}
       Public String exoid {get;set;}
       public String existingorderid {get;set;}
       
    public  ctr_firstController(){        
       Table = new Tables__c();
             
   }
   
   public Tables__c getTables() {
        return Table1;
    }

    public PageReference go() {
        
        String tableno =Table.TablesLU__c; 
       Table1 =  [select id, Name, Reserved__c from Tables__c where id=:tableno limit 1];
       Table1.Reserved__c= True;
       update Table1;
       
	   system.debug('table name:: '+Table1.Name);
       eoid = [select id, name, Tables__c ,Status__c from Order__c where Tables__c=:Table1.Name and Status__c='In Progress' limit 1];
	   
	   system.debug('records:: '+eoid);
	   
       if(eoid.size()>0)
           existingorderid = eoid[0].id;
       else
           existingorderid = null;

        pagereference ref = new pagereference('/apex/vfp_Home?exoid='+existingorderid+'&tablen='+tableno+'&tout=false');
        ref.setredirect(true);
        return ref;
        
    }
}


 
This was selected as the best answer
Jyotirmaya Rath 10Jyotirmaya Rath 10
Please Debug the Query for Order__c  And the table Name
System.debug('Table1.Name ' + Table1.Name); 
System.debug( [select id, name, Tables__c ,Status__c from Order__c where Tables__c=:Table1.Name and Status__c=:'In Progress' limit 1]);
If you get a record your code is fine and it will work

Jyotirmaya
Puja ChoudharyPuja Choudhary
Thank you for the help. :)