You need to sign in to do that
Don't have an account?
Batmansfdc
Can some one help me with writing a test class with this apex class?
public without sharing class CreateContactController {
@AuraEnabled
public static Id createRecord (Contact contact){
System.debug('Inserting contact with:' + contact.FirstName + contact.LastName + contact.Email);
Id returnID = null;
if(contact != null){
User u = [SELECT Id, Contact.AccountId FROM User WHERE Id = :UserInfo.getUserId()][0];
contact.AccountId = u.Contact.AccountId;
insert contact;
returnId = contact.Id;
}
else {
System.debug('Could not insert.');
}
return returnId;
}
}
@AuraEnabled
public static Id createRecord (Contact contact){
System.debug('Inserting contact with:' + contact.FirstName + contact.LastName + contact.Email);
Id returnID = null;
if(contact != null){
User u = [SELECT Id, Contact.AccountId FROM User WHERE Id = :UserInfo.getUserId()][0];
contact.AccountId = u.Contact.AccountId;
insert contact;
returnId = contact.Id;
}
else {
System.debug('Could not insert.');
}
return returnId;
}
}
remove your first debug or it will not work, also you have to have a contact assosiated to your user
Please try below code .
Hope this will helpful for you.Please mark as best answer if it will help you.
Thanks,
system.queryexception list has no rows for assignment to sobject in test class
Make sure you have modified the SOQL with the variables relevant to your org.