You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Create test class for campaign apex class
Hello, I tried to make a test class for my apex but I still get errors.
Could you give me some support:
Apex class
My test class to this point:
I get the error message: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LinkedEntityId]: [LinkedEntityId]
Could you give me some support:
Apex class
public class Kampagne_Brief{ public string camId {get;set;} @InvocableMethod(Label = 'Kampagne_Brief' description='') public static void Kampagne_Brief(List<Id> CampaignId) { string camName = [SELECT Id, Name FROM Campaign WHERE Id =: CampaignId.get(0) LIMIT 1].Name; String strDate = String.valueOf(System.now().dateGmt()); // FORMAT YYYY-MM-DD // String strDate = System.now().format('yyyyMMdd'); // FORMAT YYYYMMDD PageReference page = Page.Kampagne_Brief_PDF; page.getParameters().put('Id', CampaignId.get(0)); string camId= page.getParameters().put('Id', CampaignId.get(0)); // string camName = page.getParameters().put('Campaign.Name', CampaignId.get(0)); Blob contentBlob = page.getContentAsPDF(); ContentVersion cv = new ContentVersion(); cv.VersionData = contentBlob; cv.Title = strDate + '_' + camName; // cv.Title = System.today().year() + '_' + System.today().month() + '_' + System.today().day() + '_' + 'Serienbrief_'+ camName; cv.PathOnClient = strDate + '_' + camName + '.pdf'; // cv.PathOnClient = System.today().year() + '_' + System.today().month() + '_' + System.today().day() + '_' + 'Serienbrief.pdf'; cv.Vertraulichkeitsstufe__c = 'Intern'; cv.Dokumentenklasse__c ='Anderes Dokument (nicht aufbewahrungspflichtig)'; insert cv; cv = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1]; ContentDocumentLink cdl = new ContentDocumentLink(); cdl.ContentDocumentId = cv.ContentDocumentId; cdl.ShareType = 'I'; cdl.LinkedEntityId = camId; insert cdl; } }
My test class to this point:
I get the error message: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LinkedEntityId]: [LinkedEntityId]
@isTest public with sharing class Kampagnen_Brief_Test { static testmethod void contentDocumentTest() { Campaign cam = new Campaign(); cam.Name = 'Test Briefkampagne'; cam.RecordTypeId = '0127a000001lOti'; cam.IsActive = True; insert cam; ContentVersion cv = new ontentVersion(); cv.Title = '2022-03-10_John Campaign'; cv.PathOnClient = '2022-03-10_John Campaign.pdf'; cv.VersionData = Blob.valueOf('Test Content'); cv.IsMajorVersion = true; cv.Vertraulichkeitsstufe__c = 'Intern'; cv.Dokumentenklasse__c ='Anderes Dokument (nicht aufbewahrungspflichtig)'; Insert cv; ContentVersion contentVersion_2 = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1]; ContentDocumentLink contentlink = new ContentDocumentLink(); contentlink.contentdocumentid = contentVersion_2.contentdocumentid; contentlink.ShareType = 'V'; insert contentlink; Kampagne_Brief KB = new Kampagne_Brief(); } }
Try Below Code
Small Change In You Class In Bold Please Mark It As Best Asnwer If It Helps
Thank You!
All Answers
Try Below test Class Please Mark It As Best Asnwer If It Helps
Thank You!
The Visualforce ist
Try Below Code
Small Change In You Class In Bold Please Mark It As Best Asnwer If It Helps
Thank You!