• Alfredo Puente Vasconcelos
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I'm having problems when I call an external web service from Salesforce Apex. When I try to call the web service, I get a System.CalloutException. I believe that the cause of the problem is that the response is too long that Salesforce can't handle it. Is there any problem in my code? How can I consume web service with long json responses with Apex?

Thank you for your attention
 
future(Callout=true)
public static void webServiceCall(){
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint(' here_is_my_url ');
    request.setMethod('GET');
    request.setHeader('Content-Type','application/json');
    request.setTimeout(120000);
    HttpResponse response = http.send(request);
}

 
Hello everyone, I'm having some issues while I try to get the attachments on an Email Message trigger. I want to block all the emails that have Excel Files attached but when I try to access the Attachments, Apex says the the list is Empty. Can someone help me? :(
 
trigger BlockExcel on EmailMessage (before insert) {
    List<EmailMessage> compatibleEmails = new List<EmailMessage>();
    for(EmailMessage activeMail : Trigger.new){
        if(activeMail.HasAttachment == true && activeMail.Subject.contains('Entrega de propuesta')){
            compatibleEmails.add(activeMail);
        }else{
            System.debug('Dont Enter');
        }
    }
    for(EmailMessage email : compatibleEmails){   
        /*********************ERROR Attachment Size = 0***********/
        System.debug('The size of my attachment list is: ' + email.Attachments.size());      
        for(Integer i = 0; i < email.Attachments.size(); i++){     
            if(email.Attachments[i].ContentType == '.xlsx' || email.Attachments[i].ContentType == 'xlsx'){
                email.addError('Excel Files are not allow');
                break;
            }
        }
    }
}

Thanks for your time
Hi all 

How to execute below code in anonymous window   
 
public class UserUpdate {
   public void updateUser(List<ID> ids){
        Id userId = ids.get(0);

        Profile prf = [select id from Profile where Name='Work.com Only User'];
        User usr = [select IsActive,UserRoleId,ProfileId,Title,CompanyName,CallCenterId,DelegatedApproverId,ManagerId from User where id=:userId];
        usr.UserRoleId = null;
        usr.ProfileId = prf.id;
        usr.Title = null;
        usr.CompanyName = null; 
        usr.CallCenterId = null;      
        usr.DelegatedApproverId = null;
        usr.ManagerId = null;
        usr.IsActive = false;
        update usr;
        
    }
    }
Anonymous code is 
 
List<Id> Ids = new List<Id>();
Ids.add(id);
UserUpdate.updateUser(Ids);

kindly Support and Suggest

Thanks ​​​​​​​
Hello everyone, I'm having some issues while I try to get the attachments on an Email Message trigger. I want to block all the emails that have Excel Files attached but when I try to access the Attachments, Apex says the the list is Empty. Can someone help me? :(
 
trigger BlockExcel on EmailMessage (before insert) {
    List<EmailMessage> compatibleEmails = new List<EmailMessage>();
    for(EmailMessage activeMail : Trigger.new){
        if(activeMail.HasAttachment == true && activeMail.Subject.contains('Entrega de propuesta')){
            compatibleEmails.add(activeMail);
        }else{
            System.debug('Dont Enter');
        }
    }
    for(EmailMessage email : compatibleEmails){   
        /*********************ERROR Attachment Size = 0***********/
        System.debug('The size of my attachment list is: ' + email.Attachments.size());      
        for(Integer i = 0; i < email.Attachments.size(); i++){     
            if(email.Attachments[i].ContentType == '.xlsx' || email.Attachments[i].ContentType == 'xlsx'){
                email.addError('Excel Files are not allow');
                break;
            }
        }
    }
}

Thanks for your time
I have created a ContentDocument and ContentDocumentLink against the parent object record. However, AttachedContentDocuments related list for the record is still empty. It works successfully, outside of a test class (via Anonymous Apex, for instance) . Any ideas would be appreciated.

For anyone interested, the following Code is a trigger that send an email update to Case Owner, Case Contact and Case Team (users and contacts) in the Case everytime Case has been updated with an new Email-to-Case Message.

 

I have no idea why my list of Attachments is empty in the following lines of code??? The debug logs return 0 although my email test has attachments in the email and I can see this when going to the email Message record in the case.

 

list<Attachment> allAttachmentsInEmail = [Select Name, ContentType, Body From Attachment Where parentId =:e.id];


system.debug('---->number of attachments: ' + allAttachmentsInEmail.size());

 

Hope someone knows if I did something silly with my query?

 

Full code for those interested in using it.

 

trigger SendEmailUpdateOnEmailMessageForCase on EmailMessage (before insert, after insert) { 

	try{	
		for(EmailMessage e: trigger.new){
		
			//system.debug('@@@###$$$%%^^ Inserted email' + 'trigger size = ' + trigger.new.size());
			string caseId = string.valueof(e.ParentId);
						
			if(caseId.startsWith('500')){	//This Email Message is for a Case 
				
				//Look up Case Details
				Case theCase = [SELECT Id, ContactId, OwnerID, Subject, Priority, IsClosed, EntitlementId, Description, CreatedDate, CaseNumber, AccountId, Email_Message_Body_Copy_For_Template__c  FROM Case WHERE Id =: caseId Limit 1];			
				
				if(trigger.isBefore){	
					if(e.TextBody != theCase.Email_Message_Body_Copy_For_Template__c){
						theCase.Email_Message_Body_Copy_For_Template__c = e.TextBody; //This field updates the Case so that we can dynamically merge field in the Template 'CASE_ICT_Customer_New_Case_Update'
						try{
							update theCase;
						}catch(dmlexception e2){
							system.debug('Problem with udpating Case sObject in SendEmailUpdateOnEmailMessageForCase: ' + e2.getMessage());
						}
					}				
					
				}else if(trigger.isAfter){
					
					system.debug('***** the email Id is ' + e.id);
					Set<ID> toEmailId = new Set<ID>();;
					toEmailId.add(theCase.OwnerId);
					//Get Ids of the Case Team Members
					List<CaseTeamMember> member = [Select MemberId From CaseTeamMember where ParentId =:caseId];
					
					for(CaseTeamMember m: member){
						toEmailId.add(m.MemberId);			
					}
					//system.debug('%%%List of Members %%%%% ' + toEmailId);
					
					//Get contact and user list from the set of Id's			
					List<Contact> listContactEmails = [SELECT Email FROM Contact Where ID IN: toEmailId];
					List<User> listUserEmails =  [SELECT Email FROM User Where ID IN: toEmailId]; 
		
					//Get all email address in unique set
					Set<String> setOfContactEmails = new Set<String>();
					Set<String> setOfUserEmails = new Set<String>();
					for(Contact c: listContactEmails){
						setOfContactEmails.add(c.Email);
					}
					for(User u: listUserEmails){
						setOfUserEmails.add(u.Email);
					}
								
					list<String> listOfEmails = new list<String>();
					listOfEmails.addAll(setOfContactEmails);
					listOfEmails.addAll(setOfUserEmails);
					listOfEmails.sort();		
				
					//Create the email message body
					Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
					EmailTemplate emailTemp = [Select id From EmailTemplate Where developerName = 'CASE_ICT_Customer_New_Case_Update' Limit 1]; //A email template for Cases
					email.orgWideEmailAddressId = '0D2D0000000GnPW';	//Our Org Wide default
					email.replyTo = 'support.test@ictnetworks.com.au';
		      		        email.saveAsActivity = false;
					email.settargetObjectId(theCase.ContactId);
					email.setCcAddresses(listOfEmails);
					email.setTemplateId(emailTemp.Id);
					email.setwhatId(theCase.Id);
					
					//Check for Attachments							
					system.debug('H$H$H$H$H Attachment Flag: ' + e.HasAttachment);
					if(e.HasAttachment){
						//Create list of Messageing email File Attachments
						list<Messaging.EmailFileAttachment> fileAttachments = new list<Messaging.EmailFileAttachment>();
						//Query all child Attachments relating to this email Id
					        list<Attachment> allAttachmentsInEmail = [Select Name, ContentType, Body From Attachment Where parentId =:e.id]; 
						//Add to list of Attachments to email
						system.debug('---->number of attachments: ' + allAttachmentsInEmail.size());
						for(Attachment a: allAttachmentsInEmail){
							Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
							efa.setFileName(a.Name);
							efa.setBody(a.Body);
							fileAttachments.add(efa);
						}
						email.setFileAttachments(fileAttachments);
					}	
					
					system.debug('@@@@@targetI ObjectID = ' + email.targetObjectId);
					system.debug('@@@@@emailTemp.Id = ' + emailTemp.Id);
					system.debug('@@@@@whatId = ' + email.whatId);
					//email.setPlainTextBody('Hello!'); 
					//email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
					//system.debug(email); 
					//Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
										
				}
			}
		}
	} catch (exception e){
		System.debug('The following exception has occurred: ' + e.getMessage());
	}		

}