function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mlfmlf 

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!

 

 

Shailesh DeshpandeShailesh Deshpande
You need to use the API name of the object and not the label. Hence the error. To find the API name of the object go to,

Setup > create> objects> donationdesignation relationjship > API name.

Use it.
Rahul SharmaRahul Sharma
Patil is right, DonationDesignationRelationship might be a Object label. You need to use Its API Name, API name must be like : DonationDesignationRelationship__c.
Check and let us know if you face any issues!
mlfmlf

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!

arizonaarizona
a18U000000BOP4r needs to be surrounded by single quotes. I assume Designation is a lookup to another sObject. If that is the case the field will need __c appended to it. Designation__c = 'a18U000000BOP4r'
mlfmlf

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.

 

trigger OpportunityAddDesignation on Opportunity (after insert) {
  
  List<DonationDesignationRelationship__c> ddrs = new List<DonationDesignationRelationship__c>();
  Designation__c des;
  List<Designation__c> dList = new List<Designation__c>();
  
  if (Trigger.isInsert && Trigger.isAfter) {
    for (Opportunity opp: Trigger.new) {
      if (opp.Amount > 0) {
        des = [Select Id from dList where Name = 'foo'];
        ddrs.add(new DonationDesignationRelationship__c
          (Amount = opp.Amount, des.id, Opportunity = opp.Id));
      }
    }
  }
 
Thanks.
Satya Ranjan MohantySatya Ranjan Mohanty
Hi,
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