You need to sign in to do that
Don't have an account?
shobana shobana
Test class failed ?
Hello everyone
I am new to salesforce
Actually i wrote a test class it showing me error can anyone help to solve this problem.
Thank you in advance
I am new to salesforce
Actually i wrote a test class it showing me error can anyone help to solve this problem.
Apex class public with sharing class UpdateMileStone{ //public Mile_Stone__c mStone {get; set;} public Case__c project; public List<MSList> newMSList{get; set;} public UpdateMileStone(ApexPages.StandardController stdController){ project = (Case__c)stdController.getRecord(); project = [Select Id, (Select Id, Name, Date_Received__c, Description__c, Date_Required_By__c From Required_Documents__r) from Case__c where Id =:project.Id]; newMSList = new List<MSList>(); for(Required_Documents__c m: project.Required_Documents__r){ MSList msListTemp = new MSList(); msListTemp.mStone= m; newMSList.add(msListTemp); } } //Updating Milestone public PageReference updateDocumentRecords(){ List<Required_Documents__c> MSUpdateList = new List<Required_Documents__c>(); for(MSList mTemp: newMSList){ if(mTemp.selectMS){ MSUpdateList.add(mTemp.mStone); } } if(MSUpdateList.size()>0){ update MSUpdateList; }else{ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please select one/multiple Required Documents to update!')); return null; } return new PageReference('/'+project.Id); } // Inner Class to create Payment Schedule with Checkbox public class MSList{ public Boolean selectMS {get; set;} public Required_Documents__c mStone {get; set;} public MSList(){ selectMS=false; } } Test class @IsTest Public class updatemilestone{ static testMethod void testUpdateMileStone(){ Test.startTest(); User usr = new User(Id=UserInfo.getUserId()); System.runAs(usr){ Case__c p1=new Case__c(Name='test1'); insert p1; Required_Documents__c m1=new Required_Documents__c(Name='test2'); m1.Date_Received__c = System.today(); insert m1; ApexPages.StandardController stdcontroller = new ApexPages.Standardcontroller(p1); UpdateMileStone ums = new UpdateMileStone(stdcontroller); ums.updateMileStoneRecords(); Required_Documents__c k=new Required_Documents__c(); k.selectMS= true; } ums.updateDocumentRecords(); } Test.stopTest(); }
Thank you in advance
1 thing which i am seeing is you are not assigning case to Required documents.
And can you please tell the error which you are getting.
Thank you for your replay.
I have changed my code.
Am getting error "Constructor not defined: [updatemilestone].<Constructor>(ApexPages.StandardController) "
workflow is used.
Can you give me a guidelines to solve this issue.
It's showing the error "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it.
Required fields are missing: [Name]: []"
While inserting the record, you are not adding required field in the code. please add required fields also. Regards,