3

am calling an apex call from process builder.In process builder am sending an id of invention disclosure object and in the class am getting an error as: Error: Compile Error: Invalid loop variable type expected Id was Invention_Disclosure_New__c at line 51 column 17

public class Idfattachment
{
@InvocableMethod
public static void Idfattach(List<Id> InventionDisclosure)
{
       IDF_Email__c settings = IDF_Email__c.getInstance('EmailConfig');
        String status= settings.status__c;
        String tosub = settings.subject__c;
        String toemail = settings.Email__c;
        Boolean taction = settings.Mail_ON_OFF__c;
        if(taction)
        {
            List<Messaging.SingleEmailMessage> myListofMails = NEW List<Messaging.SingleEmailMessage>();
            Map<string,List<ContentDocumentLink>> MapIDFsDocLink = NEW Map<string,List<ContentDocumentLink>>();
            set<id> ConLinkIDset = New set<id>();
            list<id> idfid = New list<id>();  
            List<ContentDocumentLink> lstContentDocumentLinks = [SELECT ContentDocumentId,Id,LinkedEntityId
                                                            FROM ContentDocumentLink WHERE LinkedEntityId IN: InventionDisclosure];
            for(ContentDocumentLink ConDocLink : lstContentDocumentLinks)
            {
                ConLinkIDset.add(ConDocLink.ContentDocumentId);
                List<ContentDocumentLink> temp = MapIDFsDocLink.get(ConDocLink.LinkedEntityId);
               if(temp == null) 
               {
                   MapIDFsDocLink.put(ConDocLink.LinkedEntityId, new List<ContentDocumentLink>{ConDocLink});
               } 
               else 
               {
                   temp.add(ConDocLink);
               }
            }
            Map<string,List<ContentVersion>> MapLinksDocuments = NEW Map<string,List<ContentVersion>>();
            List<ID> ConLinkIDSList = NEW List<ID>(ConLinkIDset);
            List<ContentVersion> documents= [ 
                                                SELECT Id, Title,PathOnClient,VersionData,isLatest,ContentDocumentId
                                                FROM ContentVersion
                                                WHERE isLatest = true AND ContentDocumentId  IN:ConLinkIDSList
                                            ];
            for(ContentVersion ConDoc : documents)
            {
                List<ContentVersion> temp = MapLinksDocuments.get(ConDoc.ContentDocumentId);
                if(temp == null) 
                {
                    MapLinksDocuments.put(ConDoc.ContentDocumentId, new List<ContentVersion>{ConDoc});
                } 
                else 
                {
                    temp.add(ConDoc);
                }
            }
            for(Id idf : InventionDisclosure)  <--**Getting Error here**           {   

                    if(idf.Disclosure_Status__c == status)
                    {
                        Id newDocLink = idf.Id;
                        if(MapIDFsDocLink.containsKey(idf.id))
                        {
                            set<ID> lstDocId = new set<ID>();
                            List<ContentDocumentLink> lstContentDocumentLinks1 =MapIDFsDocLink.get(idf.id);               
                            for(ContentDocumentLink docit : lstContentDocumentLinks1) 
                            {                   
                                lstDocId.add(docit.ContentDocumentId);  
                            }                   
                            List<Messaging.EmailFileAttachment> attachments = new List<Messaging.EmailFileAttachment>{};
                            List<ContentVersion> documents1= NEW List<ContentVersion>();
                            for(id ids : lstDocId)
                            {
                                if(MapLinksDocuments.containsKey(ids))
                                {
                                    List<ContentVersion> documentslist = MapLinksDocuments.get(ids);
                                    documents1.addall(documentslist);
                                }                                   
                            }
                            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();                
                            for (ContentVersion document: documents1)
                            {
                                Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
                                attachment.setBody(document.VersionData); 
                                attachment.setFileName(document.PathOnClient);
                                attachments.add(attachment);
                            }
                            semail.setSubject(tosub);
                            string query ='SELECT Id,'+toemail+' FROM Invention_Disclosure_New__c WHERE Id =:newDocLink';
                            List<Invention_Disclosure_New__c > sobjList = Database.query(query);
                            String[] sendTo = new String[]{}; 
                            Set<string> fieldApis = New Set<string>();
                            List<String> lstAlpha = toemail.split(',');
                            if(lstAlpha.size()>0)
                            for(string s:lstAlpha)
                            {
                                fieldApis.add(s);
                            }
                            for(Invention_Disclosure_New__c  tmpUser:sobjList)
                            {
                            if(fieldApis.contains('PPA_EmailId__c'))
                                if(tmpUser.PPA_EmailId__c!=null && tmpUser.PPA_EmailId__c!='')
                                    sendTo.add(tmpUser.PPA_EmailId__c);
                                    system.debug('PPA email:'+sendTo);
                                if(fieldApis.contains('Inventor_Email_Id__c'))
                                    if(tmpUser.Inventor_Email_Id__c!=null && tmpUser.Inventor_Email_Id__c!='')
                                        sendTo.add(tmpUser.Inventor_Email_Id__c);
                                        system.debug('Inventor email:'+sendTo);
                            }
                            semail.setToAddresses(sendTo);
                            system.debug(semail);
                            String messageBody = '<html><body>Hi,New Invention Disclosure entitled '+idf.Title__c +',has been submitted for review.Please refer the attached document for the complete information of the submitted disclosure.</body></html>';
                            semail.setHtmlBody(messageBody); 
                            semail.setFileAttachments(attachments);
                            if(attachments.size() > 0)
                            {
                                myListofMails.add(semail);
                            }
                        }

                }                       
            }
            if(myListofMails.size()>0) 
            {
                Messaging.sendEmail(myListofMails);
            }
        } 
    }
}
2
  • Can you specify Which object Ids InventionDisclosure list contains? It seems LinkedEntity ids. Please clarify.
    – Mr.Frodo
    May 26, 2018 at 7:36
  • now it is solved,now am getting this error -->Error: Compile Error: Variable does not exist: Disclosure_Status__c at line 54 column 32 May 26, 2018 at 7:39

2 Answers 2

2

At Line 51, replace Invention_Disclosure_New__c with Id.

As InventionDisclosure is type List<Id>

Even after changing this you will recieve further errors because here you need an object Type, So what you can do is you can perform a query like this before line 51:

List<Invention_Disclosure_New__c> idf1 = [Select Id, Disclosure_Status__c from Invention_Disclosure_New__c where Id in : InventionDisclosure];

and leave the line 51 as it is so code would be like this:

List<Invention_Disclosure_New__c> idf1 = [Select Id, Disclosure_Status__c from Invention_Disclosure_New__c where Id in : InventionDisclosure]; for(Invention_Disclosure_New__c idf : idf1){

I am assuming InventionDisclosure list contains Id of Invention_Disclosure_New__c records.

6
  • ok, now am getting on next line,Error: Compile Error: Variable does not exist: Disclosure_Status__c at line 54 column 32 May 26, 2018 at 7:28
  • See my updated answer. Add query just above line 51.
    – Mr.Frodo
    May 26, 2018 at 7:42
  • duplicate variable exits idf May 26, 2018 at 7:51
  • sorry, updated.
    – Mr.Frodo
    May 26, 2018 at 7:53
  • super,that is solved.now am getting this error while running:An Apex error occurred: System.EmailException: SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: [] -- what does it mean? May 26, 2018 at 8:00
1

Actually, you are calling it from process builder and pasing list of Ids (not list of objects) same as trigger.new (if it was a apex trigger)

So update your methods to accept List<Invention_Disclosure_New__c > InventionDisclosure

@InvocableMethod
public static void Idfattach(List<Invention_Disclosure_New__c > InventionDisclosure) {...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .