I'm trying to set the country field on the Address object on a Lead. However when I try to do:
mylead.address = my_country_string
It returns the error in the title of this question.
Illegal assignment from String to System.Address
If I try to do:
mylead.adddress.country = my_country_string
It returns the error
Invalid foreign key relationship: Lead.Address at line 55 column 13
How do I set the country field of the address object on a Lead if I already have a lead?
Best Answer
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/compound_fields_address.htm
Address is a compound field, above is documentation for compound fields
Below is Lead Object documentation showing Country for the field on lead
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_lead.htm
You should be using
lead.Country