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

i have created an apex class for creation of tasks in opportunity records

Hi all ,
My requirment is to create sort order for tasks .........
the tasks are created when opportyunity record is created ........
Example : 3)Task3  but i want output has 1)Task1, 2)Task2, 3)Task3  in order
My code :
public class CompsureTasks_helper{
    //Create tasks
    public static void createTasks(List<id> oppId){
    List<Opportunity> oppList = [select id,name,closedate,ownerid,Opportunity_Period__c from Opportunity where id IN : oppId];
    List<Task> insertTasks = new List<Task>();
    for(Opportunity opp : oppList){
    //for Task1
        task t = new task(OwnerId = opp.ownerid,Subject = 'Task1',Status = 'Open',Priority = 'Normal',WhatId = opp.Id);
           integer tt = (integer)Math.round((15*opp.Opportunity_Period__c)/100);
           t.activitydate =*opp.Opportunity_Period__c)/100));
           t.IsReminderSet = true;
           t.ReminderDateTime = t.activitydate;  
    //For Task2   
        task t1 = new task(OwnerId = opp.ownerid,Subject = 'Task2',Status = 'Open',Priority = 'Normal',WhatId = opp.Id);
            t1.activitydate =*opp.Opportunity_Period__c)/100));
            t1.IsReminderSet = true;
            t1.ReminderDateTime = t1.activitydate;  
    //For Task3   
        task t2 = new task(OwnerId = opp.ownerid,Subject = 'Task3',Status = 'Open',Priority = 'Normal',WhatId = opp.Id);
            t2.activitydate =*opp.Opportunity_Period__c)/100));
            t2.IsReminderSet = true;
            t2.ReminderDateTime = t2.activitydate;  
    insert insertTasks;
Hi nihar annamaneni,
your code is working fine. I'm getiing Output  below screenshot
What else you need? please explain brief
hi rajeshkumar,
sorry i did not add some information to my question
when i completed task1 and task2
it showing output has task2
                                   User-added imagetask1
Hi nihar annamaneni,
Sorry, I'm not get your above post. give some more info.
In screen shot right side you can see the tasks......
but the tasks are in the order down to up order............but i want that tasks in reverse order(top to down order)...
that means last task should come first and so on and atlast first task should come last...............