You need to sign in to do that
Don't have an account?
Akash Garg 2
how to write rest class test class for apex class for code coverage over 75%
Hi
I'm new to salesforce.
Can anyone help in writing the test class.
need urgently.
Please guide and help
I'm new to salesforce.
Can anyone help in writing the test class.
global class tridentUpdateOverduePGLWebService { webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) { //HttpRequest req = new HttpRequest(); //req.setHeader('Content-Type','application/x-www-form-urlencoded'); SFAResponse objResponse = new SFAResponse(); Exceptions__c excep = new Exceptions__c(); // to capture web service failure exceptions. list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{}; for (Integer i=0; i<OverdueRec.size();i++) { OverDue_PGL__c OverDueObj= new OverDue_PGL__c(); OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new; OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new; OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new; OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new; OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new; OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new; OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new; OverdueLst.add(OverDueObj); system.debug('Values taken'); } if (Overduelst.size()>0) { try { insert OverdueLst; objResponse.Status = true; objResponse.Description = 'Record Updated'; system.debug('Record Updated'); } catch(exception e) { system.debug('Error'); excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c; excep.error__c = e.getmessage(); insert excep; //objResponse.SFDCId = OverdueLst.CustName; objResponse.Status = false; objResponse.Description = e.getmessage(); } } else { objResponse.Status = false; objResponse.Description ='No Item found to update'; system.debug('Record not Updated'); } return objResponse; // this will return result. } global class Overdue_element { webservice string CustomerName_name1_new; webservice string Total_Outstanding_INR_DMBTR_new; webservice string Payment_Term_Zterm_new; webservice string Overdue_Amount_INR_ovr_amt_new; webservice string Ageing_Days_days_new; webservice string Excise_Invoice_exnum_new; webservice string Item_Text_sgtxt_new; } global class SFAResponse { //webservice Id SFDCId; webservice Boolean Status; webservice String Description; } }
need urgently.
Please guide and help
Please let me know if it helps.
All Answers
Here is the code
rajamohan vakati 17
I have tried your mentioned code.
Its works but gives only 72 % code coverage.
please help to increase the code coverage.
Alberto OM
Can you please write code as i'm new to coding and i have no idea what are you saying to do.
Add the code as per Alberto OM . it will cover catch block.
Thanks ,
Raj
Alberto
I have added the new code lines but nothing happens.
Still it is giving 72% code coverage.
Please help as i have stuck badly in this.
Please let me know if it helps.
this is still giving 72 % code coverage.
Ch Nagendra Prasad
Code works and it is now giving me 93% code coverage.
Thanks u very much.
can anyone also help in writing test class of following apex class:-
is there any issue with the code above
I'm very sorry to say this and I don't want to sound unpolite, but the issue is with your attitude. You should have learned from the previous test method, and apply the knowledge to the second one, instead of pretending to have your work done by the community...
Just my opinion though...
I have tried test class but it only gives me 72% code coverage.
Can anyone help in increasing the code coverage.