• Ant Backhouse
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi All,

I wrote a class method for sending a single email message in my staging environment and the expected default behaviour of being saved as an activity worked. Moving to production, the saving as activity failed. Moreover, I can execute the code as anonymous apex and it saves as activity in the prod org. Here is the method:
 
public with sharing class EmailUpdateController {

	public static void sendTemplateEmail(String templateId, String whoId, String whatId) {
		Messaging.reserveSingleEmailCapacity(1);				
		Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
		email.setUseSignature(false);	
		email.setTemplateId(templateId);
		email.setTargetObjectId(whoId);
		email.setWhatId(whatId);
		List<Messaging.SendEmailResult> results = Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{email});
		Boolean returnValue = true;
		for (Messaging.SendEmailResult er : results) {
			System.debug(er.isSuccess());
			if(!er.isSuccess()) {
				System.debug(er.getErrors());
				returnValue = false;
			}
		}
		System.debug('Success was '+returnValue);
		
	}

}

This method works fine in staging and also running this in the dev console in production works.

Running code in Developer Console

I get activity as expected
Activity on Opportunity
When running the method however, eg: 
EmailUpdateController.sendTemplateEmail('00X0I000001dmpUUAQ', '00328000015yPZXAA2', '0060I00000R9fIMQAZ');

No activity is saved.  

Appreciate your help. I've been pulling my hair out with this.
I'm following the examples as given in the updated documentation.
 
<aura:component>
    <lightning:recordEditForm recordId="003XXXXXXXXXXXXXXX" objectApiName="Contact">
        <lightning:messages />
        <lightning:inputField fieldName="FirstName" />
        <lightning:inputField fieldName="LastName" />
        <lightning:inputField fieldName="Email" />
        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update" />
    </lightning:recordEditForm>
</aura:component>
Inserting a recordId in the above example results in the following error:
[Error in $A.getCallback() [Cannot read property 'value' of undefined]]
Even the second example, attempting to create a record, is throwing an error:
<aura:component>
    <lightning:recordEditForm aura:id="recordEditForm" 
                           objectApiName="Contact">
        <lightning:messages />
        <lightning:inputField fieldName="Name" />
        <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
    </lightning:recordEditForm>
</aura:component>
In the above code, there are two separate errors happening:

1) I'm getting the error 'Cannot read property 'defaultRecordTypeId' of undefined' even though there are no record types associated with my Conatct object.  To get around this error, I have created a record type and I'm now passing in the recordTypeId.  Updated code looks like:
<aura:component>
    <lightning:recordEditForm aura:id="recordEditForm" 
                           objectApiName="Contact"
                           recordTypeId="XXXXXXXXXXXXX">
        <lightning:messages />
        <lightning:inputField fieldName="Name" />
        <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
    </lightning:recordEditForm>
</aura:component>
2) Now that I'm past the recordTypeId error, I now receive this error:
cannot read property 'fields' of undefined

I understand that this new component is in Beta for the current release, but I wanted to understand if the documentation is incomplete, if I'm making some simple error that I cannot see, or if the feature is not fully functional yet.



 
Hi All,

I wrote a class method for sending a single email message in my staging environment and the expected default behaviour of being saved as an activity worked. Moving to production, the saving as activity failed. Moreover, I can execute the code as anonymous apex and it saves as activity in the prod org. Here is the method:
 
public with sharing class EmailUpdateController {

	public static void sendTemplateEmail(String templateId, String whoId, String whatId) {
		Messaging.reserveSingleEmailCapacity(1);				
		Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
		email.setUseSignature(false);	
		email.setTemplateId(templateId);
		email.setTargetObjectId(whoId);
		email.setWhatId(whatId);
		List<Messaging.SendEmailResult> results = Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{email});
		Boolean returnValue = true;
		for (Messaging.SendEmailResult er : results) {
			System.debug(er.isSuccess());
			if(!er.isSuccess()) {
				System.debug(er.getErrors());
				returnValue = false;
			}
		}
		System.debug('Success was '+returnValue);
		
	}

}

This method works fine in staging and also running this in the dev console in production works.

Running code in Developer Console

I get activity as expected
Activity on Opportunity
When running the method however, eg: 
EmailUpdateController.sendTemplateEmail('00X0I000001dmpUUAQ', '00328000015yPZXAA2', '0060I00000R9fIMQAZ');

No activity is saved.  

Appreciate your help. I've been pulling my hair out with this.