• Anto Hotelbeds
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 49
    Questions
  • 45
    Replies
Hi all,

In my org, when a customer service agent is working on a case and hits the send email button to use the standard send email functionality, I hav a requirement that is:
- Capture the body of the email and create with it a Case Comment related to the parent case of the email. Also, get all the attachments related to the email and relate them to the case. Finally, delete the email message.

I am able to do everything except for the attachments part. I have created a trigger on emailMessage that creates the case comment without trouble, but another part of my trigger is created to get the attachments, but it always returns 0 elements in the list. This is the trigger on email message related to the attachment part(just getting the attachment of the first email to check if it works):
 
trigger EmailMessageAfterOperationTrigger on EmailMessage (after delete, after insert, after undelete, after update) {

if (trigger.isInsert){
    	Attachment[] attList = [select id, name, body from Attachment where ParentId = :Trigger.new[0].Id];
    	Attachment[] insertAttList = new Attachment[]{};

        system.debug('Has the email attachments?:' + Trigger.new[0].HasAttachment);
    	system.debug('list of attachments realted to the email message: ' + attList);

    	for(Attachment a: attList){
               Attachment att = new Attachment(name = a.name, body = a.body, parentid = Trigger.new[0].id);
               insertAttList.add(att);
        }
       if(insertAttList.size() > 0){
            insert insertAttList;
       }
    	
    }
This is the debug log the system shows:
 
09:45:00.579 (1579755455)|USER_DEBUG|[146]|DEBUG|Has the email attachments?:true
09:45:00.579 (1579760206)|SYSTEM_METHOD_EXIT|[146]|System.debug(ANY)
09:45:00.579 (1579778024)|SYSTEM_METHOD_ENTRY|[147]|String.valueOf(Object)
09:45:00.579 (1579802168)|SYSTEM_METHOD_EXIT|[147]|String.valueOf(Object)
09:45:00.579 (1579814171)|SYSTEM_METHOD_ENTRY|[147]|System.debug(ANY)
09:45:00.579 (1579819259)|USER_DEBUG|[147]|DEBUG|list of attachments realted to the email message: ()

I have also created a trigger on attachment before insert but it doesnt get fired when sending an email with attachment:
 
trigger AttachmentBeforeOperationTrigger on Attachment (before delete, before insert, before update) {

	if (Trigger.isInsert || Trigger.isUpdate){
		for (Attachment a: Trigger.new){
			system.debug('el attachment: ' + a);
		}
	}

}

I need to get this attachments related to the email message, can please anyone help me?

Thanks,

Antonio





 
Hi,

I have a visualforce page where I am showing all the attachments related to a case with a checkbox to know if the user has marked it. This is the related part of the VF page:

<apex:pageBlock title="Existing Case Attachments">
    <apex:pageBlockTable value="{!listAttachWrapper}" var="item">
        <apex:column title="Select" headerValue="Add Attachment" width="50px,50px">
            <apex:inputCheckbox value="{!item.IsChecked}">
                </apex:inputCheckbox>
        </apex:column>
        <apex:column headerValue="File">
            <apex:outputLink value="{!URLFOR($Action.Attachment.Download,item.att.Id)}"
                target="_blank">{!item.att.Name}</apex:outputLink>
        </apex:column>
        <apex:column value="{!item.att.Description}" />
    </apex:pageBlockTable>
</apex:pageBlock>

I also have my controller with the definition of the wrapper class:

public List<attWrapper> listAttachWrapper {get;set;}
public List <Attachment> selectedmems{get;set;}
public class attWrapper{
    public Attachment att {get; set;}
    public Boolean isChecked{get; set;}
    public attWrapper(Attachment att){
        this.att=att;
        if (isChecked==null){
            isChecked=false;
        }
    }
}

And in the constructor of the method, I get the elements and mark the ischecked field to false:

listAttachWrapper=new List<attWrapper>();
for (Attachment a:[SELECT Name,Description FROM Attachment WHERE ParentId=:case1.Id])
        listAttachWrapper.add(new attWrapper(a));

Finally I have the method that is called from the VF page, where I try to get which attachments have been market to true:

selectedmems=new List<Attachment>();
system.debug('List of members: '+listAttachWrapper);
for (attWrapper att: listAttachWrapper){
    if (att.IsChecked==true){
        selectedmems.add(att.att);
    }
}
system.debug('The list is:' + selectedmems);

The problem is that I get all the elements with the IsChecked field to false, even though I am selecting them in the VF page.

I have been for two days already with this, can anyone help please?

Thanks a lot!

Antonio
Hi,

I have a visualforce page where I am showing all the attachments related to a case with a checkbox to know if the user has marked it. This is the related part of the VF page:
<apex:pageBlock title="Existing Case Attachments">
        <apex:pageBlockTable value="{!listAttachWrapper}" var="item">
            <apex:column title="Select" headerValue="Add Attachment" width="50px,50px">
                <apex:inputCheckbox value="{!item.IsChecked}">
                    </apex:inputCheckbox>
            </apex:column>
            <apex:column headerValue="File">
                <apex:outputLink value="{!URLFOR($Action.Attachment.Download, item.att.Id)}"
                    target="_blank">{!item.att.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!item.att.Description}" />
        </apex:pageBlockTable>
    </apex:pageBlock>

I also have my controller with the definition of the wrapper class:

public List<attWrapper> listAttachWrapper {get;set;}
public List <Attachment> selectedmems{get;set;}
   
public class attWrapper{
	public Attachment att {get; set;}
      	public Boolean isChecked{get; set;}
      
      	public attWrapper(Attachment att){
      		this.att=att;
        	if (isChecked==null){
        		isChecked=false;
        	}
      	}
    }

And in the constructor of the method, I get the elements and mark the ischecked field to false:

listAttachWrapper=new List<attWrapper>();
for (Attachment a:[SELECT Name,Description FROM Attachment WHERE ParentId=:case1.Id])
			listAttachWrapper.add(new attWrapper(a));

Finally I have the method that is called from the VF page, where I try to get which attachments have been market to true:

selectedmems=new List<Attachment>();
system.debug('List of members: '+listAttachWrapper);
for (attWrapper att: listAttachWrapper){
                	if (att.IsChecked==true){
                		selectedmems.add(att.att);
                	}
                }
system.debug('The list is:' + selectedmems);

The problem is that I get all the elements with the IsChecked field to false, even though I am selecting them in the VF page.

I have been for two days already with this, can anyone help please?

Thanks a lot!

Antonio




Hi,

I have a requirement for the community portal. It says that for picklist fields, when the user is checking the available options in the piclist, when the user mouse over each one of the values, the system should show a help text.

Is there anyway to do so using Javascript or Jquery? Could someone point me on the right direction please?

I know i can show the standar salesfoce help text on my visualforce page, but I have around 30 options in the picklist, so its quite confusing to do it with this standard funcionality.

Any help is appreciated!

All the best,

Antonio
Hi,

When creating a lead, I need to compare the lead Fiscal number field with the account fiscal number in a soql query. 
The issue comes with this case:
Lead Fiscal Number: DE12345
Account Fiscal Number: 12345

I want the query to detect this situation and return me the account in the list, but it doesnt appear:

This is my code:

        string FiscalNumber1Lead='%' + lead.Fiscal_Number_1__c + '%';
      
        return [Select ID, Name, Owner.Name, Fiscal_Number_2__c, Fiscal_Number_1__c,KAM__c,AccountNumber,Account_Status__c,Commercial_Brand__c, Inactive_Reason__c From Account
        Where ((Fiscal_Number_1__c LIKE :FiscalNumber1Lead))  limit 100];

But with this situation I am comparing  '12345' like: '%DE12345%', and obviously returns me no results....

I also tried to change the condition to:

Where ((l2.Fiscal_Number_1__c LIKE :Fiscal_Number_1__c)) but it returns me an error in the code.

Can anybody give help me please?

Thanks,

Antonio
Hi,

I have an email handler for my EmailToCase. I am having errors when receiving an email with chinese characters.

What I do in my handler is take the body of the email, cut it to 4000char (max length of a case comment) and insert it as a case comment in the case. This is my handler code thats inserts the new case comment:

newCommand.CommentBody=newCommand.CommentBody+'\n\t\n'+CommentEmail;
               system.debug('Longitud del comment: '+newCommand.CommentBody.length());
               newCommand.CommentBody=limitLength(newCommand.CommentBody,CaseComment.CommentBody.getDescribe().getLength()-1).unescapeHtml4();
               system.debug('Comment length after cutting: '+newCommand.CommentBody.length());
             newCommand.IsPublished = TRUE;
             newCommand.ParentId =case.Id;
            insert newCommand;

When I make a debug, I receive that the length of the case comment I am about to insert is 3798, but I still get the error:

error: STRING_TOO_LONG, Body: data value too large:........... (max length=4000): [CommentBody]

This just happens with emails sent with chinese characters.

Did anyone face this issue before? Anyone has an idea on how to fix this?

Thanks a lot,

Antonio
Hi,

I have got a visualforce page, where I am showing in a table a list of cases I get from my Apex Class.

This is my visualforce:

<apex:page controller="XMLCasePopupController" title="Search" showHeader="false" sideBar="false" tabStyle="Case" id="page" >
  <!-- messages -->
  <apex:outputPanel id="top" layout="block">
    <apex:outputLabel value="Possible duplicates" style="margin:20px; padding:10px; margin-top:10px; font-weight:bold; font-size: 1.5em;"/>
  </apex:outputPanel>

  <apex:form >
  <apex:pageBlock title="XML Case Edit" id="XML_Case_Edit" mode="Edit">
      <!-- Buttons toolbar -->   
        <apex:pageBlockButtons >
            <apex:commandButton value="Finish" action="{!endCaseCreation}"/>
        <!--    <apex:commandButton value="Back" action="{!backStep}"/> -->
        </apex:PageBlockButtons>
      
        <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
  <apex:actionRegion >
      <!-- results panel -->
      <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
          <apex:pageBlock id="searchResults">
             <apex:pageBlockTable value="{!results}" var="c" id="tblResults">
                    <apex:column >
                    <apex:facet name="header">
                        <apex:outputPanel >Release</apex:outputPanel>
                    </apex:facet>
                    <apex:outputLink onClick="test('{!c.Id}');return false;">{!c.Module_Release__c}</apex:outputLink>
                    </apex:column>
</apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock>
      </apex:outputPanel>
  </apex:actionRegion>
  </apex:outputPanel>
    </apex:pageBlock>
    <apex:actionFunction name="test" action="{!ShowCaseToTrue}">
        <apex:param name="param1" assignto="{!IdChosen}" value=""/>
    </apex:actionFunction>
  </apex:form>

So I am calling the actionFunction ShowCaseToTrue and I want to pass the Id of the case that the user has clicked in the table. This is my apex class:

public with sharing class XMLCasePopupController {


  public List<Case> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
  public string caseId{get;set;}
  public Boolean ShowCase{get;set;}
  public Case ChosenCase{get;set;}
  public Id IdChosen{get;set;}

  public XMLCasePopupController() {
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    caseId = System.currentPageReference().getParameters().get('id');
    //ShowCase=False;
    System.debug('==> searchString = ' + searchString + ' -- caseid ' + caseId);
    runSearch();
  }

  // performs the keyword search
  public PageReference search() {
    runSearch();

    return null;
  }

  // performs the keyword search
  public void ShowCaseToTrue() {
    this.ShowCase=True;
    system.debug('El id que tengo que buscar es: '+ IdChosen);
    ChosenCase=[SELECT Id,CaseNumber FROM Case WHERE Id=:IdChosen];
  }
}

I am always getting a null value in IdChosen. Can anybody help me on what I am missing here?

Thanks a lot!

Antonio
Hi,

I have got a visualforce page, where I am showing in a table a list of cases I get from my Apex Class.

This is my visualforce:

<apex:page controller="XMLCasePopupController" title="Search" showHeader="false" sideBar="false" tabStyle="Case" id="page" >
  <!-- messages -->
  <apex:outputPanel id="top" layout="block">
    <apex:outputLabel value="Possible duplicates" style="margin:20px; padding:10px; margin-top:10px; font-weight:bold; font-size: 1.5em;"/>
  </apex:outputPanel>

  <apex:form >
  <apex:pageBlock title="XML Case Edit" id="XML_Case_Edit" mode="Edit">
      <!-- Buttons toolbar -->    
        <apex:pageBlockButtons >
            <apex:commandButton value="Finish" action="{!endCaseCreation}"/>
        <!--    <apex:commandButton value="Back" action="{!backStep}"/> -->
        </apex:PageBlockButtons>
       
        <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
  <apex:actionRegion >
      <!-- results panel -->
      <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
          <apex:pageBlock id="searchResults">
             <apex:pageBlockTable value="{!results}" var="c" id="tblResults">
                    <apex:column >
                    <apex:facet name="header">
                        <apex:outputPanel >Release</apex:outputPanel>
                    </apex:facet>
                    <apex:outputLink onClick="test('{!c.Id}');return false;">{!c.Module_Release__c}</apex:outputLink>
                    </apex:column>
</apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock>
      </apex:outputPanel>
  </apex:actionRegion>
  </apex:outputPanel>
    </apex:pageBlock>
    <apex:actionFunction name="test" action="{!ShowCaseToTrue}">
        <apex:param name="param1" assignto="{!IdChosen}" value=""/>
    </apex:actionFunction>
  </apex:form>

So I am calling the actionFunction ShowCaseToTrue and I want to pass the Id of the case that the user has clicked in the table. This is my apex class:

public with sharing class XMLCasePopupController {

 
  public List<Case> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
  public string caseId{get;set;}
  public Boolean ShowCase{get;set;}
  public Case ChosenCase{get;set;}
  public Id IdChosen{get;set;}
 
  public XMLCasePopupController() {
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    caseId = System.currentPageReference().getParameters().get('id');
    //ShowCase=False;
    System.debug('==> searchString = ' + searchString + ' -- caseid ' + caseId);
    runSearch(); 
  }

  // performs the keyword search
  public PageReference search() {
    runSearch();
 
    return null;
  }

  // performs the keyword search
  public void ShowCaseToTrue() {
    this.ShowCase=True;
    system.debug('El id que tengo que buscar es: '+ IdChosen);
    ChosenCase=[SELECT Id,CaseNumber FROM Case WHERE Id=:IdChosen];
  }
}

I am always getting a null value in IdChosen. Can anybody help me on what I am missing here?

Thanks a lot!

Antonio

Hi,

 

I have a surely easy requirement but I cant manage to get it. I have my case, and I need to send an email (though Apex) with the case description (between other fields). I have my case description with line breaks as follows:

 

"Hello hello hello



And two two two


Three
Three"

 

I send the email with the following code:

 

 

String HTMLDesc=case2.Description.escapeHtml3();
mail.setToAddresses(toAddresses);
mail.setSubject('YYYYYou have been involved in the XML Case #'+Case2.CaseNumber);
mail.setHtmlBody('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><table><tr><td>You are receiving this e-mail because you have been added to the referenced XML Support case. If you wish to post a comment to the case, please respond to the unique email address provided for this case without modifying the subject. </td></tr></table><br><table style="width:100%;border-collapse: collapse;"><tr><td style="padding:5px 0;width:140px;border-bottom:1px solid #aaa;">Case Description:</td><td style="padding:5px 0;width:560px;border-bottom:1px solid #aaa;">'+HTMLDesc+'</td></tr><br><br>Regards, <br>'+UserInfo.getName()+'<br>Clients Integration Support <br>Hotelbeds<br><br></html>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

But I am getting the case description in plain text as follows:

 

"Hello hello hello And two two two Three Three"

 

Thanks a lot!

 

Antonio

 

Hi, 

I have got this code in one of my visualforce pages: 

<apex:pageBlockSectionItem > 
<apex:outputLabel value="2. Does your system allow to change children ages during the booking process? (We do not allow it)" style="float: left;width:150px;"/> 
<apex:outputPanel > 
<apex:inputField value="{!Survey__c.System_allow_to_change_children_age__c}"> 
<apex:actionSupport event="onchange" rerender="Survey_Info" status="status"/> 
</apex:inputField> 
<apex:actionStatus id="status"/> 
</apex:outputPanel> 
</apex:pageBlockSectionItem> 

 

I want to show the long line "2. Does your system allow to change children ages during the booking process? (We do not allow it)" but the flag style is not working and I see everything in one line when I want to see it in two lines.(inserting a break line in the middle

Can you indicate me how to do it? 

Thanks, 

Antonio

Hi,

 

I need to send an attachment  via email through apex.

 

What I do in my code is create a case, then request for the attachment and once the attachment is introduces I send the email. This attachment can be in multiple formats (xls, txt,...).

 

I am able to send the attachment, but not in the correct format...Can you tell me please what I am doing wrong?

 

public PageReference uploadAndSendEmail() {
     
    //Upload the file
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = case1.Id; // the record the file is attached to
    attachment.IsPrivate = false;
   
   //I get the intranet Id of the user
    User u=[SELECT Id,Intranet_ID__c FROM User WHERE Id=:case2.OwnerId];
    string interfaceId=u.Intranet_ID__c;
    if (attachment.Body!=NULL){
    	try {
      		//Introduce the attachment
      		insert attachment;
      		//and create and send email
        	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        	String[] toAddresses = new String[] {'a.***@****.com'};
        	mail.setToAddresses(toAddresses);
        	
        	Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[1];
  	        Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
      		fileAttachment.setBody(attachment.body);
      		fileAttachment.setFileName(attachment.name);
      		fileattachment.setContentType(attachment.ContentType);
      		fileAttachments[0] = fileAttachment;
   		mail.setFileAttachments(fileAttachments);
        	mail.setSubject('New Request: ' + Case2.Subject + ' - ' + Case2.Id + ' - PROJ=32 -     ISSUE='+Case2.Footprints_ID__c);// New Request: {!Case.RecordType} - {!Case.Id} - PROJ=32 - ISSUE={!Case.Footprints_ID__c}
        	mail.setPlainTextBody('Sender= '+string.valueOf(u.Intranet_ID__c)+'\n'+
        							'New Category='+Case2.Footprints_Category__c+'\n'+
        							'NewSubcategory='+Case2.Footprints_SubCategory__c+'\n'+
        							'SFID='+Case2.Id+'\n'+
        							'SF=Yes\n'+
        							'Atlas Code: '+ Case2.Atlas_Code__c+'\n'+
        							'Ebilling Email: '+ Case2.E_billing_Email__c+'\n'+
        							'Ebilling Frequency: '+ Case2.E_billing_Frequency__c+'\n'+
        							'Comments: '+ Case2.Comments_for_Admin__c);
        	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      		
    	} catch (DMLException e) {
      		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      		return null;
    	} finally {
      		attachment = new Attachment(); 
    	}
    }else{
//DOESNT MATTER. Sends a different email
      }
    	
  }
    //Fin attachments

 

Any help is appreciated.

 

Thanks!

 

Antonio

Hi,

 

I need to send an attachment  via email through apex.

 

What I do in my code is create a case, then request for the attachment and once the attachment is introduces I send the email. This attachment can be in multiple formats (xls, txt,...).

 

I am able to send the attachment, but not in the correct format...Can you tell me please what I am doing wrong?

 

public PageReference uploadAndSendEmail() {
     
    //Upload the file
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = case1.Id; // the record the file is attached to
    attachment.IsPrivate = false;
   
   //I get the intranet Id of the user
    User u=[SELECT Id,Intranet_ID__c FROM User WHERE Id=:case2.OwnerId];
    string interfaceId=u.Intranet_ID__c;
    if (attachment.Body!=NULL){
    	try {
      		//Introduce the attachment
      		insert attachment;
      		//and create and send email
        	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        	String[] toAddresses = new String[] {'a.***@****.com'};
        	mail.setToAddresses(toAddresses);
        	
        	Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[1];
  	        Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
      		fileAttachment.setBody(attachment.body);
      		fileAttachment.setFileName(attachment.name);
      		fileattachment.setContentType(attachment.ContentType);
      		fileAttachments[0] = fileAttachment;
   		mail.setFileAttachments(fileAttachments);
        	mail.setSubject('New Request: ' + Case2.Subject + ' - ' + Case2.Id + ' - PROJ=32 -     ISSUE='+Case2.Footprints_ID__c);// New Request: {!Case.RecordType} - {!Case.Id} - PROJ=32 - ISSUE={!Case.Footprints_ID__c}
        	mail.setPlainTextBody('Sender= '+string.valueOf(u.Intranet_ID__c)+'\n'+
        							'New Category='+Case2.Footprints_Category__c+'\n'+
        							'NewSubcategory='+Case2.Footprints_SubCategory__c+'\n'+
        							'SFID='+Case2.Id+'\n'+
        							'SF=Yes\n'+
        							'Atlas Code: '+ Case2.Atlas_Code__c+'\n'+
        							'Ebilling Email: '+ Case2.E_billing_Email__c+'\n'+
        							'Ebilling Frequency: '+ Case2.E_billing_Frequency__c+'\n'+
        							'Comments: '+ Case2.Comments_for_Admin__c);
        	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      		
    	} catch (DMLException e) {
      		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      		return null;
    	} finally {
      		attachment = new Attachment(); 
    	}
    }else{
//DOESNT MATTER. Sends a different email
      }
    	
  }
    //Fin attachments

 

Any help is appreciated.

 

Thanks!

 

Antonio

Hi,

 

I need to send an attachment  via email through apex.

 

What I do in my code is create a case, then request for the attachment and once the attachment is introduces I send the email. This attachment can be in multiple formats (xls, txt,...).

 

I am able to send the attachment, but not in the correct format...Can you tell me please what I am doing wrong?

 

public PageReference uploadAndSendEmail() {
     
    //Upload the file
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = case1.Id; // the record the file is attached to
    attachment.IsPrivate = false;
   
   //I get the intranet Id of the user
    User u=[SELECT Id,Intranet_ID__c FROM User WHERE Id=:case2.OwnerId];
    string interfaceId=u.Intranet_ID__c;
    if (attachment.Body!=NULL){
    	try {
      		//Introduce the attachment
      		insert attachment;
      		//and create and send email
        	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        	String[] toAddresses = new String[] {'a.***@****.com'};
        	mail.setToAddresses(toAddresses);
        	
        	Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[1];
  	        Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
      		fileAttachment.setBody(attachment.body);
      		fileAttachment.setFileName(attachment.name);
      		fileattachment.setContentType(attachment.ContentType);
      		fileAttachments[0] = fileAttachment;
   		mail.setFileAttachments(fileAttachments);
        	mail.setSubject('New Request: ' + Case2.Subject + ' - ' + Case2.Id + ' - PROJ=32 -     ISSUE='+Case2.Footprints_ID__c);// New Request: {!Case.RecordType} - {!Case.Id} - PROJ=32 - ISSUE={!Case.Footprints_ID__c}
        	mail.setPlainTextBody('Sender= '+string.valueOf(u.Intranet_ID__c)+'\n'+
        							'New Category='+Case2.Footprints_Category__c+'\n'+
        							'NewSubcategory='+Case2.Footprints_SubCategory__c+'\n'+
        							'SFID='+Case2.Id+'\n'+
        							'SF=Yes\n'+
        							'Atlas Code: '+ Case2.Atlas_Code__c+'\n'+
        							'Ebilling Email: '+ Case2.E_billing_Email__c+'\n'+
        							'Ebilling Frequency: '+ Case2.E_billing_Frequency__c+'\n'+
        							'Comments: '+ Case2.Comments_for_Admin__c);
        	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      		
    	} catch (DMLException e) {
      		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      		return null;
    	} finally {
      		attachment = new Attachment(); 
    	}
    }else{
//DOESNT MATTER. Sends a different email
      }
    	
  }
    //Fin attachments

 

Any help is appreciated.

 

Thanks!

 

Antonio

Hi,

 

I have a custom button, Close Lead, that redirects the user to a visualforce page.

 

This is the URL of the visualforce page:

 

https://c.cs8.visual.force.com/apex/CloseLeadReason?Status=Lead%20Closed&id=00QL0000001wv7v

 

And this is the visualforce page. very simple, just showing to fields, lead status and lead status result:

 

<apex:page standardController="Lead" showHeader="true">
    <apex:sectionHeader title="Lead Edit" subtitle="{!Lead.Company}"/>  
    <apex:form >
        <apex:pageBlock title="Lead Edit" id="Edit_Fiscal_Information" mode="Edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Close" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:PageBlockButtons>
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Lead Status"/>
                        <apex:inputField value="{!lead.Status}"/>
                    </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Lead Status Result"/>
                        <apex:inputField value="{!lead.Lead_Status_Result__c}"/>
                 </apex:pageBlockSectionItem>
            </apex:pageblockSection>
       </apex:pageBlock>
     </apex:form>
</apex:page>

 

I want to prepopulate the field status with the value of the picklist 'Lead Closed' using the URL, but I am not able to do so.

 

Can anyone show me how to get it?

 

Thanks a lot!

 

Antonio

Hi all,

 

I have a problem making a call out to another system receiving the following error during debug:

 

common.apex.runtime.impl.ExecutionException: Received fatal alert: bad_record_mac"|0x56b08894

 

In my code I create an http request using the following endpoint:

 

req.setEndpoint('https://mdm.tuitravel-ad.com/mdmclients/secure/mdm.wsdl');

 

When I send the same request to the same endpoint using a Firefox SOA Cliente the request is accepeted.

We have already try this code before to a http endpoint but now, working in production, we need to make the request to an https endpoint and is when the issue appeared.

 

Could somebody help please? In case it might help, this is the certificate we use:THAWTE SSL CA

 

 

 

If any other information is needed please let me know.

 

Regards,

 

Antonio

Hi all,

 

I have a problem making a call out to another system receiving the following error during debug:

 

common.apex.runtime.impl.ExecutionException: Received fatal alert: bad_record_mac"|0x56b08894

 

In my code I create an http request using the following endpoint:

 

req.setEndpoint('https://mdm.tuitravel-ad.com/mdmclients/secure/');

 

When I send the same request to the same endpoint using a Firefox SOA Cliente the request is accepeted.

We have already try this code before to a http endpoint but now, working in production, we need to make the request to an https endpoint and is when the issue appeared.

 

Could somebody help please?

 

If any other information is needed please let me know.

 

Regards,

 

Antonio

Hi all,

 

I have a problem making a call out to another system receiving the following error during debug:

 

common.apex.runtime.impl.ExecutionException: Received fatal alert: bad_record_mac"|0x56b08894

 

In my code I create an http request using the following endpoint:

 

req.setEndpoint('https://mdm.tuitravel-ad.com/mdmclients/secure/');

 

When I send the same request to the same endpoint using a Firefox SOA Cliente the request is accepeted.

We have already try this code before to a http endpoint but now, working in production, we need to make the request to an https endpoint and is when the issue appeared.

 

Could somebody help please?

 

If any other information is needed please let me know.

 

Regards,

 

Antonio

 

Hi,

 

I have a user that just has one lead record type assinged to him.

 

I have also overwritten the new lead button with the visualforce page LeadCreation_Commercial Information without skiping the recordtype selection screen.

 

If a profile has more than one record type I dont have any problem and after the user selects the record type that wants to create, I am correctly redirected to the url:

 

https://c.eu1.visual.force.com/apex/LeadCreation_CommercialInformation?RecordType=012D000000031xH&retURL=%2F00Q%2Fo&sfdc.override=1&save_new=1&ent=Lead

 

But when a user has just one record type assinged to his profile, when clicking on create new I just get a blank page and the followint URL that doesnt indicate any record type:

 

https://c.eu1.visual.force.com/apex/LeadCreation_CommercialInformation?retURL=%2F00Q%2Fo&sfdc.override=1&save_new=1

 

Shouldnt the recordtype be in the URL always by default?Is this a problem with my code or a bug?

 

I wasnt expecting this error at all. Thanks a lot for your help.

 

Regards,

 

Antonio

 

 

Hi,

 

I the following code:

 

global class AccountSynchBatch implements Database.Batchable<sObject>,Database.AllowsCallouts{
    
    global Integer result=0;
    global Integer Mains=0;
    global Integer branches=0;
    global Integer errores=0;
    global AccountSynchBatch()
	{
    }

    global Database.QueryLocator start(Database.BatchableContext BC)
	{
        return DataBase.getQueryLocator([SELECT Id,Account_to_be_Synch__c,Atlas_Branch_Number__c FROM account WHERE Account_to_be_synch__c=True]);
	}
	
    global void execute(Database.BatchableContext BC,List<sObject> scopeAcc)
	{	
        for (Integer i=0;i<scopeAcc.size();i++){ 
            if (scopeAcc.get(i).get('Atlas_Branch_Number__c')==-1){
            	result=myCallOuts.SyncMainAccount(scopeAcc.get(i).Id);
            	Mains=mains+1;
            }else{
                result=myCallOuts.SyncBranchAccount(scopeAcc.get(i).Id);
                branches=branches+1;
            }
            if (result==1){
                scopeAcc.get(i).put('Account_to_be_synch__c',False);
            }else{
            	errores++;
            }
    	}
        update scopeAcc;
        system.debug('Mains:'+Mains);
        system.debug('Branches:'+Branches);
        system.debug('Errores:'+errores);
	}
    
    global void finish(Database.BatchableContext BC)
	{
    	//Send an email to the User after your batch completes
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		String[] toAddresses = new String[] {'a.tejado@hotelbeds.com'};
		mail.setToAddresses(toAddresses);
		mail.setSubject('Apex Batch Synch Job is done');
		mail.setPlainTextBody('The batch Apex Synch job processed with the result: Main Accounts Synch: '+Mains+', Branches Accounts Synch: '+Branches+', Errores: '+errores);
		Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
	}

}

 

When I try to acces to the three variables Mains, Branches and Errores in the finish method, even though Im sure I introduce a value in them in the execute method, I always get a 0 in the mail.

 

How do I have to declare the variables to be able of accessing them from any method?

 

Thanks,

 

Antonio

Hi,

 

I need to create a trigger but I have problems to create it in a "bulk" way. This is the requirement:

 

I have accounts which are related to another one (called the main). I can have up to 15 accounts related to this main one.

 

When some field of the main account, as the account name or address, are modified, I need to replicate this change to the accounts that are related to this main one. This change doesnt have to be replicated always, just when the related accounts fulfills a condition based on its accountrecordtype

 

I can do

 

For [a: in trigger.new]{

Account RelatedAccount=[SELECT id, recordtypeId FROM Account Where RelatedAccountId:=a.Id];

 

}

 

But this wouldnt be the bulk way and I would probably get errors.

 


Any help is appreciated.

Thanks,

Antonio

Hi all,

In my org, when a customer service agent is working on a case and hits the send email button to use the standard send email functionality, I hav a requirement that is:
- Capture the body of the email and create with it a Case Comment related to the parent case of the email. Also, get all the attachments related to the email and relate them to the case. Finally, delete the email message.

I am able to do everything except for the attachments part. I have created a trigger on emailMessage that creates the case comment without trouble, but another part of my trigger is created to get the attachments, but it always returns 0 elements in the list. This is the trigger on email message related to the attachment part(just getting the attachment of the first email to check if it works):
 
trigger EmailMessageAfterOperationTrigger on EmailMessage (after delete, after insert, after undelete, after update) {

if (trigger.isInsert){
    	Attachment[] attList = [select id, name, body from Attachment where ParentId = :Trigger.new[0].Id];
    	Attachment[] insertAttList = new Attachment[]{};

        system.debug('Has the email attachments?:' + Trigger.new[0].HasAttachment);
    	system.debug('list of attachments realted to the email message: ' + attList);

    	for(Attachment a: attList){
               Attachment att = new Attachment(name = a.name, body = a.body, parentid = Trigger.new[0].id);
               insertAttList.add(att);
        }
       if(insertAttList.size() > 0){
            insert insertAttList;
       }
    	
    }
This is the debug log the system shows:
 
09:45:00.579 (1579755455)|USER_DEBUG|[146]|DEBUG|Has the email attachments?:true
09:45:00.579 (1579760206)|SYSTEM_METHOD_EXIT|[146]|System.debug(ANY)
09:45:00.579 (1579778024)|SYSTEM_METHOD_ENTRY|[147]|String.valueOf(Object)
09:45:00.579 (1579802168)|SYSTEM_METHOD_EXIT|[147]|String.valueOf(Object)
09:45:00.579 (1579814171)|SYSTEM_METHOD_ENTRY|[147]|System.debug(ANY)
09:45:00.579 (1579819259)|USER_DEBUG|[147]|DEBUG|list of attachments realted to the email message: ()

I have also created a trigger on attachment before insert but it doesnt get fired when sending an email with attachment:
 
trigger AttachmentBeforeOperationTrigger on Attachment (before delete, before insert, before update) {

	if (Trigger.isInsert || Trigger.isUpdate){
		for (Attachment a: Trigger.new){
			system.debug('el attachment: ' + a);
		}
	}

}

I need to get this attachments related to the email message, can please anyone help me?

Thanks,

Antonio





 
Hi,

I have got a visualforce page, where I am showing in a table a list of cases I get from my Apex Class.

This is my visualforce:

<apex:page controller="XMLCasePopupController" title="Search" showHeader="false" sideBar="false" tabStyle="Case" id="page" >
  <!-- messages -->
  <apex:outputPanel id="top" layout="block">
    <apex:outputLabel value="Possible duplicates" style="margin:20px; padding:10px; margin-top:10px; font-weight:bold; font-size: 1.5em;"/>
  </apex:outputPanel>

  <apex:form >
  <apex:pageBlock title="XML Case Edit" id="XML_Case_Edit" mode="Edit">
      <!-- Buttons toolbar -->    
        <apex:pageBlockButtons >
            <apex:commandButton value="Finish" action="{!endCaseCreation}"/>
        <!--    <apex:commandButton value="Back" action="{!backStep}"/> -->
        </apex:PageBlockButtons>
       
        <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
  <apex:actionRegion >
      <!-- results panel -->
      <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
          <apex:pageBlock id="searchResults">
             <apex:pageBlockTable value="{!results}" var="c" id="tblResults">
                    <apex:column >
                    <apex:facet name="header">
                        <apex:outputPanel >Release</apex:outputPanel>
                    </apex:facet>
                    <apex:outputLink onClick="test('{!c.Id}');return false;">{!c.Module_Release__c}</apex:outputLink>
                    </apex:column>
</apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock>
      </apex:outputPanel>
  </apex:actionRegion>
  </apex:outputPanel>
    </apex:pageBlock>
    <apex:actionFunction name="test" action="{!ShowCaseToTrue}">
        <apex:param name="param1" assignto="{!IdChosen}" value=""/>
    </apex:actionFunction>
  </apex:form>

So I am calling the actionFunction ShowCaseToTrue and I want to pass the Id of the case that the user has clicked in the table. This is my apex class:

public with sharing class XMLCasePopupController {

 
  public List<Case> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
  public string caseId{get;set;}
  public Boolean ShowCase{get;set;}
  public Case ChosenCase{get;set;}
  public Id IdChosen{get;set;}
 
  public XMLCasePopupController() {
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    caseId = System.currentPageReference().getParameters().get('id');
    //ShowCase=False;
    System.debug('==> searchString = ' + searchString + ' -- caseid ' + caseId);
    runSearch(); 
  }

  // performs the keyword search
  public PageReference search() {
    runSearch();
 
    return null;
  }

  // performs the keyword search
  public void ShowCaseToTrue() {
    this.ShowCase=True;
    system.debug('El id que tengo que buscar es: '+ IdChosen);
    ChosenCase=[SELECT Id,CaseNumber FROM Case WHERE Id=:IdChosen];
  }
}

I am always getting a null value in IdChosen. Can anybody help me on what I am missing here?

Thanks a lot!

Antonio
Hi all,

In my org, when a customer service agent is working on a case and hits the send email button to use the standard send email functionality, I hav a requirement that is:
- Capture the body of the email and create with it a Case Comment related to the parent case of the email. Also, get all the attachments related to the email and relate them to the case. Finally, delete the email message.

I am able to do everything except for the attachments part. I have created a trigger on emailMessage that creates the case comment without trouble, but another part of my trigger is created to get the attachments, but it always returns 0 elements in the list. This is the trigger on email message related to the attachment part(just getting the attachment of the first email to check if it works):
 
trigger EmailMessageAfterOperationTrigger on EmailMessage (after delete, after insert, after undelete, after update) {

if (trigger.isInsert){
    	Attachment[] attList = [select id, name, body from Attachment where ParentId = :Trigger.new[0].Id];
    	Attachment[] insertAttList = new Attachment[]{};

        system.debug('Has the email attachments?:' + Trigger.new[0].HasAttachment);
    	system.debug('list of attachments realted to the email message: ' + attList);

    	for(Attachment a: attList){
               Attachment att = new Attachment(name = a.name, body = a.body, parentid = Trigger.new[0].id);
               insertAttList.add(att);
        }
       if(insertAttList.size() > 0){
            insert insertAttList;
       }
    	
    }
This is the debug log the system shows:
 
09:45:00.579 (1579755455)|USER_DEBUG|[146]|DEBUG|Has the email attachments?:true
09:45:00.579 (1579760206)|SYSTEM_METHOD_EXIT|[146]|System.debug(ANY)
09:45:00.579 (1579778024)|SYSTEM_METHOD_ENTRY|[147]|String.valueOf(Object)
09:45:00.579 (1579802168)|SYSTEM_METHOD_EXIT|[147]|String.valueOf(Object)
09:45:00.579 (1579814171)|SYSTEM_METHOD_ENTRY|[147]|System.debug(ANY)
09:45:00.579 (1579819259)|USER_DEBUG|[147]|DEBUG|list of attachments realted to the email message: ()

I have also created a trigger on attachment before insert but it doesnt get fired when sending an email with attachment:
 
trigger AttachmentBeforeOperationTrigger on Attachment (before delete, before insert, before update) {

	if (Trigger.isInsert || Trigger.isUpdate){
		for (Attachment a: Trigger.new){
			system.debug('el attachment: ' + a);
		}
	}

}

I need to get this attachments related to the email message, can please anyone help me?

Thanks,

Antonio





 
Hi,

I have a visualforce page where I am showing all the attachments related to a case with a checkbox to know if the user has marked it. This is the related part of the VF page:

<apex:pageBlock title="Existing Case Attachments">
    <apex:pageBlockTable value="{!listAttachWrapper}" var="item">
        <apex:column title="Select" headerValue="Add Attachment" width="50px,50px">
            <apex:inputCheckbox value="{!item.IsChecked}">
                </apex:inputCheckbox>
        </apex:column>
        <apex:column headerValue="File">
            <apex:outputLink value="{!URLFOR($Action.Attachment.Download,item.att.Id)}"
                target="_blank">{!item.att.Name}</apex:outputLink>
        </apex:column>
        <apex:column value="{!item.att.Description}" />
    </apex:pageBlockTable>
</apex:pageBlock>

I also have my controller with the definition of the wrapper class:

public List<attWrapper> listAttachWrapper {get;set;}
public List <Attachment> selectedmems{get;set;}
public class attWrapper{
    public Attachment att {get; set;}
    public Boolean isChecked{get; set;}
    public attWrapper(Attachment att){
        this.att=att;
        if (isChecked==null){
            isChecked=false;
        }
    }
}

And in the constructor of the method, I get the elements and mark the ischecked field to false:

listAttachWrapper=new List<attWrapper>();
for (Attachment a:[SELECT Name,Description FROM Attachment WHERE ParentId=:case1.Id])
        listAttachWrapper.add(new attWrapper(a));

Finally I have the method that is called from the VF page, where I try to get which attachments have been market to true:

selectedmems=new List<Attachment>();
system.debug('List of members: '+listAttachWrapper);
for (attWrapper att: listAttachWrapper){
    if (att.IsChecked==true){
        selectedmems.add(att.att);
    }
}
system.debug('The list is:' + selectedmems);

The problem is that I get all the elements with the IsChecked field to false, even though I am selecting them in the VF page.

I have been for two days already with this, can anyone help please?

Thanks a lot!

Antonio
Hi,

I have a visualforce page where I am showing all the attachments related to a case with a checkbox to know if the user has marked it. This is the related part of the VF page:
<apex:pageBlock title="Existing Case Attachments">
        <apex:pageBlockTable value="{!listAttachWrapper}" var="item">
            <apex:column title="Select" headerValue="Add Attachment" width="50px,50px">
                <apex:inputCheckbox value="{!item.IsChecked}">
                    </apex:inputCheckbox>
            </apex:column>
            <apex:column headerValue="File">
                <apex:outputLink value="{!URLFOR($Action.Attachment.Download, item.att.Id)}"
                    target="_blank">{!item.att.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!item.att.Description}" />
        </apex:pageBlockTable>
    </apex:pageBlock>

I also have my controller with the definition of the wrapper class:

public List<attWrapper> listAttachWrapper {get;set;}
public List <Attachment> selectedmems{get;set;}
   
public class attWrapper{
	public Attachment att {get; set;}
      	public Boolean isChecked{get; set;}
      
      	public attWrapper(Attachment att){
      		this.att=att;
        	if (isChecked==null){
        		isChecked=false;
        	}
      	}
    }

And in the constructor of the method, I get the elements and mark the ischecked field to false:

listAttachWrapper=new List<attWrapper>();
for (Attachment a:[SELECT Name,Description FROM Attachment WHERE ParentId=:case1.Id])
			listAttachWrapper.add(new attWrapper(a));

Finally I have the method that is called from the VF page, where I try to get which attachments have been market to true:

selectedmems=new List<Attachment>();
system.debug('List of members: '+listAttachWrapper);
for (attWrapper att: listAttachWrapper){
                	if (att.IsChecked==true){
                		selectedmems.add(att.att);
                	}
                }
system.debug('The list is:' + selectedmems);

The problem is that I get all the elements with the IsChecked field to false, even though I am selecting them in the VF page.

I have been for two days already with this, can anyone help please?

Thanks a lot!

Antonio




Hi,

I have a requirement for the community portal. It says that for picklist fields, when the user is checking the available options in the piclist, when the user mouse over each one of the values, the system should show a help text.

Is there anyway to do so using Javascript or Jquery? Could someone point me on the right direction please?

I know i can show the standar salesfoce help text on my visualforce page, but I have around 30 options in the picklist, so its quite confusing to do it with this standard funcionality.

Any help is appreciated!

All the best,

Antonio
Hi,

When creating a lead, I need to compare the lead Fiscal number field with the account fiscal number in a soql query. 
The issue comes with this case:
Lead Fiscal Number: DE12345
Account Fiscal Number: 12345

I want the query to detect this situation and return me the account in the list, but it doesnt appear:

This is my code:

        string FiscalNumber1Lead='%' + lead.Fiscal_Number_1__c + '%';
      
        return [Select ID, Name, Owner.Name, Fiscal_Number_2__c, Fiscal_Number_1__c,KAM__c,AccountNumber,Account_Status__c,Commercial_Brand__c, Inactive_Reason__c From Account
        Where ((Fiscal_Number_1__c LIKE :FiscalNumber1Lead))  limit 100];

But with this situation I am comparing  '12345' like: '%DE12345%', and obviously returns me no results....

I also tried to change the condition to:

Where ((l2.Fiscal_Number_1__c LIKE :Fiscal_Number_1__c)) but it returns me an error in the code.

Can anybody give help me please?

Thanks,

Antonio

Hi,

 

I have a surely easy requirement but I cant manage to get it. I have my case, and I need to send an email (though Apex) with the case description (between other fields). I have my case description with line breaks as follows:

 

"Hello hello hello



And two two two


Three
Three"

 

I send the email with the following code:

 

 

String HTMLDesc=case2.Description.escapeHtml3();
mail.setToAddresses(toAddresses);
mail.setSubject('YYYYYou have been involved in the XML Case #'+Case2.CaseNumber);
mail.setHtmlBody('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><table><tr><td>You are receiving this e-mail because you have been added to the referenced XML Support case. If you wish to post a comment to the case, please respond to the unique email address provided for this case without modifying the subject. </td></tr></table><br><table style="width:100%;border-collapse: collapse;"><tr><td style="padding:5px 0;width:140px;border-bottom:1px solid #aaa;">Case Description:</td><td style="padding:5px 0;width:560px;border-bottom:1px solid #aaa;">'+HTMLDesc+'</td></tr><br><br>Regards, <br>'+UserInfo.getName()+'<br>Clients Integration Support <br>Hotelbeds<br><br></html>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

But I am getting the case description in plain text as follows:

 

"Hello hello hello And two two two Three Three"

 

Thanks a lot!

 

Antonio

 

Hi, 

I have got this code in one of my visualforce pages: 

<apex:pageBlockSectionItem > 
<apex:outputLabel value="2. Does your system allow to change children ages during the booking process? (We do not allow it)" style="float: left;width:150px;"/> 
<apex:outputPanel > 
<apex:inputField value="{!Survey__c.System_allow_to_change_children_age__c}"> 
<apex:actionSupport event="onchange" rerender="Survey_Info" status="status"/> 
</apex:inputField> 
<apex:actionStatus id="status"/> 
</apex:outputPanel> 
</apex:pageBlockSectionItem> 

 

I want to show the long line "2. Does your system allow to change children ages during the booking process? (We do not allow it)" but the flag style is not working and I see everything in one line when I want to see it in two lines.(inserting a break line in the middle

Can you indicate me how to do it? 

Thanks, 

Antonio

Hi,

 

I need to send an attachment  via email through apex.

 

What I do in my code is create a case, then request for the attachment and once the attachment is introduces I send the email. This attachment can be in multiple formats (xls, txt,...).

 

I am able to send the attachment, but not in the correct format...Can you tell me please what I am doing wrong?

 

public PageReference uploadAndSendEmail() {
     
    //Upload the file
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = case1.Id; // the record the file is attached to
    attachment.IsPrivate = false;
   
   //I get the intranet Id of the user
    User u=[SELECT Id,Intranet_ID__c FROM User WHERE Id=:case2.OwnerId];
    string interfaceId=u.Intranet_ID__c;
    if (attachment.Body!=NULL){
    	try {
      		//Introduce the attachment
      		insert attachment;
      		//and create and send email
        	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        	String[] toAddresses = new String[] {'a.***@****.com'};
        	mail.setToAddresses(toAddresses);
        	
        	Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[1];
  	        Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
      		fileAttachment.setBody(attachment.body);
      		fileAttachment.setFileName(attachment.name);
      		fileattachment.setContentType(attachment.ContentType);
      		fileAttachments[0] = fileAttachment;
   		mail.setFileAttachments(fileAttachments);
        	mail.setSubject('New Request: ' + Case2.Subject + ' - ' + Case2.Id + ' - PROJ=32 -     ISSUE='+Case2.Footprints_ID__c);// New Request: {!Case.RecordType} - {!Case.Id} - PROJ=32 - ISSUE={!Case.Footprints_ID__c}
        	mail.setPlainTextBody('Sender= '+string.valueOf(u.Intranet_ID__c)+'\n'+
        							'New Category='+Case2.Footprints_Category__c+'\n'+
        							'NewSubcategory='+Case2.Footprints_SubCategory__c+'\n'+
        							'SFID='+Case2.Id+'\n'+
        							'SF=Yes\n'+
        							'Atlas Code: '+ Case2.Atlas_Code__c+'\n'+
        							'Ebilling Email: '+ Case2.E_billing_Email__c+'\n'+
        							'Ebilling Frequency: '+ Case2.E_billing_Frequency__c+'\n'+
        							'Comments: '+ Case2.Comments_for_Admin__c);
        	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      		
    	} catch (DMLException e) {
      		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      		return null;
    	} finally {
      		attachment = new Attachment(); 
    	}
    }else{
//DOESNT MATTER. Sends a different email
      }
    	
  }
    //Fin attachments

 

Any help is appreciated.

 

Thanks!

 

Antonio

Hi,

 

I have a custom button, Close Lead, that redirects the user to a visualforce page.

 

This is the URL of the visualforce page:

 

https://c.cs8.visual.force.com/apex/CloseLeadReason?Status=Lead%20Closed&id=00QL0000001wv7v

 

And this is the visualforce page. very simple, just showing to fields, lead status and lead status result:

 

<apex:page standardController="Lead" showHeader="true">
    <apex:sectionHeader title="Lead Edit" subtitle="{!Lead.Company}"/>  
    <apex:form >
        <apex:pageBlock title="Lead Edit" id="Edit_Fiscal_Information" mode="Edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Close" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:PageBlockButtons>
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Lead Status"/>
                        <apex:inputField value="{!lead.Status}"/>
                    </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Lead Status Result"/>
                        <apex:inputField value="{!lead.Lead_Status_Result__c}"/>
                 </apex:pageBlockSectionItem>
            </apex:pageblockSection>
       </apex:pageBlock>
     </apex:form>
</apex:page>

 

I want to prepopulate the field status with the value of the picklist 'Lead Closed' using the URL, but I am not able to do so.

 

Can anyone show me how to get it?

 

Thanks a lot!

 

Antonio

Hi all,

 

I have a problem making a call out to another system receiving the following error during debug:

 

common.apex.runtime.impl.ExecutionException: Received fatal alert: bad_record_mac"|0x56b08894

 

In my code I create an http request using the following endpoint:

 

req.setEndpoint('https://mdm.tuitravel-ad.com/mdmclients/secure/');

 

When I send the same request to the same endpoint using a Firefox SOA Cliente the request is accepeted.

We have already try this code before to a http endpoint but now, working in production, we need to make the request to an https endpoint and is when the issue appeared.

 

Could somebody help please?

 

If any other information is needed please let me know.

 

Regards,

 

Antonio

Hi,

 

I the following code:

 

global class AccountSynchBatch implements Database.Batchable<sObject>,Database.AllowsCallouts{
    
    global Integer result=0;
    global Integer Mains=0;
    global Integer branches=0;
    global Integer errores=0;
    global AccountSynchBatch()
	{
    }

    global Database.QueryLocator start(Database.BatchableContext BC)
	{
        return DataBase.getQueryLocator([SELECT Id,Account_to_be_Synch__c,Atlas_Branch_Number__c FROM account WHERE Account_to_be_synch__c=True]);
	}
	
    global void execute(Database.BatchableContext BC,List<sObject> scopeAcc)
	{	
        for (Integer i=0;i<scopeAcc.size();i++){ 
            if (scopeAcc.get(i).get('Atlas_Branch_Number__c')==-1){
            	result=myCallOuts.SyncMainAccount(scopeAcc.get(i).Id);
            	Mains=mains+1;
            }else{
                result=myCallOuts.SyncBranchAccount(scopeAcc.get(i).Id);
                branches=branches+1;
            }
            if (result==1){
                scopeAcc.get(i).put('Account_to_be_synch__c',False);
            }else{
            	errores++;
            }
    	}
        update scopeAcc;
        system.debug('Mains:'+Mains);
        system.debug('Branches:'+Branches);
        system.debug('Errores:'+errores);
	}
    
    global void finish(Database.BatchableContext BC)
	{
    	//Send an email to the User after your batch completes
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		String[] toAddresses = new String[] {'a.tejado@hotelbeds.com'};
		mail.setToAddresses(toAddresses);
		mail.setSubject('Apex Batch Synch Job is done');
		mail.setPlainTextBody('The batch Apex Synch job processed with the result: Main Accounts Synch: '+Mains+', Branches Accounts Synch: '+Branches+', Errores: '+errores);
		Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
	}

}

 

When I try to acces to the three variables Mains, Branches and Errores in the finish method, even though Im sure I introduce a value in them in the execute method, I always get a 0 in the mail.

 

How do I have to declare the variables to be able of accessing them from any method?

 

Thanks,

 

Antonio

Hi,

 

I need to create a trigger but I have problems to create it in a "bulk" way. This is the requirement:

 

I have accounts which are related to another one (called the main). I can have up to 15 accounts related to this main one.

 

When some field of the main account, as the account name or address, are modified, I need to replicate this change to the accounts that are related to this main one. This change doesnt have to be replicated always, just when the related accounts fulfills a condition based on its accountrecordtype

 

I can do

 

For [a: in trigger.new]{

Account RelatedAccount=[SELECT id, recordtypeId FROM Account Where RelatedAccountId:=a.Id];

 

}

 

But this wouldnt be the bulk way and I would probably get errors.

 


Any help is appreciated.

Thanks,

Antonio

Hi,

 

I have a requirement. Everytime an account is modified, I need to send this modification to my company system.

 

To do this we use http call outs. The problem is that I cant make the call to the class that makes the call out from the trigger because the class will be marked with the @future method and I will make more than 200 call every 24hours per day.

 

How can I manage this in other way? Can I make a call out from a trigger without using the @future annotation using any toher Salesforce utility (like apex batches...)?

 

Thanks a lot

 

Antonio

Hi,

 

I have a problem trying to create my first apex batch.

 

I have got a trigger, that checks if an account has been modified. If so, I add the id of the account to a list and at pass the list of ids to the apex batch.

 

The apex batch must call to a function in a class that will make a call out.

 

This is my trigger:

 

trigger ModAccountInvokeService on Account (after update) {
    List <Id> MainAccounts=new List <Id>();
    List <Id> BranchAccounts=new List <Id>();
    for (Integer i=0;i<Trigger.new.size();i++){
        Account acc=Trigger.new[i];
        if (acc.RecordTypeId=='012D000000035RH' || acc.RecordTypeId=='012D000000035Bw'){
            if (Trigger.new[i].Province_Commercial_2__c!=Trigger.old[i].Province_Commercial_2__c){
                //
                //myCallOuts.SyncMainAccount(acc.Id);
                //Introduce the Id of the account to the list
                MainAccounts.add(Trigger.new[i].Id);
            }
        
    }
    //Llamo a los batches que irán haciendo el call out
     Database.executeBatch(new MainAccountSynchBratch(MainAccounts),1);
}

 And this is my Batch Code:

 

global class MainAccountSynchBatch implements Database.Batchable<Id>,Database.AllowsCallouts{
    
    //Recibo el listado de las cuentas main que hay que sincronizar
    
	List<Id> MainAccounts = new List<Id>();
    global MainAccountSynchBatch(List<Id> listMainAccounts)
	{
        MainAccounts = listMainAccounts;
    }

    global List<Id> start(Database.BatchableContext BC)
	{
		//return DataBase.getQueryLocator([SELECT Id FROM account WHERE Id IN : MainAccounts]);
        return Database.Batchable();//(MainAcounts);
	}
	
    global void execute(Database.BatchableContext BC,List<Account> scopeAcc)
	{
		
        for (Integer i=0;i<scopeAcc.size();i++){
            //scopeAcc.get(i).Commercial_Area__c=ownerMap.get(scopeAcc.get(i).OwnerId).Commercial_Area__c;
            myCallOuts.SynchMainAccount(scopeAcc.get(i));
    	}
    	//update scopeAcc;
	}
    
    global void finish(Database.BatchableContext BC)
	{
    	//Send an email to the User after your batch completes
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		String[] toAddresses = new String[] {'a.tejado@hotelbeds.com'};
		mail.setToAddresses(toAddresses);
		mail.setSubject('Apex Batch Synch Job is done');
		mail.setPlainTextBody('The batch Apex Synch job processed ');
		Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
	}

}

 How can I pass to the Execute method the list of Ids that I receive in the batch?

 

Really appreciate your help.

 

Thanks,

 

Antonio