• Matt Robertson
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
In my apex controller I call a SendEmail() method and it send an email correctly when called from one of my other methods but when I call it from another method in the same controller the body is empty. I have debuged the passed parameters and they are all the exact same as the method that works but it just sends an email with the correct subject with the body empty. The ResendEmail method is the one not working. 
public void SendEmail(ID et) {
        Messaging.SingleEmailMessage mail =new Messaging.SingleEmailMessage();
        Contact recipient = (Contact) currentrecord.getSObject('Contact');
		system.debug(et);
        system.debug(recipient.id);
        mail.saveAsActivity = true;
        mail.setTargetObjectId(recipient.Id);
        mail.setTemplateId(et);
        mail.setWhatId(currentRecord.id);
        system.debug(currentRecord.id);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }

    public PageReference ResendEmail() {
        system.debug(resendtype);
        String resendtype2 =resendtype.remove('RMA').trim();
        String templateID='';
        templateID= RMA__c.getInstance(resendtype2).Email_Template_ID__c;
        System.debug(templateID);
       
        Contact recipient = (Contact) currentrecord.getSObject('Contact');
        If(recipient.email == null || SkipEmail =='false') {
            system.debug('Email Will not be sent Recipient:' +recipient +' SendEmail:' +SkipEmail);           
        }
        Else {
            system.debug('Email Will be Sent');
            sendemail(templateid);       
        }

        List <Task> updates =new List <Task> ();
        for (Task email: [SELECT ID,Status,RecordTypeID,CreatedDate,Subject FROM Task Where WhatID = :currentrecord.ID Order by CreatedDate DESC limit 1]) {
            email.recordtypeID ='012Q00000004wNk';
            email.Type = resendtype;
            updates.add(email);
            update updates;
        }
        try {
            PageReference parentPage= new PageReference('/apex/RMA?scontrolCaching=1&id=' + currentRecord.Id);
            parentPage.setRedirect(true);
            return parentPage;
        }
        Catch(Exception ex) {
            ApexPages.Message msg =new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage());
            ApexPages.addMessage(msg);
        }
        return null;
    }
How can I use permission sets to restrict data categories? When I restrict the specific categories I get an error. But when the permission for the data category is set to all the user can see everything. I want to restrict what parts of the data categories the customer sees by using permission sets. Why is this happening. The profile has none for the data category access.
 User-added image
In my apex controller I call a SendEmail() method and it send an email correctly when called from one of my other methods but when I call it from another method in the same controller the body is empty. I have debuged the passed parameters and they are all the exact same as the method that works but it just sends an email with the correct subject with the body empty. The ResendEmail method is the one not working. 
public void SendEmail(ID et) {
        Messaging.SingleEmailMessage mail =new Messaging.SingleEmailMessage();
        Contact recipient = (Contact) currentrecord.getSObject('Contact');
		system.debug(et);
        system.debug(recipient.id);
        mail.saveAsActivity = true;
        mail.setTargetObjectId(recipient.Id);
        mail.setTemplateId(et);
        mail.setWhatId(currentRecord.id);
        system.debug(currentRecord.id);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }

    public PageReference ResendEmail() {
        system.debug(resendtype);
        String resendtype2 =resendtype.remove('RMA').trim();
        String templateID='';
        templateID= RMA__c.getInstance(resendtype2).Email_Template_ID__c;
        System.debug(templateID);
       
        Contact recipient = (Contact) currentrecord.getSObject('Contact');
        If(recipient.email == null || SkipEmail =='false') {
            system.debug('Email Will not be sent Recipient:' +recipient +' SendEmail:' +SkipEmail);           
        }
        Else {
            system.debug('Email Will be Sent');
            sendemail(templateid);       
        }

        List <Task> updates =new List <Task> ();
        for (Task email: [SELECT ID,Status,RecordTypeID,CreatedDate,Subject FROM Task Where WhatID = :currentrecord.ID Order by CreatedDate DESC limit 1]) {
            email.recordtypeID ='012Q00000004wNk';
            email.Type = resendtype;
            updates.add(email);
            update updates;
        }
        try {
            PageReference parentPage= new PageReference('/apex/RMA?scontrolCaching=1&id=' + currentRecord.Id);
            parentPage.setRedirect(true);
            return parentPage;
        }
        Catch(Exception ex) {
            ApexPages.Message msg =new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage());
            ApexPages.addMessage(msg);
        }
        return null;
    }