You need to sign in to do that
Don't have an account?
raman123
how can i write test class for below code
trigger populate on project__c (before insert , before update){
MAP<ID , user> mapCon = new MAP<ID , user>([Select id ,name,city
from user
]);
for(project__c obj : trigger.new)
{
if(obj.delivery_location__c == null)
{
user u = mapcon.get(obj.ownerid);
if (u.city != null)
obj.Delivery_location__c=u.city;
else {
obj.Delivery_location__c = 'NA';
}
}
}
}
MAP<ID , user> mapCon = new MAP<ID , user>([Select id ,name,city
from user
]);
for(project__c obj : trigger.new)
{
if(obj.delivery_location__c == null)
{
user u = mapcon.get(obj.ownerid);
if (u.city != null)
obj.Delivery_location__c=u.city;
else {
obj.Delivery_location__c = 'NA';
}
}
}
}
Sorry but first I would like to optimise your code by below code. The reason your code
Starts directly with the SOQL with no where clause or LIMIT which is never efficient. Always make your trigger to focus on the relevant information. This way your code will work in long term. Please also find the test class with 100% converage.
All Answers
Sorry but first I would like to optimise your code by below code. The reason your code
Starts directly with the SOQL with no where clause or LIMIT which is never efficient. Always make your trigger to focus on the relevant information. This way your code will work in long term. Please also find the test class with 100% converage.
Public class ProjectTest {
static testMethod void MTest() {
project__c proj= new project__c();
proj.name = 'Test';
proj.delivery_location__c= '';
insert objAccount;
//User u = [select id,name ,city from user];
}