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
Polayya reddyPolayya reddy 

how to create tasks,attachments from Account object.

Hi 

Could you please check the below points and provide your answers

how to Create a  new Account and create a three tasks for it.
how to Create a new Account and attach three attachments for it
how to Write a SOQL to fetch all Accounts including records in Recyclebin.

Thanks
 
Best Answer chosen by Polayya reddy
SandhyaSandhya (Salesforce Developers) 
Hi,

Task is a standard object you can see for every record of standard and custom objects.

Please follow below steps.

Goto--> Accounts-->open any record-->
scrolldown your page

you can see "Open Activities" and "Notes and Attachments."

under Open Activities--->click new task.

Please see below screenshot

User-added image

enter the details for the task you want to assign.

User-added image

In the same way, you can create attachments under Notes and Attachments.

Attach file

User-added image

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi Polayya,

3.how to Write a SOQL to fetch all Accounts including records in Recyclebin.


From apex
System.assertEquals(2, [SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS]);


You cannot do it directly within the Query Editor of developer console but there's a workaround for you to test your query in Developer Console. The workaround is to use the "Execute Anonymous Window".

1. Open "Enter Apex Code" window by selecting "Debug" -> "Open Execute Anonymous Window" menu
2. Enter your query there and output the result to the log. Check the "Open Log" checkbox. 

List<Account> fruits = [SELECT ID FROM Account ALL ROWS];
System.debug(JSON.serialize(fruits);

3. Click "Execute" to run your code and check the log file for your result.


1.how to Create a  new Account and create a three tasks for it.
can you elaborate this (did you mean when ever a record is created three tasks should be created?trigger sort of thing).

Please let us know.


Thanks and Regards
Sandhya
Polayya reddyPolayya reddy
Hi Sandhya,

Thanks for your reply. we need relate task to Account object.Just like Account and contacts.I not found any task object.

Thanks
Polayya reddy
Muneendar POC 6Muneendar POC 6
Please refer the below code..You can create the attachments also like Tasks. 

trigger AccountTrigger on Account (After insert) {
    list<task> taskList=new list<task>();
    for(Account acc:trigger.new){
        Task tskone=Utilities.CreateTask(acc.id,'In progress');
        Task tskotwo=Utilities.CreateTask(acc.id,'In progress');
        Task tskthree=Utilities.CreateTask(acc.id,'In progress');
        taskList.add(tskone);
        taskList.add(tskotwo);
        taskList.add(tskthree);                                   
    }
                                          
insert taskList;                                          
}


public class Utilities {
    public static task CreateTask(String accid,String sub){
        Task tsk=new Task(whatid=accid,Status='In Progress',Subject=sub);
        return tsk;
    }
  
}

 
SandhyaSandhya (Salesforce Developers) 
Hi,

Task is a standard object you can see for every record of standard and custom objects.

Please follow below steps.

Goto--> Accounts-->open any record-->
scrolldown your page

you can see "Open Activities" and "Notes and Attachments."

under Open Activities--->click new task.

Please see below screenshot

User-added image

enter the details for the task you want to assign.

User-added image

In the same way, you can create attachments under Notes and Attachments.

Attach file

User-added image

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
This was selected as the best answer