You need to sign in to do that
Don't have an account?

Error: Compile Error: Invalid type
Hi,
I'm totally green with Apex trigger, and this is my first stab at writing one. I'm trying to add this Opportunity trigger on NPSP to assign a Designation to an Opportunity transaction when it's created. The trigger is created from Setup->Customize->Opportunity->Trigger. DonationDesignationRelationship is a custom object, which has a master-detail relationship with Opportunity.
When I hit "Quick Save", I got this error:
Error: Compile Error: Invalid type: DonationDesignationRelationship at line 5 column 57
It might be something really straighforward, but somehow I can't figure out. The code is pretty simple:
// Add Designation to a brand new Opportunity
trigger OpportunityAddDesignation on Opportunity (after insert) {
List<DonationDesignationRelationship> ddrs = new List<DonationDesignationRelationship>();
if (Trigger.isInsert && Trigger.isAfter) {
for (Opportunity opp: Trigger.new) {
if (opp.Amount > 0) {
ddrs.add(new DonationDesignationRelationship
(Amount = opp.Amount, Designation = a18U000000BOP4r, Opportunity = opp.Id));
}
}
}
insert ddrs;
}
I'd really appreciate any help or pointers to accomplish this.
Thanks!
Setup > create> objects> donationdesignation relationjship > API name.
Use it.
Check and let us know if you face any issues!
Thank you Rahul and Shailesh, you're both right. I got over that compilation error, but ran into the next one.
Error: Compile Error: Variable does not exist: a18U000000BOP4r at line 11 column 47
I have several "Designations" defined: "ProgramA", "ProgramB", "ProgramC". In DonationDesignationRelationship, Designation is a lookup field. To experiment with this trigger, I assigned the ID of "ProgramA" in the add statement:
ddrs.add(new DonationDesignationRelationship__c
(Amount = opp.Amount, Designation = a18U000000BOP4r, Opportunity = opp.Id));
Apparently, Apex doesn't like it. If I have a name of a program, how can I pass it as parameter to the "add" method?
Thanks!
Thanks Arizona. That works for the hard coded value that I attempted.
What should I do if I'd like to look up the value from a list of "Designations" defined on the system? I tried the following but it didn't work. Apex doesn't like the dList definition on line 5, and des.id on line 12. I'd like to look up a particular name in the global list of "Designations", but didn't succeed. dList is supposed to be initialized to that global "Designations" list, but I don't know how to access it from the trigger context.
Can any one please help me out to resolve the issue ,i am geting below error
Error: Compile Error: Invalid type: Schema.ContentDocumentLink
The error is pointing to blod line in the code
if(!(newpmlist.size()>0)){
List<ID> cdllist =new List<ID>();
List<Planned_Meeting__c> pmlist = new List<Planned_Meeting__c>();
pmlist=[select Id, name,Attachment_Name__c from Planned_Meeting__c where id in :pmidlist];
for(ContentDocumentLink cdlObj : [SELECT Visibility,LinkedEntityId, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =: pmidlist]){
if(cdl.Visibility=='InternalUsers'){
cdllist.add(cdl.ContentDocumentId);
}
}
if(cdllist.size()>0){
for(Planned_Meeting__c pms : pmlist){
for(ContentDocument cdoc : [SELECT FileExtension, Title FROM ContentDocument WHERE Id IN : cdllist]){
if(pms.Attachment_Name__c !='' && pms.Attachment_Name__c != null){
attname= pms.Attachment_Name__c +', '+ cdoc.Title+'.'+cdoc.FileExtension;
}else{
attname= cdoc.Title+'.'+cdoc.FileExtension;
}
pms.Attachment_Name__c = attname ;
newpmlist.add(pms);
}
}
Thanks in advance
satya