• joseph nix
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi, I am new to Apex. I have the below doubt,
trigger ClosedOpportunity on Opportunity (after update) {
    List<task> carry=New List<task>();
    for(opportunity opp:trigger.new){
    if(opp.stagename=='Closed won'){
     task t=new task(
         whatid=opp.id,
         status='Active',
         Subject='Follow Up Opp Task',
         ActivityDate=system.today()
     ) ; 
        carry.add(t);
    }
        }
    insert carry;
}
In the above, code. Its working when i am putting "Insert carry" But not working if i want to put "Insert t", As i can see both are instances created, so why do i have to create "carry" and add "t" in that. Why not i can "insert t" directly ?