trigger MandatoryDocumentsUploadedEmail on Verification_Documents__c (after insert) {
            Set<Id> oppIds = new Set<Id>();
            Set<Id> verDocIds = new Set<Id>();
            for(Verification_Documents__c vd : Trigger.new){
            List<Opportunity> verOpps = [SELECT Id, Name,stageName, (SELECT id, Name, Document_Name__c, docType__c, Document_Master__c,Document_Master__r.Stages__c,
                                                                     Document_Master__r.Document_Name__c, Document_Master__r.DocumentType__c, Reviewed__c, Approved__c,
                                                                     AttachmentId__c, Comment__c FROM Verification_Documents__r WHERE Opportunity__r.Id IN :oppIds) 
                                         FROM Opportunity WHERE Id IN :oppIds];

            system.debug('verOpps::: '+ verOpps);
            List<Verification_Documents__c> vd = [SELECT Id,Name,docType__c,Approved__c,AttachmentId__c,Document_Status__c,Photograph__c,Reviewed__c,Document_Master__r.Document_Name__c,Document_Master__r.User__c,Comment__c,
                                                  Opportunity__r.Sales_Contractor__r.Email,Opportunity__r.Loan_Number__c FROM Verification_Documents__c where Document_Master__r.Mandatory__c=true and Opportunity__r.Id IN : oppIds and Document_Master__r.Stages__c= 'Verification'];
            List<TypeWiseDocument__c> fileListMandate = new List<TypeWiseDocument__c>();
            List<String> fileList = new List<String>();
            for(TypeWiseDocument__c documentDesc: [Select Document_Name__c, Stages__c, User__c, DocumentType__c 
                                                   FROM TypeWiseDocument__c 
                                                   WHERE Mandatory__c=true AND DocumentType__c = 'Predefined'])
            //Map<String,Verification_Documents__c> MapAttchmentByType=new Map<String,Verification_Documents__c>();

            for (Opportunity o : verOpps) 
                System.debug('opp id for record type is ====  '+o.Id);
                String opporId = o.Id;

                Map<String,Verification_Documents__c> MapAttchmentByType=new Map<String,Verification_Documents__c>();
                for(Verification_Documents__c attch : o.Verification_Documents__r)
                    MapAttchmentByType.put(attch.docType__c, attch);   
                    if(attch.Document_Master__r.Stages__c == 'Verification'){
                        if(attch.AttachmentId__c != null){
                            List<String> toAddress = new List<String> ();
                            User LoggedinUsr1= [SELECT Id,Name,Email,Partner_User_Type__c, Profile.Name FROM User where id='0056C000001CnFnQAK' LIMIT 1];
                            System.debug('****In try'+LoggedinUsr1.Email);
                            EmailTemplate emailTemp = [SELECT Id, Name, Body, HtmlValue FROM EmailTemplate where name='DocumentsUploadedByCustomer']; 
                            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                            email.setSenderDisplayName('Oa Team');

                            if(email != null){                
                                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email }); 

Will this send an email after uploading all the mandatory documents at verification stage.

closed as unclear what you're asking by Derek F, glls, Pranay Jaiswal, Reshma, battery.cord Mar 25 at 12:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Hey Mahesh, please don't change the content of your question to new code/new questions after receiving answers - it invalidates the posts that have been made and is confusing to other readers. You can post a new question if you need to but please be specific about what you're asking. – David Reed Mar 22 at 13:11
  • Can you please look at the code and say where is the mistake.It is not getting into this for(Verification_Documents__c attch : o.Verification_Documents__r) loop.Please – mahesh Mar 22 at 17:19
List<Verification_Documents__c> vd = [
    SELECT ... 
    FROM Verification_Documents__c 
    WHERE Opportunity__c IN: Trigger.new 
          AND Document_master__r.Stages__c IN: Trigger.new 
          AND Document_Master__r.Mandatory__c=true];

I've trimmed and formatted this so it is a little easier to read.

You have two bind expressions here, Opportunity__c IN: Trigger.new and Document_master__r.Stages__c IN: Trigger.new. We don't know the type of the second one so I'll focus on the first.

Presumably, Opportunity__c is a lookup from Verification_Documents__c to Opportunity. That means the field type is an Id of an Opportunity object. You're asking Salesforce to evaluate that field against a collection of a different object - Trigger.new is a collection of Verification_Documents__c objects.

The comparand must be of the same type. You'd need to iterate over Trigger.new and accumulate a Set of Opportunity Ids. You could then use that collection in your bind. A similar pattern would address the other bind, to Document_master__r.Stages__c, using whatever type that field happens to be.

Not the answer you're looking for? Browse other questions tagged or ask your own question.