You need to sign in to do that
Don't have an account?
yash mehta 12
Can anyone help to write test class ?
trigger majorIdonApplication on Application__c (before insert,before update) {
Set<String>majorName = new Set<string>();
Set<Id>majorNameset = new Set<Id>();
for(Application__c application : Trigger.new){
if(application.Intended_Major__c !=null){
majorName.add(application.Intended_Major__c);
}
}
for(Major__c major : [SELECT id,Name FROM Major__c WHERE name In : majorName]){
majorNameset.add(major.Id);
}
for(Application__c app : Trigger.new){
for(Id Child : majorNameset){
app.Major_Interest__c = Child;
}
}
}
Set<String>majorName = new Set<string>();
Set<Id>majorNameset = new Set<Id>();
for(Application__c application : Trigger.new){
if(application.Intended_Major__c !=null){
majorName.add(application.Intended_Major__c);
}
}
for(Major__c major : [SELECT id,Name FROM Major__c WHERE name In : majorName]){
majorNameset.add(major.Id);
}
for(Application__c app : Trigger.new){
for(Id Child : majorNameset){
app.Major_Interest__c = Child;
}
}
}
- Hope it will be helpful.
Please mark it as best answer if the information is informative.Thanks
Rahul Kumar
Please try below code and let me know if it helps you.
@isTest
private class majorIdonApplicationTest{
static testMethod void testTriggerBeforeInsertforApp(){
Major__c majorObject = new Major__c();
majorObject.Name='Test Major';
insert majorObject;
Application__c applicationObj = new Application__c();
applicationObj.Intended_Major__c=majorObject.Name;
// the insert call : will test before insert
insert applicationObj;
Major__c majorObjectForUpdate = new Major__c();
majorObjectForUpdate.Name='Test Major1';
insert majorObjectForUpdate;
Application__c insertedApp = [Select Id,Intended_Major__c from Application__c Limit 1];
insertedApp.Intended_Major__c=majorObjectForUpdate.Name;
// the insert call : will test before update
update insertedApp;
}
}
Regards,
Pawan Kumar