+ Start a Discussion
symantecAPsymantecAP 

Button redirect

I am creating a button on a home page which wud take me to  VF PAGE which shows a Case record in a particular Queue.

I created a button "Accept" and when we click the button it shud get redirected to that case.i am able to get the record on the VF page but however not able to redirect to that record from the VF  Page

 

when iam trying to click Accpet button it takes me toURL which has both record type id and id ...but i juss need id from the queue

 

Here is the code..

public class Getnextcase {

  


   public PageReference Accept() {
    List<Case>cas;
    id caseid;
  cas = [Select id from case c where ownerid=:'00G30000000lZ39' limit 1];
  
    string url = 'https://cs1.salesforce.com/';
    url+=Cas ;
   
    PageReference nextpage = new pagereference( url);
        return nextpage;
        
    }


   

 

    
    List<Case> Cases;
    public List<Case> getCases(){
    Cases = [Select id,casenumber,account.name,contact.name,CreatedDate,Subject,Status from case where Ownerid=:'00G30000000lZ39' order by CreatedDate ASC limit 1];
    return cases;
}
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
mikefmikef

try this:

 

  public PageReference Accept() {
     PageReference p;    
     Case tmpCase;

     try{
         tmpCase = [select id from Case where OwnerId=:'00G30000000lZ39' limit 1];
  
         p = new pagereference('/' + tmpCase.Id);
     }catch(QueryException e){
         //do something with the exception.
     }
      retrun p; 
   }

 

 

All Answers

mikefmikef

try this:

 

  public PageReference Accept() {
     PageReference p;    
     Case tmpCase;

     try{
         tmpCase = [select id from Case where OwnerId=:'00G30000000lZ39' limit 1];
  
         p = new pagereference('/' + tmpCase.Id);
     }catch(QueryException e){
         //do something with the exception.
     }
      retrun p; 
   }

 

 

This was selected as the best answer
symantecAPsymantecAP

Thank you

 

I have modified the code.. I need to change the caseowner on the click of the Accpet button ..the code is saved but i am unable to change the case owner field to the current user.

 

public class Getnextcase {

  


  
  
    List<Case> Cases;
    public List<Case> getcases(){
     Cases = [Select ownerid,casenumber,account.name,contact.name,CreatedDate,Subject,Status from case where Ownerid=:'00G30000000lZ39' order by CreatedDate ASC limit 1];
   return Cases;
    }

   public PageReference Accept() {
     PageReference p;    
     Case tmpCase;

     try{
         tmpCase = [select id from Case where OwnerId=:'00G30000000lZ39' limit 1];
  
         p = new pagereference('/' + tmpCase.Id);
     }catch(QueryException e){
         //do something with the exception.
     }
     for (Case c:Cases){
        if(c.ownerId=='00G30000000lZ39'){
        c.ownerid=Userinfo.getUserid();
        }
        }
     return p;
       
   }
        
        }

 

Thanks again

 

vanessenvanessen

According to the code you are returning to the page before inserting or updating the case.

symantecAPsymantecAP

u r ryt vanessan...i have used the update command and it works fine ....thank u ..