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
Harshal Patil 15Harshal Patil 15 

Hello, Need help

Best Answer chosen by Harshal Patil 15
Khan AnasKhan Anas (Salesforce Developers) 
Hi Harshal,

Greetings to you!

In if condition you need to use == instead of =
oldMaptest1.get(t1.id).subject__c=='America'

Use below code:
public class createTest2whenCreateTest1 {
   
  public static void createtest2(List<test__c> test1list,
                                  Map<id,test__c>oldMaptest1)
  {
      List<test2__c> test2list = new List<test2__c> ();
      for(test__c t1 : test1list )
      {
          if(t1.subject__c=='London' && oldMaptest1.get(t1.id).subject__c=='America') 
          {
              test2__c t2 = new test2__c();
              t2.name='By t1';
              t2.test__c = t1.id;
              t2.status__c='success';
              test2list.add(t2);
             
          }
          insert test2list;
      }
  }
   
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Harshal Patil 15Harshal Patil 15
got a error : Expression cannot be assigned.


public class createTest2whenCreateTest1 {
   
  public static void createtest2(List<test__c> test1list,
                                  Map<id,test__c>oldMaptest1)
  {
      List<test2__c> test2list = new List<test2__c> ();
      for(test__c t1 : test1list )
      {
          if(t1.subject__c=='London' && oldMaptest1.get(t1.id).subject__c='America') 
          {
              test2__c t2 = new test2__c();
              t2.name='By t1';
              t2.test__c = t1.id;
              t2.status__c='success';
              test2list.add(t2);
             
          }
          insert test2list;
      }
  }
   
}
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Harshal,

Greetings to you!

In if condition you need to use == instead of =
oldMaptest1.get(t1.id).subject__c=='America'

Use below code:
public class createTest2whenCreateTest1 {
   
  public static void createtest2(List<test__c> test1list,
                                  Map<id,test__c>oldMaptest1)
  {
      List<test2__c> test2list = new List<test2__c> ();
      for(test__c t1 : test1list )
      {
          if(t1.subject__c=='London' && oldMaptest1.get(t1.id).subject__c=='America') 
          {
              test2__c t2 = new test2__c();
              t2.name='By t1';
              t2.test__c = t1.id;
              t2.status__c='success';
              test2list.add(t2);
             
          }
          insert test2list;
      }
  }
   
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Harshal Patil 15Harshal Patil 15
Great ! it work.
Thank you.