You need to sign in to do that
Don't have an account?
Abel Palma
Test class with id
I´m trying to make the test class of this, but I having problems, I have an error......System.StringException: Invalid id: Colaborador__c:{Id=a0Of4000003bHFxEAM}
this is my apex class
This is the test class that I´m doing
this is my apex class
public class ActionColocarCls { @AuraEnabled public static Colaborador__c getAccountData (Id accountId){ Colaborador__c searchAcc = new Colaborador__c(); searchAcc = [SELECT Name, Empresa__c, Sector__c, Capability__c,Nivel__c FROM Colaborador__C WHERE Id =: accountId]; system.debug('Account: ' + searchAcc); return searchAcc; } }
This is the test class that I´m doing
@isTest global class ActionColocarClsTest { @testSetup static void setup() { Profile profileAdmin = [SELECT Id FROM Profile WHERE name = 'System Administrator']; UserRole roleAdmin=[SELECT Id FROM UserRole WHERE PortalType = 'None' Limit 1]; User user_test=new User(UserRoleId = roleAdmin.Id, ProfileId = profileAdmin.Id, Username='contactAdmin@deloitte.com', Alias='Admin', Email = 'contactAdmin@deloitte.com', EmailEncodingKey = 'UTF-8', Firstname = 'test', Lastname = 'user', languagelocalekey= 'en_US', LocaleSidKey = 'en_Us', TimeZoneSidKey = 'America/Chicago'); insert user_test; User userAdmin=[SELECT id FROM User WHERE email = 'contactAdmin@deloitte.com' LIMIT 1]; System.runAs(userAdmin){ Colaborador__c con = new Colaborador__c(); con.Name='Joe'; con.ApellidoMaterno__c='Vargas'; con.ApellidoPaterno__c='Medina'; con.Empresa__c='Deloitte'; con.Sector__c='Digital'; con.Capability__c='SalesForce'; con.Nivel__c='Analista'; insert con; Colaborador__c objCol =[SELECT id,Name, Empresa__c, Sector__c, Capability__c,Nivel__c FROM Colaborador__C]; } } static testmethod void tesActionColocar(){ Test.startTest(); Colaborador__c objCol2 = [SELECT id FROM Colaborador__C LIMIT 1]; String accountId=String.valueOf(objCol2) ; system.debug('resumen' + objCol2); ActionColocarCls.getAccountData(accountId); Colaborador__c objColaborador = [SELECT Name, Empresa__c, Sector__c, Capability__c,Nivel__c FROM Colaborador__c WHERE Id =:accountId]; system.debug('Taer records de colaboradores' +objColaborador); Test.stopTest(); } }
All Answers
The test code becomes