I created an apex controller class and i am trying to upload ot to salesforce, i receive many errors, one of them is:"Comparison arguments must be compatible types: System.Address, String" and "Field is not writeable: Contact.Name (30:50)" same error with MailingAddress field. From what i know you can edit the name of a contact and its MailingAddress, i´ll leave my code down below:
@AuraEnabled(cacheable=true)
public static List<Object> searchContacts(String seachTerm) {
List <Contact> result= ([SELECT id,Name,Phone,MailingAddress,Email,Title,Birthdate FROM contact where Name like: '%' + seachTerm +'%']);
return result;
}
@AuraEnabled(cacheable=true)
public static void deleteContact(String conToDelete){
Contact result= ([SELECT id, Name,Phone,MailingAddress,Email,Title,Birthdate FROM contact where Name like: '%' + conToDelete +'%']);
try{
delete result;
}catch(DmlException e){
system.debug(e);
}
}
@AuraEnabled(cacheable=true)
public static void editContact(Contact Contact){
Contact editContact=Contact;
if(editContact.Name!=null || editContact.Name!=''){
Contact result= ([SELECT id,Name,Phone,MailingAddress,Email,Title,Birthdate FROM contact where Name like:'%' + editContact.Name +'%']);
if(editContact.Name!=result.Name){result.Name=editContact.Name;}
if((editContact.Phone!=null || editContact.Phone!='') && editContact.Phone!=result.Phone){result.Phone=editContact.Phone;}
if((editContact.MailingAddress!=null || editContact.MailingAddress!='') && editContact.MailingAddress!=result.MailingAddress){result.MailingAddress=editContact.MailingAddress;}
if((editContact.Email!=null || editContact.Email!='') && editContact.Email!=result.Email){result.Email=editContact.Email;}
if((editContact.Title!=null || editContact.Title!='') && editContact.Title!=result.Title){result.Title=editContact.Title;}
if((editContact.Birthdate!=null || editContact.Birthdate!='') && editContact.Birthdate!=result.Title){result.Birthdate=editContact.Birthdate;}
try{
update result;
}catch(DmlException e){
system.debug(e);
}
}
}
Thank you!