You need to sign in to do that
Don't have an account?
Select fields values
Hi, Please could you help me take one value from a field of object contact? This is my code, it is not working properly(the result is null), the ID 0033000000bOWgWAAW exist and the name of the field is correct, I want to take a value of field address and send it via url to external web service.
contact cont = new contact(Id = '0033000000bOWgWAAW');
string name2 = cont.FirstName; /// the result is null
All this code is inside a class or inside a trigger.
I thing this is a simple thing but I am stuck. (I check the book "apex code developer's guide Version 18").
Thanks in advance
If you want to retrieve the data for that contact you need to make an soql query
What you are doing there is just setting a new contact Object with the id given, but all other fields are null.
To do what you want you need to do the following
contact c = [Select <includes all fields separated by coma you want> From contact Where Id=: <yourid>];
Then if you access to the name for example you will have the value
All Answers
If you want to retrieve the data for that contact you need to make an soql query
What you are doing there is just setting a new contact Object with the id given, but all other fields are null.
To do what you want you need to do the following
contact c = [Select <includes all fields separated by coma you want> From contact Where Id=: <yourid>];
Then if you access to the name for example you will have the value
Thank you very much for your help.