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
Abby StockerAbby Stocker 

Help with this code please!!

I am trying to get the current case record Id. I will be using this class in a trigger. Thank you!!!

public class currentCaseRecord {
    Case currentRecord;
    public currentCaseRecord (Apex Pages.StandardController controller){
        currentRecord = [Select Id FROM Case Where Id =:ApexPages.currentPage().
                getParameters().get('id')];
        }
    public case getcurrentRecord(){
        return currentRecord;
    }
}


Here are the errors I am receiving:
1) Unexpected token '.'.
2)Invalid character in identifier: Pages.StandardController
3)Invalid type: Apex
Best Answer chosen by Abby Stocker
Ahmed Ansari 13Ahmed Ansari 13

Hi Abby Stocker,

TRy THis 

public class currentCaseRecord {
    Case currentRecord;
    public currentCaseRecord (ApexPages.StandardController controller){
        currentRecord = [Select Id FROM Case Where Id =:ApexPages.CurrentPage().getparameters().get('id');
        }
    public case getcurrentRecord(){
        return currentRecord;
    }
}

Thanks

Ahmed Ansari

All Answers

OFröhlichOFröhlich
Hi,
have you had a look at the trigger class definition?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Trigger.htm
Why don't you use trigger new in the trigger?
Ahmed Ansari 13Ahmed Ansari 13

Hi Abby Stocker,

TRy THis 

public class currentCaseRecord {
    Case currentRecord;
    public currentCaseRecord (ApexPages.StandardController controller){
        currentRecord = [Select Id FROM Case Where Id =:ApexPages.CurrentPage().getparameters().get('id');
        }
    public case getcurrentRecord(){
        return currentRecord;
    }
}

Thanks

Ahmed Ansari

This was selected as the best answer
Abby StockerAbby Stocker
No errors! Thank you so much!
Ajay K DubediAjay K Dubedi
Hi Stocker,

* You just need to remove space between ApexPages

* Remove the space :
  
      public currentCaseRecord (Apex Pages.StandardController controller){ 
 
* it should be  :  
 
      public currentCaseRecord (ApexPages.StandardController controller){ 
 

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com