You need to sign in to do that
Don't have an account?
Jon Foy
Need Help Writing an Apex Class for the following Trigger
trigger UpdateTimeSlip on TimeSlip__c (before insert, before update){
Map<Id,Id> caseResourceMap = new Map<Id,Id>();
String userId = userInfo.getUserId();
String userName = userInfo.getName();
Set<Id> caseIds = new Set<Id>();
for(TimeSlip__c ts : trigger.new){
caseIds.add(ts.Case__c);
}
for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){
caseResourceMap.put(caseResource.Case__c,caseResource.Id);
}
List<Contact> contactList = [select id,Name from Contact where Name =: userName];
System.debug('contactList '+contactList );
for(TimeSlip__c ts : trigger.new){
if(ts.Resource_Name__c == null){
if(contactList[0].Id != null){
ts.Resource_Name__c = contactList[0].Id;
}
}
if(ts.Case_Resource_ID__c == null){
if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){
ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
}
}
}
}
Map<Id,Id> caseResourceMap = new Map<Id,Id>();
String userId = userInfo.getUserId();
String userName = userInfo.getName();
Set<Id> caseIds = new Set<Id>();
for(TimeSlip__c ts : trigger.new){
caseIds.add(ts.Case__c);
}
for(Case_Resource__c caseResource : [select id,Case__c from Case_Resource__c where Resource_Name__c =: userId and Case__c IN: caseIds ]){
caseResourceMap.put(caseResource.Case__c,caseResource.Id);
}
List<Contact> contactList = [select id,Name from Contact where Name =: userName];
System.debug('contactList '+contactList );
for(TimeSlip__c ts : trigger.new){
if(ts.Resource_Name__c == null){
if(contactList[0].Id != null){
ts.Resource_Name__c = contactList[0].Id;
}
}
if(ts.Case_Resource_ID__c == null){
if(caseResourceMap.containsKey(ts.Case__c) && caseResourceMap.get(ts.Case__c) !=null){
ts.Case_Resource_ID__c = caseResourceMap.get(ts.Case__c);
}
}
}
}
you can try this code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
Now go to setup --> app setup --> develop --> apex class --> new
and paste below code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
shouldn't it start with @istest?
Can you please share the screenshot of that error?
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
UpdateTimeSlip
Time Started 8/29/2014 11:05 AM
Class TimeSlipTestClass
Method Name timeSlipTestMethod
Pass/Fail Fail
Error Message System.DmlException: Insert failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, E-mail: invalid email address: standarduser123testorg.com: [Email]
Stack Trace Class.TimeSlipTestClass.timeSlipTestMethod: line 10, column 1
TimeSlipTestClass timeSlipTestMethod System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Resource Name: id value of incorrect type: 005A0000005ZCNIIA4: [Resource_Name__c]
Stack Trace: Class.TimeSlipTestClass.timeSlipTestMethod: line 25, column 1
FYI, I had to change the field name from Case_Resource_Name__c to Resource_Name__c
So for this you just have to replace 24th line with below code:
This will solve your problem..:)
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal