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
Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan) 

One questions about this code snippet

I took this directly off David's blog (http://www.sfdc99.com/2014/02/18/quiz-answers-chapter-4/). Is it possible to use a lead object(dupe) to store contents of a List variable? What purpose does it serve?

dupe = [SELECT Id, Potential_Lead_Dupe__c, Potential_Contact_Dupe__c FROM Lead WHERE Id = :dupe.Id];


 
Lead dupe = new Lead();
    dupe.FirstName = 'Frodo';
    dupe.LastName  = 'Baggins';
    dupe.Company   = 'Shire';
    insert dupe;
    
    dupe = [SELECT Id, Potential_Lead_Dupe__c, 
                   Potential_Contact_Dupe__c 
            FROM Lead 
            WHERE Id = :dupe.Id];
    System.assertEquals(lead1.Id, dupe.Potential_Lead_Dupe__c);
    System.assertEquals(ctc1.Id, dupe.Potential_Contact_Dupe__c);


 
PratikPratik (Salesforce Developers) 
Hi Miragedeb,

Do you want to store the SOQL query result in Dupe variable? if yes then please create a list<lead> to store the SOQL result as it will return the list. 

Thanks,
Pratik
Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan)
Hey Pratik,
You probably misunderstood my question. If you see the code snippet I posted above (it works since it's from David's site and I didn't write it), that is using dupe (an instance of Lead object) to store a SOQL query result. Are we allowed to do that? 
The dupe variable is first declared as an object instance and then the same variable is used for storing a SOQL query result and that is what confuses me.