0

I have a contructor written as :

public class ABCD{
 Public Employee__c e;
    public ABCD(Employee_c emp){
    this.e=emp;
    methodcalled();
    }
}

Now this methodcalled calls another method , which in turn calls another .

My question - How do I access the Employee id (e /emp) in those methods .

In one of the methods , I need to write something like this :

 SELECT fields from Object where Parentid=emp
  • 2
    'e' is Public property of type 'Employee__c' so it should be available to all methods in the class 'ABCD'. Can you share your complete class code plz. – Mahmood Oct 26 '16 at 13:33
  • 1
    It might be worth your time to run through some of the Apex Trailheads to get a firmer understanding on how apex code operates. – battery.cord Oct 26 '16 at 13:38
3

I think you made some typo in your code, it should be:

this.e = emp;

If you mean same class, you should just use e - since this is class param:

SELECT fields from Object where Parentid =: e.Id

If you need this in some external method you must pass current instance of your class.

  • The whitespace is just personal preference, some developers prefer it, others do not. I have my own preferences on how I use equals, and it's no less "correct" or "incorrect" than the next. – sfdcfox Oct 26 '16 at 20:12
  • 1
    @sfdcfox typo (in fact rather mistake) was about wrong variable placing not whitespaces. Orginally it was "this.emp=e;". Anyway it is good that you are pinting it out, at least some people will now know it is just "coding standard" not APEX syntax. Thanks for you comment :) – Artur Kępczyński Oct 28 '16 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.