You need to sign in to do that
Don't have an account?
Alfia Quadri 11
I am new to apex, I am writing an apex class and I have the salesforce id, how do I update the contact record if I have the salesforce id.
Thanks
how to update contact record when salesforce id is available
I am new to apex, I am writing an apex class and I have the salesforce id, how do I update the contact record if I have the salesforce id.
Thanks
You first have to retrive the recordo with a SOQL query and storing in a variable after that, you can use this variable to update record.
Regards
For the above scenerio you can just use the code as below. You may not need to query the contact
just replace the id above with your id and fields as per your requirement.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
As you have contact record id get that record from database using SOQL,Then update the required field value
con.fieldName__c = 'Enter your required value';
update con;
Thanks,
https://www.krowd-darden.com/
public static Contact updateContactDetails(String conId){
for(Contact con:[SELECT Id, FirstName, LastName, Email FROM Contact WHERE Id=conId]){
con.FirstName='Your FirstName';
con.LasttName='Your LasttName';
con.Email='Your Name';
}
update con;
return con;
}
}
contactObject.id='your id';
contactObject.lastname='Test';
update contactObject;
(Please include all mandatory fileds for DML)
Hi Alfia,
If you already know the contact ID, you can use it in the query to retrieve the contact and then update it.
You can use the code below as a refrence.
Please mark it best answer if it helps.
Thanks