0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

メモがある取引先責任者を抽出する

Posted at

直接抽出するのは難しいのでApexバッチで取引先責任者にマークをつけて、あとはレポートで対応することとします。

I would like to export contacts with notes

public class BAT_findNote_Contact implements Database.Batchable<sObject> {
    
    // *******************************************************************************************
    //    
    // BAT_findNote_Contact bat  = new BAT_findNote_Contact();
    // ID jobId = Database.executeBatch(bat);                                 
    //                                                                                
    // ********************************************************************************************
    
    public Database.QueryLocator start(Database.BatchableContext BC) {
        // collect the batches of records or objects to be passed to execute
        
        String query = 'Select Id From Contact WHERE isNote__c =False ';
        System.debug('******** query ' + query);
        return Database.getQueryLocator(query);
    }
    
    public void execute(Database.BatchableContext BC, List<Contact> conList) {
        
        System.debug('******** comList ' + conList);
        Set<Id> ConIdSet = new Set<Id>();
        for (Contact c : conList ){
            ConIdSet.add(c.Id);
        }
        system.debug('### ConIdSet ############ ----> '+ ConIdSet.size() );    
        
        List<ContentDocumentLink> CDLList = [SELECT Id,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId =: ConIdSet ];
		system.debug('### CDLList ############ ----> '+ CDLList.size() );                 
        List<Contact> updateContactList = new List<Contact>();    
        
        for (ContentDocumentLink CDL : CDLList ){
            Contact con = new Contact();
            con.Id = CDL.LinkedEntityId;
            con.isNote__c = True;
            updateContactList.add(con);
        }
        
        try {       
            
            system.debug('### updateContactList ############ ----> '+ updateContactList.size() );                 
            if(updateContactList.size() > 0) update updateContactList;
            
        } catch(Exception e) {
            System.debug(e);
        }
        
    }
    
    public void finish(Database.BatchableContext BC) {
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?