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
Daniel GageDaniel Gage 

Retrieve value from SOQL results

This seems like a dumb question. So dumb, in fact that I'm having trouble finding the answer to it. To preface. I am not an Apex Developer(I'm a C# guy). I've just been helping out a friend get some stuff done. I've pretty much taken care of all the hardest parts of the code, but this last one is baffling me.

I need to update a field on the Lead record from the results of a SOQL query to a custom entity.

The problem is, I have no idea how to retrieve anything from the query. For most of my coding to now, I've used the List<> to get things to match up right for the rest of the code. But I can't seem to get that field value out of it. Here is the list. Any help... from anyone. (even if it is just to point me in the right direction) would be very helpful. Thanks.
(I need the value in the TFA_Salesforce_ID__c field on the Member_Verification__c Entity as a string value)

   list<String> leadEmails= new list<String>();
    for (Lead lead:Trigger.new) {
        leadEmails.add(lead.Email);
    }
    
    list<Member_Verification__c> emails = [
        Select  id, Primary_Email__c,TFA_Salesforce_ID__c
        from Member_Verification__c
        where (Primary_Email__c != null and Primary_Email__c in :leadEmails)
    ];

 

Best Answer chosen by Daniel Gage
sweetzsweetz
You can retreive as below,
 
string accname;
 accname = [SELECT Id,Name FROM Account LIMIT 1].Name;
 System.debug(accname);
Now you can assign that to a field you want. Hope this helps.

All Answers

sweetzsweetz
So you want to get the TFA id and assign it to some field on the lead object. Am I right?
 
Daniel GageDaniel Gage
correct. and I know this has to be basic 101. but its driven me batty tonight
sweetzsweetz
You can retreive as below,
 
string accname;
 accname = [SELECT Id,Name FROM Account LIMIT 1].Name;
 System.debug(accname);
Now you can assign that to a field you want. Hope this helps.
This was selected as the best answer
Daniel GageDaniel Gage
thank you. will try this is the morning.
sweetzsweetz
Let me know if you need further help. If this answer helped you please close the thread and mark it as the best answer.
Daniel GageDaniel Gage
thanks. I ended up getting it to work with your help. I think it's kind of ugly code, but it is working as expected with 100 percent coverage. Thanks again.