DEV Community

Takahiro Kudo
Takahiro Kudo

Posted on

2 2

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);

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay