You need to sign in to do that
Don't have an account?
bhanu_prakash
field_custom_validation_exception, assignment project must match expense report project.
Hi
iam facing below erroron test class actually error with validation rule and it is managed pacakage, how can i fix it but modification my code and i need a test class to reslove that issue
field_custom_validation_exception, assignment project must match expense report project.
trigger UpdateCompany on Expense_Report__c (before insert) {
Set<Id> resourceId = new Set<Id>();
Map<Id,Id> resourceIdVsRegionsId = new Map<Id,Id>();
Map<Id,Id> mapRegionToCompanyName = new Map<Id,Id>();
for(Expense_Report__c expRep: Trigger.New){
if(expRep.Resource__c!= Null){
resourceId.add(expRep.Resource__c);
}
}
if(resourceId.size() >0){
for(Contact resourceObj : [select id,Region__c from Contact where id in:resourceId]){
if(resourceObj.Region__c != Null){
resourceIdVsRegionsId.put(resourceObj.Id, resourceObj.Region__c);
}
}
if(resourceIdVsRegionsId.size() >0){
for(Region__c regionObj :[Select Id,ffpsai__OwnerCompany__c from Region__c where Id IN: resourceIdVsRegionsId.values()]){
if(regionObj.ffpsai__OwnerCompany__c != Null){
mapRegionToCompanyName.put(regionObj.id,regionObj.ffpsai__OwnerCompany__c);
}
}
for(Expense_Report__c expRepObj: Trigger.New){
expRepObj.ffpsai__OwnerCompany__c = mapRegionToCompanyName.get(resourceIdVsRegionsId.get(expRepObj.Resource__c));
}
}
}
iam facing below erroron test class actually error with validation rule and it is managed pacakage, how can i fix it but modification my code and i need a test class to reslove that issue
field_custom_validation_exception, assignment project must match expense report project.
trigger UpdateCompany on Expense_Report__c (before insert) {
Set<Id> resourceId = new Set<Id>();
Map<Id,Id> resourceIdVsRegionsId = new Map<Id,Id>();
Map<Id,Id> mapRegionToCompanyName = new Map<Id,Id>();
for(Expense_Report__c expRep: Trigger.New){
if(expRep.Resource__c!= Null){
resourceId.add(expRep.Resource__c);
}
}
if(resourceId.size() >0){
for(Contact resourceObj : [select id,Region__c from Contact where id in:resourceId]){
if(resourceObj.Region__c != Null){
resourceIdVsRegionsId.put(resourceObj.Id, resourceObj.Region__c);
}
}
if(resourceIdVsRegionsId.size() >0){
for(Region__c regionObj :[Select Id,ffpsai__OwnerCompany__c from Region__c where Id IN: resourceIdVsRegionsId.values()]){
if(regionObj.ffpsai__OwnerCompany__c != Null){
mapRegionToCompanyName.put(regionObj.id,regionObj.ffpsai__OwnerCompany__c);
}
}
for(Expense_Report__c expRepObj: Trigger.New){
expRepObj.ffpsai__OwnerCompany__c = mapRegionToCompanyName.get(resourceIdVsRegionsId.get(expRepObj.Resource__c));
}
}
}
@isTest public class updatecompanyTest { static testmethod void myunittest(){ region__c r = new region__c(Name ='China'); insert r; Company__c com = new Company__c(Name ='Infosys'); insert com; Expense_Report__c er = new Expense_Report__c(Name='Travel',region__c= r.id,Company__c= com.id); insert er; Expense_Report__c erc = [SELECT Id, Company__c, name FROM Expense_Report__c]; test.starttest(); update erc; test.stopTest(); } }
still getting error with validation ruel "field_custom_validation_exception, assignment project must match expense report project."
You have a validation rule on Expense report which causes an error. insert Expense_Report__c object along with assignment project to pass the test class.
Thansk ,
Raj