• Jess core
  • NEWBIE
  • 15 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
Hi,

I have a trigger in Sandbox that updates a checkbox field to true if an attachment is attached to an expense record.  I have also created a test class with a code coverage of 75%.

Trigger:
 
trigger ExpenseAttachment on ContentDocumentLink (after insert) {
String tempParentId;
	Set<Id> setParentId = new Set<Id>();
	List<Expense__c> Expenselst = new List<Expense__c>();
	
 for (ContentDocumentLink cdl : trigger.new ) {
			tempParentId = cdl.LinkedEntityId;
	 
			if (tempParentId.left(3) =='a0X') {
				System.debug('Debug : found a0X');
				System.debug('Debug : content document id ' + cdl.ContentDocumentId );
				setParentId.add(cdl.LinkedEntityId);
			}
		}
	Expenselst = [select Id , HasAttachment__c from Expense__c where Id IN :setParentId];
	 
	 For(Expense__c e : Expenselst)
	 {
		e.HasAttachment__c = True;
	 }

	 update Expenselst;
}

Test Class:
@istest
private class TestExpenseAttachment {
    @isTest static void TestExpensewithAttachment(){
        //Test data setup
        //Create an Expense
        
        Expense__c Exp = new Expense__c();
        insert Exp;
        
        //Create a ContentVersion
    
        ContentVersion ContentDoc = new ContentVersion();
        ContentDoc.Title = 'My Doc';
        ContentDoc.ContentUrl= 'test.com';
        Insert ContentDoc;
        
		ContentVersion testContent = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :ContentDoc.Id];
        
        // Create a ContentDocumentLink
        ContentDocumentLink ContentDL = new ContentDocumentLink();
        ContentDL.ContentDocumentId = testcontent.contentdocumentid;
        ContentDL.LinkedEntityId=Exp.id;
        ContentDL.ShareType='I';
        Insert ContentDL;
        
        //Assert checkbox field
        System.assert(Exp.HasAttachment__c=TRUE);
    }
}


When I try to deploy this to production through change sets, I get the following error:

"Your organization's code coverage is 8%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
    ExpenseAttachment"

This is ny first time deploying a trigger.  Why is the code coverage of this trigger 75% in sandbox but 0% in production and how can I increase the code coverage?  Also how can I increase the org's code coverage?

Thanks.
Hi,

I am building the process with the following criteria.  If this is true, it would run an email alert.  However,  the email is still being recieved even if the floor expected invoice (currency field) is equal to the floor quoted amount (formula currency field).  Both fields have 2 decimal places.
 
AND(
FLOOR([Quote_Line__c].ExpectedTotalInvoice__c ) > FLOOR([Quote_Line__c].QuotedTotal__c ),
NOT(ISNULL([Quote_Line__c].ExpectedTotalInvoice__c )) ,
NOT(ISNULL([Quote_Line__c].QuotedTotal__c ))
)

 
Hi,

When trying to create a flow in Lightning, I would like to include a lookup field in the screen element.  To do this, I created a text input 'Reported By' to enter the name from the role custom object.  I realise that the flow wants the record id of the role as the text input. 

How can I make it so that when I enter the name or part of the name in the Reported By field, the flow would get the id of the role and return the name of the role?
We would like to see which records have an attachment attached from the list view.  To do this, we created a checkbox field HasAttachment, default unchecked, and the following trigger.  If the Expense custom object record has an attachment, then the HasAttachment field should update to TRUE.  We tested this trigger through 'Upload File' under the Notes and Attachments related list, however, the HasAttachment field remains unchecked.
 
trigger AttachmentonExpense on Attachment (after insert) 
{
Set setParentId = new Set();
List Expenselst = new List();

for(Attachment att: Trigger.new)
{
setParentId.add(att.ParentId);
}

Expenselst = [select Id , HasAttachment__c from Expense__c where Id IN :setParentId];

For(Expense__c e : Expenselst)
{
e.HasAttachment__c = True;
}

update Expenselst;
}

 
Hi,

I have a trigger in Sandbox that updates a checkbox field to true if an attachment is attached to an expense record.  I have also created a test class with a code coverage of 75%.

Trigger:
 
trigger ExpenseAttachment on ContentDocumentLink (after insert) {
String tempParentId;
	Set<Id> setParentId = new Set<Id>();
	List<Expense__c> Expenselst = new List<Expense__c>();
	
 for (ContentDocumentLink cdl : trigger.new ) {
			tempParentId = cdl.LinkedEntityId;
	 
			if (tempParentId.left(3) =='a0X') {
				System.debug('Debug : found a0X');
				System.debug('Debug : content document id ' + cdl.ContentDocumentId );
				setParentId.add(cdl.LinkedEntityId);
			}
		}
	Expenselst = [select Id , HasAttachment__c from Expense__c where Id IN :setParentId];
	 
	 For(Expense__c e : Expenselst)
	 {
		e.HasAttachment__c = True;
	 }

	 update Expenselst;
}

Test Class:
@istest
private class TestExpenseAttachment {
    @isTest static void TestExpensewithAttachment(){
        //Test data setup
        //Create an Expense
        
        Expense__c Exp = new Expense__c();
        insert Exp;
        
        //Create a ContentVersion
    
        ContentVersion ContentDoc = new ContentVersion();
        ContentDoc.Title = 'My Doc';
        ContentDoc.ContentUrl= 'test.com';
        Insert ContentDoc;
        
		ContentVersion testContent = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :ContentDoc.Id];
        
        // Create a ContentDocumentLink
        ContentDocumentLink ContentDL = new ContentDocumentLink();
        ContentDL.ContentDocumentId = testcontent.contentdocumentid;
        ContentDL.LinkedEntityId=Exp.id;
        ContentDL.ShareType='I';
        Insert ContentDL;
        
        //Assert checkbox field
        System.assert(Exp.HasAttachment__c=TRUE);
    }
}


When I try to deploy this to production through change sets, I get the following error:

"Your organization's code coverage is 8%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
    ExpenseAttachment"

This is ny first time deploying a trigger.  Why is the code coverage of this trigger 75% in sandbox but 0% in production and how can I increase the code coverage?  Also how can I increase the org's code coverage?

Thanks.
We would like to see which records have an attachment attached from the list view.  To do this, we created a checkbox field HasAttachment, default unchecked, and the following trigger.  If the Expense custom object record has an attachment, then the HasAttachment field should update to TRUE.  We tested this trigger through 'Upload File' under the Notes and Attachments related list, however, the HasAttachment field remains unchecked.
 
trigger AttachmentonExpense on Attachment (after insert) 
{
Set setParentId = new Set();
List Expenselst = new List();

for(Attachment att: Trigger.new)
{
setParentId.add(att.ParentId);
}

Expenselst = [select Id , HasAttachment__c from Expense__c where Id IN :setParentId];

For(Expense__c e : Expenselst)
{
e.HasAttachment__c = True;
}

update Expenselst;
}