• Ben Huri
  • NEWBIE
  • 15 Points
  • Member since 2021
  • Asperii

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hey guys, what is your best suggested way to delete a record with it's related lists and it's look up fields??

I thought to query all records with SOSL by the record Id, but i found out it is not possible (Or there's a way?).

Another option is quering all related lists (with inner loops) and then loop on all related lists (with getPopulatedFieldsAsMap() and delete them list by list.

I would love to hear your best solution in performence terms.

Thanks!
 
User-added image


I am getting 92% coverage , not 100%
Here is my Mockup callout :


@isTest
global class BatchCalloutMock implements HttpCalloutMock {
    global HTTPResponse respond(HTTPRequest req) {
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('test');
        res.setStatusCode(200);
        res.setStatus('Sucess'); 
        return res;
    }
}


Here is my test class :-

@isTest
public class BatchClassOrderPOTestClass {
    static testMethod void testbarchClass(){
        Account newAccountRecord = new Account();
        newAccountRecord.Name = 'Test Account Record';
        insert newAccountRecord;
        Order newOrderRecord = new Order();
        newOrderRecord.AccountId = newAccountRecord.Id;
        newOrderRecord.EffectiveDate = System.today();
        newOrderRecord.Status = 'Draft';
        // insert newAccountRecord;
        insert newOrderRecord;
        List<ID> idd = new List<ID>();
        idd.add(newOrderRecord.id);
        List<Order> recordsToSend = [select id from Order WHERE ID =: newOrderRecord.Id];
        
        Test.setMock(HttpCalloutMock.class, new BatchCalloutMock());
       // Test.startTest();
        BatchClassOrderPO obj = new BatchClassOrderPO(idd);
        
        //cPO newcPO = new cPO(recordsToSend);
        database.executeBatch(obj,25);
       // Test.stopTest();
    }
    
}
Hey guys, what is your best suggested way to delete a record with it's related lists and it's look up fields??

I thought to query all records with SOSL by the record Id, but i found out it is not possible (Or there's a way?).

Another option is quering all related lists (with inner loops) and then loop on all related lists (with getPopulatedFieldsAsMap() and delete them list by list.

I would love to hear your best solution in performence terms.

Thanks!