Searching object name attached Attachment

takakd

Takahiro Kudo

Posted on December 25, 2019

Searching object name attached Attachment

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);
💖 💪 🙅 🚩
takakd
Takahiro Kudo

Posted on December 25, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Searching object name attached Attachment
salesforceapex Searching object name attached Attachment

December 25, 2019