1

I have a custom object, Job (Job__c (this is parent)), and another custom object is Job Applicant (Job_Applicant__c (this is child).

How do I get ID from the URL from sc.getRecord().id in the following?

public class Job_Application{
    public Id JobID{get;set;}
    public List<Job__c> Query{get;set;}

    public Job_Application(ApexPages.StandardController sc){

        JobID = sc.getRecord().id;
        System.debug('----Job ID ----- ' + JobID);
        fetchRecords();
    }

    public void fetchRecords(){
        Query = [SELECT Id, (SELECT id, Name, Experience__c, Qualification__c, Score__c, Spoken_Language__c, Technical__c FROM Job_Applicants__r) FROM Job__c WHERE Id =:JobID];

        System.debug('---Query Result ---- ' + Query);
    }
}

This is not working.

7

Have you tried simply:

JobID = sc.getId();

See docs here.

This assumes that the standardController attribute on your page is for Job__c and that the URL is something like /apex/YourPage?id=[some job id].

0

Apexpages is a global variable that you can access from your constructor, probably your problem is the ApexPages.StandardController sc variable that you are passing as an argument in the constructor is probably being declared as null, so:

Just use the following:

JobID = apexpages.currentpage().getparameters().get('id'); 

instead

JobID = sc.getRecord().id;

And remove ApexPages.StandardController sc from the parameters of your constructor, it should work now

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.