Skip to main content

Hello, I am trying to export some contacts from a user that is migrating and he wants to have the notes that he added for some contacts. I tried to run a report but I can not add notes to a contact report. I tried Dataloader but I can not get together contact and notes. Does anyone know? Thanks

3 Antworten
  1. 1. Mai 2022, 05:12

    Hi ,

     

    1. Add a checkbox called isNote__c to the contact.

    2. Use the following Apex batch to set this field to True if a note exists.

     

    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/9000