function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
yash mehta 12yash 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 :{
        if(application.Intended_Major__c !=null){
    for(Major__c major : [SELECT id,Name FROM Major__c WHERE name In : majorName]){
    for(Application__c app :{
        for(Id Child : majorNameset){
            app.Major_Interest__c = Child;
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Yash Mehta,
  • Hope it will be helpful.
Please mark it as best answer if the information is informative.

Rahul Kumar

Hi Yes,
Please try below code and let me know if it helps you.

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();
// 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];
// the insert call : will test before update
update insertedApp;


Pawan Kumar
please let me know if it works for you.