You need to sign in to do that
Don't have an account?
Dan Rogers
Can access a field in SOQL, can't access it in Apex....?
Hi,
I'm new to Apex Code / SOQL.
I'm trying to write a trigger based on someone's Mailchimp Interest Lists. I can the value I need no problem if I run SOQL directly, e.g.
gives me the result I need:
But whatever I do I can't seem to get access to this value in Apex Code, e.g. this is the trigger:
Results of those debugs:
lead.MC4SF__MC_Subscriber__r.MC4SF__Interests__c = null
lead.MC4SF__MC_Subscriber__c = a0B24000004BPMnEAO
(the SOQL query) sobjList[0] = Lead:{MC4SF__MC_Subscriber__c=a0B24000004BPMnEAO, Id=00Q24000004bfgYEAQ}
Is there anything I can do to get this value :) ? It's driving me crazy.
Cheers!
Dan
I'm new to Apex Code / SOQL.
I'm trying to write a trigger based on someone's Mailchimp Interest Lists. I can the value I need no problem if I run SOQL directly, e.g.
select MC4SF__MC_Subscriber__r.MC4SF__Interests__c from lead where Id = '00Q24000004bfgYEAQ'
gives me the result I need:
But whatever I do I can't seem to get access to this value in Apex Code, e.g. this is the trigger:
trigger updateMCStatus on Lead (after update) { Map<String, Lead> leadMap = new Map<String, Lead>(); for (Lead lead : System.Trigger.new) { System.Debug('lead mc interests: ' + lead.MC4SF__MC_Subscriber__r.MC4SF__Interests__c); System.Debug('lead mc subscriber: ' + lead.MC4SF__MC_Subscriber__c); String query = 'select MC4SF__MC_Subscriber__r.MC4SF__Interests__c from lead where Id = \'' + String.escapeSingleQuotes(lead.Id) + '\''; System.Debug(query); List<sObject> sobjList = Database.query(query); System.Debug('object: ' + sobjList[0]); } }
Results of those debugs:
lead.MC4SF__MC_Subscriber__r.MC4SF__Interests__c = null
lead.MC4SF__MC_Subscriber__c = a0B24000004BPMnEAO
(the SOQL query) sobjList[0] = Lead:{MC4SF__MC_Subscriber__c=a0B24000004BPMnEAO, Id=00Q24000004bfgYEAQ}
Is there anything I can do to get this value :) ? It's driving me crazy.
Cheers!
Dan
All Answers
Is "MC4SF__Interests__c" a different object?
Thanks for your reply, yes it is a different object I think (at least in the schema). This data/schema is from an itegration (mailchimp). It's nested quite heavily;
Leads (and Contacts) are related to an MC_Subscriber object, then that MC_Subscriber object has the Custom Field Interests (which I think is managed / autopopulated somehow... as I said, fairly new to this :) ).
THanks!
Dan
However, you should still be able to get it back in a SOQL query. I would check that you have read (Object CRUD) permission on the MCSF_MC_Subscriber object first, and also that the MCS4SF_Intersests__c field is visible in your FLS or Field Level Security settings. Additionally, it shouldn't matter, but verify that you have visibility to the MC4SF__MC_Subscriber__r record through Org Wide Defaults / Sharing Settings too.
Got it thanks. You were actually both right, I had some FLS that wasn't set, then I retrieved the Interests directly from the Subscriber Object:
Gives me the value I needed (a0324000003mJl8AAE).
Sorry that I can't vote both as best answer, I flipped a coin :D
Thanks for your help!!
Dan