• Pravallika Badepally
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
APEX CLASS----
public class LGTN_eArkivInvoiceFiles_LCC {  
    @AuraEnabled 
    public static String getInvoiceContentDocument(String invoiceNumber){
        String contentDocumentId=null;
        String versionIdentifier='Invoice_'+invoiceNumber;
        List<ContentVersion> versions = [Select Id,ContentDocumentId from ContentVersion where eArkivDocumentIdentifier__c=:versionIdentifier];
        if(versions.isEmpty()){
            List< ApexCalloutLog__c > calloutlogsToUpsert = new List< ApexCalloutLog__c > ();
            LGTN_eArkivInvoiceFile_WS eArkiv_ws= new LGTN_eArkivInvoiceFile_WS (invoiceNumber,Label.LGTN_eArkiv_Invoice_IntegrationName,false);
            eArkiv_ws.setEndPoint(eArkiv_ws.endpoint+'='+invoiceNumber);
            eArkiv_ws.send(false);
            calloutlogsToUpsert.addAll(eArkiv_ws.callOutLogs);
            if(eArkiv_ws.callout.error == null) { 
                if(!UTIL_Apex.empty(eArkiv_ws.eArkivInvoiceFileLink)){
                    LGTN_eArkivInvoiceFile_WS eArkiv_File_ws= new LGTN_eArkivInvoiceFile_WS (invoiceNumber,Label.LGTN_eArkiv_Invoice_IntegrationName,true);
                    eArkiv_File_ws.setEndPoint(eArkiv_ws.eArkivInvoiceFileLink); 
                    eArkiv_File_ws.send(false);  
                    if(eArkiv_File_ws.callout.error == null) { 
                        contentDocumentId=eArkiv_File_ws.documentFileId; 
                    }
                    calloutlogsToUpsert.addAll(eArkiv_File_ws.callOutLogs);   
                }
            }
            if(!calloutlogsToUpsert.isEmpty())DataBase.upsert(calloutlogsToUpsert);
        }else{
            contentDocumentId=versions[0].ContentDocumentId;
        }
        return contentDocumentId;
    }
}


I HAVE TRIED THIS TEST CLASS AND GOT CODE CODE COVERAGE OF 71% BUT THE LINES WHICH I HAVE MARKED AS "BOLD" ARE NOT COVERING AND METHOD IS NOT PASSING.PLEASE HELP ME IN THIS.
TEST CLASS----
public class LGTN_eArkivInvoiceFiles_LCC_TEST {
    
    @isTest static void TestgetInvoiceContentDocument()
    {
        UTIL_TestFactory.setUpOrg();
        User tempUser4 = UTIL_TestFactory.createUserWithoutSetup('testsetupOrgUser'+DateTime.now().millisecond()+'@Test14.com','System Administrator');
        System.runAs(tempUser4){
            StaticResourceCalloutMock successfulMock = new StaticResourceCalloutMock();
            successfulMock.setStaticResource('TestInvoiceFiles');
            successfulMock.setStatusCode(200);
            successfulMock.setHeader('Content-Type', 'text/json');
            Test.startTest();
            Test.setMock(HttpCalloutMock.class, successfulMock); 
            LGTN_eArkivInvoiceFiles_LCC.getInvoiceContentDocument('Test');
            Test.stopTest();
            
        }
    }
}
trigger Contract_AfterInsert on Contract__c (after insert) {
    Public Set<Id>conIds=new Set<ID>();
        for (Contract__c con: Trigger.New)
        conIds.add(con.Id);
     ContentWorkspace ws = [SELECT Id, Name, RootContentFolderId FROM ContentWorkspace WHERE Name = 'eArkiv Contract Files'];
     
        String  xmlContent ='test data setup';
        Blob blobContent = Blob.valueOf(xmlContent);
        ContentVersion conver = new ContentVersion();
        conver.title = 'Contrname'; 
        conver.ContentDocument.ParentId = ws.Id;
        conver.PathOnClient = 'test';           
        conver.VersionData = blobContent;     
        insert conver;
        ContentVersion testContent = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :conver.Id];
        
        ContentWorkspaceDoc newWorkspaceDoc = new ContentWorkspaceDoc();        
        newWorkspaceDoc.ContentWorkspaceId = ws.Id; 
        newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId;
        insert newWorkspaceDoc;
}

        
I have written like this but not getting the correct output. Can someone help me in this?
public class LGTN_eArkivInvoiceFiles_LCC {  
    @AuraEnabled 
    public static String getInvoiceContentDocument(String invoiceNumber){
        String contentDocumentId=null;
        String versionIdentifier='Invoice_'+invoiceNumber;
        List<ContentVersion> versions = [Select Id,ContentDocumentId from ContentVersion where eArkivDocumentIdentifier__c=:versionIdentifier];
        if(versions.isEmpty()){
            List< ApexCalloutLog__c > calloutlogsToUpsert = new List< ApexCalloutLog__c > ();
            LGTN_eArkivInvoiceFile_WS eArkiv_ws= new LGTN_eArkivInvoiceFile_WS (invoiceNumber,Label.LGTN_eArkiv_Invoice_IntegrationName,false);
            eArkiv_ws.setEndPoint(eArkiv_ws.endpoint+'='+invoiceNumber);
            eArkiv_ws.send(false);
            calloutlogsToUpsert.addAll(eArkiv_ws.callOutLogs);
            if(eArkiv_ws.callout.error == null) { 
                if(!UTIL_Apex.empty(eArkiv_ws.eArkivInvoiceFileLink)){
                    LGTN_eArkivInvoiceFile_WS eArkiv_File_ws= new LGTN_eArkivInvoiceFile_WS (invoiceNumber,Label.LGTN_eArkiv_Invoice_IntegrationName,true);
                    eArkiv_File_ws.setEndPoint(eArkiv_ws.eArkivInvoiceFileLink); 
                    eArkiv_File_ws.send(false);  
                    if(eArkiv_File_ws.callout.error == null) { 
                        contentDocumentId=eArkiv_File_ws.documentFileId; 
                    }
                    calloutlogsToUpsert.addAll(eArkiv_File_ws.callOutLogs);   
                }
            }
            if(!calloutlogsToUpsert.isEmpty())DataBase.upsert(calloutlogsToUpsert);
        }else{
            contentDocumentId=versions[0].ContentDocumentId;
        }
        return contentDocumentId;
    }
}