You need to sign in to do that
Don't have an account?
Maggie Farley 14
Trigger Errors and Test Class Errors
Hello,
I am trying to create a trigger to populate a Contract Uploaded Date on the Opportunity. I am new to triggers and keep getting erros on both the apex trigger and apex class. Can someone please help me?
trigger setContractAttachment on Attachment (before insert) {
List<Opportunity> listOpp = new List<Opportunity>();
for(Attachment att: Trigger.New){
if(att.ParentId.getSobjectType() == Opportunity.SobjectType) {
oppId.add(att.ParentId);
opp.Contract_Uploaded_Date__c=Date.today();
}
//update the Opportunities
opportunityList = [select id, has_Attachment__c from Opportunity where id is : oppId];
if(opportunityList!=null && opportunityList.size()>0){
for(Opportunity opp : opportunityList){
opp.has_Attachment__c = true;
}
update opportunityList;
}
Test Class
Test Class
@isTest
public class ContractAttachmentTest {
Opportunity = [Select id=;0062C0000022sfT]
Attachment attachTest = new Attachment (Name= 'Test');
attachTest.body = Blob.valueOf('')
attachTest.ParentID = b.Id;
attachTest.OwnerID = U.Id;
insert attachTest;
}
I am trying to create a trigger to populate a Contract Uploaded Date on the Opportunity. I am new to triggers and keep getting erros on both the apex trigger and apex class. Can someone please help me?
trigger setContractAttachment on Attachment (before insert) {
List<Opportunity> listOpp = new List<Opportunity>();
for(Attachment att: Trigger.New){
if(att.ParentId.getSobjectType() == Opportunity.SobjectType) {
oppId.add(att.ParentId);
opp.Contract_Uploaded_Date__c=Date.today();
}
//update the Opportunities
opportunityList = [select id, has_Attachment__c from Opportunity where id is : oppId];
if(opportunityList!=null && opportunityList.size()>0){
for(Opportunity opp : opportunityList){
opp.has_Attachment__c = true;
}
update opportunityList;
}
Test Class
Test Class
@isTest
public class ContractAttachmentTest {
Opportunity = [Select id=;0062C0000022sfT]
Attachment attachTest = new Attachment (Name= 'Test');
attachTest.body = Blob.valueOf('')
attachTest.ParentID = b.Id;
attachTest.OwnerID = U.Id;
insert attachTest;
}
Please refer above trigger class.
Class is not required if you paste above code in trigger.
In test class, below line need to replace with data
//Populate all required opportunity fields here
PLease mark this answer as best if it helped.
All Answers
Please refer above trigger class.
Class is not required if you paste above code in trigger.
In test class, below line need to replace with data
//Populate all required opportunity fields here
PLease mark this answer as best if it helped.
This worked in Sandbox but when I deployed it to production it did not work. Do I need test cases in Production?