+ Start a Discussion
Lee YakiwchukLee Yakiwchuk 

Unable to access Address compound field on Lead object in Apex trigger.

This link:
https://help.salesforce.com/apex/HTViewSolution?urlname=Spring-15-Access-Address-and-Geolocation-Compound-Fields-Using-Apex&language=en_US

says I can access Address compound fields from Apex.  I can access Account address fields but on Leads I get the error "Invalid field Address for SObject Lead".  This error when my trigger runs.  There is no error in the Developer console.  Not sure if this is by design or if I amdoing something wrong.  

I have tried just referencing the field, assigning the field to an Address type field, and looking it up in a SOQL query.  I can look the field up in the Execute Anonymous console and it works fine.

Any idea what I am doing wrong?  

Thanks!!
Shailesh DeshpandeShailesh Deshpande
hi Lee;



I am able to access the lead address field in the trigger. Not sure what might be causing you the problem, however you might want to check the version of the class/trigger. I get the above error for versions below 30.


For testing purpose, i used below code and it worked fine. Ofcourse, it is not correct code, but it was just for checking if i am able to access the Address field in the trigger:
trigger AddressField on Lead (before update){

Address addr;

Lead l = [Select Id, Address from Lead where Id=: trigger.new[0].id];
addr = l.address; // l.address
system.debug('============'+addr);
Trigger.new[0].Street = addr.city+addr.State+'XYZ';

}
Thanks,
Shailesh.
Lee YakiwchukLee Yakiwchuk
Hi Shailesh,

I have very similar code and I also do not get an error when saving.  However, when the trigger runs( when I update a lead), it gives the error "Invalid field Address for SObject Lead".  If you are able to update a lead without error, I think I probably need to open a ticket with SF support.

Thanks!!
Lee
Shailesh DeshpandeShailesh Deshpande
Well, thats weird. The trigger does update the lead and I dont get any error while running the trigger. I get the above error, while saving the trigger with versions below 30. Still it might be worth checking the version of your trigger.
Lee YakiwchukLee Yakiwchuk
I'm on 33 and I've tried 30-33.  I've even recreated it. I guess I'll contact SFDC support.  Thanks for your help!!
Varun GuruvugariVarun Guruvugari
@Lee Yakiwchuk: Are you updating the lead on the standard layout or a VF page ? If it is a VF page, what is the version of the VF page ?
Lee YakiwchukLee Yakiwchuk
Hi Varun,

Its a standard layout.  SalesForce support is looking into it.  So we'll see what they come up with and I'll post it back here.

Thanks!
Lee