You need to sign in to do that
Don't have an account?
Tejas Wadke 5
Need test class for following code
Hello,
---------TRIGGER----------
trigger UpdateReportName on ActivityPlanningAndReport__c (before insert) {
Map<Id,User> ownerMap;
Set<Id> oppOwnerIds = new Set<Id>();
String nameOfOwner;
for(ActivityPlanningAndReport__c p : trigger.new)
{
oppOwnerIds.add(p.OwnerId);
}
ownerMap = new Map<Id,User>([SELECT Id, Name FROM User WHERE Id IN :oppOwnerIds]);
for(ActivityPlanningAndReport__c p : trigger.new)
{
nameOfOwner = ownerMap.get(p.OwnerId).Name;
if(p.Name!=null)
{
p.Name = p.Country_txt__c+'_'+ p.Display_Engagement_Date__c+'_'+nameOfOwner;
}
}
}
---------TRIGGER----------
trigger UpdateReportName on ActivityPlanningAndReport__c (before insert) {
Map<Id,User> ownerMap;
Set<Id> oppOwnerIds = new Set<Id>();
String nameOfOwner;
for(ActivityPlanningAndReport__c p : trigger.new)
{
oppOwnerIds.add(p.OwnerId);
}
ownerMap = new Map<Id,User>([SELECT Id, Name FROM User WHERE Id IN :oppOwnerIds]);
for(ActivityPlanningAndReport__c p : trigger.new)
{
nameOfOwner = ownerMap.get(p.OwnerId).Name;
if(p.Name!=null)
{
p.Name = p.Country_txt__c+'_'+ p.Display_Engagement_Date__c+'_'+nameOfOwner;
}
}
}
Here is the test class. I coded it in note pad, so there might be small typos in code, plese correct it
Thanks,
Nagendra
static testmethod void testUpdateReportName(){
ActivityPlanningAndReport__c apr = new ActivityPlanningAndReport__c(Name='' Country_txt__c+'_'+ Display_Engagement_Date__c+'_''+userinfo.getname(),Country_txt__c='Test txt',OwnerId=Userinfo.getUserId()); insert apr; System.assertEquals(apr.Name, 'Country_txt__c+'_'+ Display_Engagement_Date__c+Userinfo.getName());
}
}
Try this you will get your 100% coverege
mark it as correct answer,if it helps you out.
Thanks
Shouldnt we create Account,Opportunity instances and then create the custom object instance ?
Also "OwnerId=Userinfo.getUserId());" how does this work?
Thanks