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
Dhruv NirgudeDhruv Nirgude 

how to post querries

Hey, In Apex Trigger i have 2 big problems one is method does not exist and last one variable does not exist these shown in Problem tab and that type of issue i saw in every TriggerHandlerClass. So below i mentioned my code.

public class Account2TriggerHandler {
    public static void createRelatedOpp(List<Account> newList){
    List<Opportunity> oppoToBeInserted = new List<Opportunity>();
        for(Account acc : newList){
    Opportunity opp = new Opportunity();
   opp.Name = acc.Name;
   opp.AccountId = Acc.Id;
   opp.StageName = 'Prospecting';
   opp.CloseDate = System.today();
   oppToBeInserted.add(opp);
 }    
      if(!oppToBeInserted.isEmpty()){
       insert oppToBeInserted;
  }
  }
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Dhruv,

Can you also post the trigger as comment below  so we can check what exactly the issue and modify the code accordingly.

Thanks,
 
mukesh guptamukesh gupta
Hi Dhruv, 

Please use below code:-
 
public class Account2TriggerHandler {
    public static void createRelatedOpp(List<Account> newList){
    List<Opportunity> oppToBeInserted = new List<Opportunity>();
        for(Account acc : newList){
    Opportunity opp = new Opportunity();
   opp.Name = acc.Name;
   opp.AccountId = Acc.Id;
   opp.StageName = 'Prospecting';
   opp.CloseDate = System.today();
   oppToBeInserted.add(opp);
 }    
      if(!oppToBeInserted.isEmpty()){
       insert oppToBeInserted;
  }
  }

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
Dhruv NirgudeDhruv Nirgude
Thank you Mukesh for helping me it worked well
mukesh guptamukesh gupta
Hi Dhruv,

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh