You need to sign in to do that
Don't have an account?
LIM AI KHOON
Code Coverage dynamic SObject
Hi, anyone can help me with how to have 100% code coverage for these lines?
public static void submitFinalApprovalNo(Id recordId) { sObject record = recordId.getSObjectType().newSobject(recordId); record.put('Final_Approved__c',false); update record; }
Don't pass the record type id to method. It's expecting the record Id.
In test class you have to insert the Account record and need to pass the record Id to your actual class. Add if there is any other fields are required to create account in below test class.
I hope you have the Final_Approved__c custom field in Account Object. If it's not account object then you have to insert that particular object in below test class.
Thanks,
Maharajan.C
All Answers
Hi Lim,
Please find the test class with 100% coverage.
You have to get record type Id As the below
Id record=Schema.SObjectType.Account.RecordTypeInfosByName.get('Student').RecordTypeId;
here sobject is Account so replace your Sobject and Recordtype Name is Student so replace student with your subject record type Name.
Please let me know it is working or not.
Please mark it as the Best answer so that other people would take reference from it.
Thank You
I got error in this line
please show me the error.
Have you used your class name of this method submitFinalApprovalNo()
this is my class name SubmitFinal
Account - Potential is label name of record type Right??
please do system.debug(record) and check there is data inside record or not.
Record type name right?
It might be possible, your account does not has this field Final_Approved__c
if account has this field then your record type Account - Potential does not has this field Final_Approved__c
So correct it.
if you replace Final_Approved__c with another standard field then it will give 100% coverage
like record.put('Name','Test');
we cannot change to another standard field, because that class we want to change data in Final_Approved__c to false. Final_Approved__c is a check box type field
GO TO OBJECT MANAGER=>ACCOUNT=>FIELD=>NEW =>Final Approved
DATA TYPE=PICKLIST or Text
if pickList then enter the below values
VALUES=>
True
Flase
Don't pass the record type id to method. It's expecting the record Id.
In test class you have to insert the Account record and need to pass the record Id to your actual class. Add if there is any other fields are required to create account in below test class.
I hope you have the Final_Approved__c custom field in Account Object. If it's not account object then you have to insert that particular object in below test class.
Thanks,
Maharajan.C