You need to sign in to do that
Don't have an account?
Ruchi Gupta Keshri
Code is not Cover where i am wrong?
@isTest static void testUpsertCase() {
// 1. Insert new record
Lead lead1Id = LeadWebService.upsertLead('Test1', 'Tata', 'Working - Contacted','Web','9999999999',null);
// Verify new record was created
System.assert(lead1Id != null);
Lead lead1 = [SELECT Id,LeadSource FROM Lead WHERE Id=:'00Q5i000005Ot9hEAC'];
System.assert(lead1 != null);
System.assertEquals(lead1.LeadSource, 'Web');
// 2. Update status of existing record to Working
Lead lead2Id = LeadWebService.upsertLead('Test1', 'Tata', 'Open - Not Contacted','Phone Inquiry','9999999999','00Q5i000005Ot9hEAC');
// Verify record was updated
System.assertEquals(lead1Id, lead2Id);
Lead lead2 = [SELECT Id,Status FROM Lead WHERE Id=:'00Q5i000005Ot9hEAC'];
System.assert(lead2 != null);
System.assertEquals(lead2.Status, 'Open - Not Contacted');
}
// 1. Insert new record
Lead lead1Id = LeadWebService.upsertLead('Test1', 'Tata', 'Working - Contacted','Web','9999999999',null);
// Verify new record was created
System.assert(lead1Id != null);
Lead lead1 = [SELECT Id,LeadSource FROM Lead WHERE Id=:'00Q5i000005Ot9hEAC'];
System.assert(lead1 != null);
System.assertEquals(lead1.LeadSource, 'Web');
// 2. Update status of existing record to Working
Lead lead2Id = LeadWebService.upsertLead('Test1', 'Tata', 'Open - Not Contacted','Phone Inquiry','9999999999','00Q5i000005Ot9hEAC');
// Verify record was updated
System.assertEquals(lead1Id, lead2Id);
Lead lead2 = [SELECT Id,Status FROM Lead WHERE Id=:'00Q5i000005Ot9hEAC'];
System.assert(lead2 != null);
System.assertEquals(lead2.Status, 'Open - Not Contacted');
}
Can you try the below test method it will cover 100% code for that method.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Can you share the apex class as you shared the test class. It is very hard to get the code from the screenshot.
Thanks,
global static Lead upsertLead(String name, String company, String status, String leadSource, String phone, string idd) {
RestRequest request= RestContext.request;
String leeId =request.requestURI.substring(request.requestURI.lastIndexOf('/')+1);
lead obj= [select id,Name, Company, LeadSource, Status,ExternalId__c, Phone from Lead where ExternalId__c=:idd Limit 1];
obj.LastName=name;
obj.Company=company;
obj.Status=status;
obj.LeadSource=leadSource;
obj.Phone=phone;
Upsert obj;
return obj;
}
Can you try the below test method it will cover 100% code for that method.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,