Tag Archives: Notes

Redirect To Standard New Note & New Attachment Pages Using Apex

Redirect to New Attachment:

public PageReference redirectToNewAttachment() {
   PageReference pgRef = new pageReference('/p/attach/NoteAttach?pid=' + String.valueof(acc.Id).subString(0, 15) + '&retURL=' + acc.Id);
   pgRef.setRedirect(true);
   return pgRef;
}

Redirect to New Note:

public PageReference redirectToNewNote() {
   PageReference pgRef = new pageReference('/002/e?parent_id=' + String.valueof(acc.Id).subString(0, 15) + '&retURL=' + acc.Id);
   pgRef.setRedirect(true);
   return pgRef;
}

SOQL Query for Tasks, Notes and Events by Object Type

Tasks:

//The below query returns a list of Tasks related to Leads
SELECT Id, Who.Id, Who.Type FROM Task WHERE Who.Type = 'Lead'

Notes:

//The below query returns a list of Notes where the parent is a specific type, in this case Opportunity
SELECT Id, Parent.Id, Parent.Type FROM Note WHERE Parent.Type = 'Opportunity'

Events:

//The below query returns a list of Events related to Account and Opportunity
SELECT Id, Subject, What.Type, whatId FROM Event WHERE What.Type IN ('Account', 'Opportunity')