DEV Community

loading...

Searching object name attached Attachment

takakd profile image Takahiro Kudo ・1 min read

I had to extrace object name attached Attachment object when I copy object records to new Salesforce Org.

// Get Attachments
List<Attachment> atts = [SELECT ParentId From Attachment];
Set<Id> idSet = new Set<Id>();
for (Attachment att : atts) {
    idSet.add(att.ParentId);
}

// Get Object Name
Set<String> objSet = new Set<String>();
for (Id rid : idSet) {
  Schema.SObjectType name = rid.getSObjectType();
  objSet.add(String.valueOf(name));
}

// dump
System.debug(objSet);

Discussion (0)

pic
Editor guide