• Gabriel McGinn
  • NEWBIE
  • 5 Points
  • Member since 2017


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 1
    Questions
  • 5
    Replies
Most of the resources I've found online reference specifically creating records not updating existing records only. 
Any assistance would be appreciated.

The following Apex class is staged in my sandbox. It is used in conjunction with a visualforce page and is launched via a button on the Incident object.

Here is the class:
public class IncidentTask
{
    public ApexPages.StandardController std;
 
    // The associated tasks to the Parent Incident
    public List<BMCServiceDesk__Task__c> tasks {get; set;}
    
    public PageReference save()
    {

     // first save the incident
        std.save();
       
     // then save the procurement tasks
        update tasks;

     // set current page as reference to be returned to after save commits
        PageReference result=ApexPages.currentPage();
         result.setRedirect(true);       
        
        // navigates to page set above with updated values
        return result;
    }

    //
    public String[] records {get;set;}
    
    public IncidentTask(ApexPages.StandardController stdCtrl)
    {
     std=stdCtrl;
     // queries related fields for the task object so they can be referenced in the visualforce page.
     tasks=[select id, Name, Subject__c, Model__c, CMDB_Model__c, BMCServiceDesk__FKIncident__c, BMCServiceDesk__FKStatus__c, Tracking_Number__c, Asset_Tag__c, Serial_Number__c, Cost__c, Vendor_Name__c from BMCServiceDesk__Task__c where BMCServiceDesk__FKIncident__c=:std.getId() order by Name asc limit 400];

    // dynamically create set of unique Line Items from query
    Set<String> taskSet = new Set<String>();
        for (BMCServiceDesk__Task__c t : tasks)
        taskSet.add(t.Subject__c);

    // convert the set into a string array  
    records = new String[taskSet.size()];
    Integer i = 0;
        for (String record : taskSet) { 
        records[i] = record;
        i++;
        }
    }

}
We got the following error:
Single Sign-On Error
We can't log you in. Check for an invalid assertion in the SAML Assertion Validator (available in Single Sign-On Settings) or check the login history for failed logins.

We tried recreate another account, but once use this "xxxxx@xxxxxxx.com" in federation ID , we got the Single Sign-On Error
We can't log you in. Check for an invalid assertion in the SAML Assertion Validator (available in Single Sign-On Settings) or check the login history for failed logins.

Any one expericence the same ?
Hi, I'm trying to complete the challenge for Customize How Records Get Approved with Approvals and when I click the button to verify the challenge I get this message: Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process was found.: []

Can someone please show me where I went wrong? Thanks!
We have an apex class that in conjunction with a visualforce page is used to send emails to customers from within Salesforce and then store that information as a record.

We need to change one of the fields that pulls through into the email that is sent to the customer. Through Testing I have established the parts of the code that would need changing if the new field was on the same object as the old field. However it's not. It's on a seperate object called BMCServiceDesk__IncidentHistory__c. I'm guessing a new SOQL query would need to be written to query this object and to get the   BMCServiceDesk__note__c field. Below is an extract of the  code, highlighted in bold is what I need removed. I'm guessing the new SOQL query would sit underneath the first query that queries the incident object? Some help on this would be greatly appreciated as I'm very new to this!

public with sharing class COL_JIS_EmailConversationController {
 
        BMCServiceDesk__Incident__c incident = null;
    //List<BMCServiceDesk__CustomAttachment__c> incidentAttachments = null;
    //Map<String,String> incidentAttachments = null;
    
     transient String bodyText = null;
     transient String lastEmailBody = null;
     String subject = null;
    //Attachment attachment = null;
    //String attID = null;
    String toAddresses = '';
    String ccAddresses = '';
    
        public COL_JIS_EmailConversationController(){
      incident =  [select id, name, COL_JIS_Caller_Email__c, COL_JIS_Caller_Name__c, COL_JIS_Subject__c,
                        BMCServiceDesk__openDateTime__c,BMCServiceDesk__IncidentDescription__c,
                        COL_JIS_Service_Desk_Signature__c,COL_JIS_Incident_History_last_entry__c,
                        COL_JIS_Category_Type__c
                               from BMCServiceDesk__Incident__c
                where id = :ApexPages.currentPage().getParameters().get('id') limit 1];
                
            List<BMCServiceDesk__IncidentHistory__c> inboundEmails = [select Id, BMCServiceDesk__note__c, BMCServiceDesk__EmailConversationData__c,
                                                                                    COL_JIS_CCEmailAddresses__c
                                                                                    from BMCServiceDesk__IncidentHistory__c 
                                                                                    where BMCServiceDesk__actionId__c = 'Email Received'
                                                                                    and BMCServiceDesk__FKIncident__c = :ApexPages.currentPage().getParameters().get('id')
                                                                                    order by Name DESC Limit 1]; 
            
            if(inboundEmails != null && inboundEmails.size() > 0){
                lastEmailBody = inboundEmails[0].BMCServiceDesk__note__c;
                if(inboundEmails[0].BMCServiceDesk__EmailConversationData__c != null){toAddresses = inboundEmails[0].BMCServiceDesk__EmailConversationData__c;}
                if(inboundEmails[0].COL_JIS_CCEmailAddresses__c != null){ccAddresses = inboundEmails[0].COL_JIS_CCEmailAddresses__c;}
            }
        if(incident != null){
            toAddresses += incident.COL_JIS_Caller_Email__c;
            subject = incident.COL_JIS_Subject__c;   
        }
        
    }
    
    public PageReference sendEmail() {
        system.debug('enter sendEmail');
        
        // attach files
        attachFile();
        // create a mail incident history record 
        
        BMCServiceDesk__Action__c action = null;
        List<BMCServiceDesk__Action__c> actions = [select Id from BMCServiceDesk__Action__c where BMCServiceDesk__Abbreviation__c = 'EMAILOUT' Limit 1];
        if(actions != null && actions.size()>0){
            system.debug('action found');
          action = actions[0];
        }
        
        String emailBody = bodyText;
        
        
        
        
        system.debug('************************* To: ' + toAddresses);
        COL_JIS_SingleEmailMessage mail = new COL_JIS_SingleEmailMessage();
        
        // get the org address to send the email from
        if(incident.COL_JIS_Category_Type__c != ''){
            List<OrgWideEmailAddress> orgWideAddresses = [SELECT Id, Address FROM OrgWideEmailAddress WHERE DisplayName = :incident.COL_JIS_Category_Type__c limit 1 ];
            if(orgWideAddresses != null && orgWideAddresses.size() > 0){
                mail.setReplyTo(orgWideAddresses[0].Address);
                mail.setOrgWideEmailAddressId(orgWideAddresses[0].Id);
            }
            
        }
        
        // set the from address as the default no reply
        /*List<OrgWideEmailAddress> replyTo = [SELECT Id, Address FROM OrgWideEmailAddress WHERE DisplayName = 'Jisc Remedyforce' limit 1 ];
            if(replyTo != null && replyTo.size() > 0){
                mail.setOrgWideEmailAddressId(replyTo[0].Id);
                
            }*/
        
        mail.setToAddress(toAddresses);
        mail.setSubject(subject + '(Ref:IN:' + incident.Name + ')');
        if(ccAddresses != null && ccAddresses != ''){
            mail.setCcAddresses(ccAddresses);
        }
        mail.setPlainTextBody(buildPlaintextBody());
        mail.setHtmlBody(buildHTMLBody());
        mail.setSaveAsActivity(false);
        Messaging.EmailFileAttachment[] attachArray = new Messaging.EmailFileAttachment[]{};
        String attachmentText = '';
        Integer noOfAttachments = selectedFoos.size();
        
        if(selectedFoos.size() > 0){
            //noOfAttachments ++;
            attachmentText = 'Attachments sent with this email(' + noOfAttachments + ')';
        }
        
        //List<Attachment> attachmentsToInsert = new List<Attachment>();
        Integer i = 1;
        for(Attachment a : selectedFoos){
            
            attachmentText += '\n' + i + '. ' + a.Name;
            i++;
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            Attachment at = [select body from Attachment where Id = :a.Id limit 1];
            attach.setFileName(a.Name);
            attach.setBody(at.body);
            //a.parentId = incident.Id;
            attachArray.add(attach);
            
            //if(a.Id == null){
                //attachmentsToInsert.add(a);
            //}
        }
        //insert attachmentsToInsert;
        
        if(attachmentText != ''){
            attachmentText += '\n***********************';
        }
        mail.setFileAttachments(attachArray);
        
        if(incident != null && action != null){
            system.debug('incident and action exist');
            Integer actionCount = [select count() from BMCServiceDesk__IncidentHistory__c where BMCServiceDesk__FKIncident__c = :incident.Id];
            actionCount++;
            String actionName = incident.Name + '_' + string.valueOf(actionCount);
            // add a note to the incident
            
            emailBody = bodyText + '\n\n' + attachmentText ;
            
            BMCServiceDesk__IncidentHistory__c note = new BMCServiceDesk__IncidentHistory__c(BMCServiceDesk__FKIncident__c = incident.Id,
                                                        BMCServiceDesk__note__c = emailBody,
                                                        BMCServiceDesk__description__c = 'Email sent to ' + toAddresses,
                                                        BMCServiceDesk__FKAction__c = action.Id,
                                                        Name =  actionName,COL_JIS_Caller_Email__c = incident.COL_JIS_Caller_Email__c );
            if(note != null){
                system.debug('insert the note');
                insert note;
            }
        }
            
    try{
        mail.send();
    }catch(Exception e){
        ApexPages.addMessages(e);
        return null;
    }
        
    //return null; // stay on the same page 
    return new PageReference('javascript:window.close()');
}
    
    String[] getAddressArray(String addresses){
        if(addresses == null){addresses = '';}
        String[] addressList = addresses.split(';',0);
        return addressList;
        
    }
    
    public BMCServiceDesk__Incident__c getIncident() {
      
        return incident;
    }
    
    public String getToAddresses() {
        if(toAddresses == null){
            toAddresses = getIncident().COL_JIS_Caller_Email__c;
        }
        return toAddresses;
    }
    
    public void setToAddresses(String s){
        toAddresses = s;
    }
    
    public String getCcAddresses() {
        
        return ccAddresses;
    }
    
    public void setCcAddresses(String s){
        ccAddresses = s;
    }
    
    public String getAdditionalText() {
        return bodyText;
    }

    public void setAdditionalText(String s) {
        bodyText = s;
    }
    
    public String getLastEmailText() {
        
            
        return lastEmailBody;
    }

    public void setLastEmailText(String s) {
        lastEmailBody = s;
    }
    
    public String getSubject() {
        
            
        return subject;
    }

    public void setSubject(String s) {
        subject = s;
    }
    
     public String getAttachFiles() {
        
        String attachmentList = '';
        
        for(Attachment a : attachments){
            attachmentList += a.name + '\n';
        }   
        return attachmentList;
    }

    
    
    // =====================================================================================
    // Private helper methods
    // =====================================================================================
    
    private String buildHTMLBody(){
        // we cannot use templates as this would require a contact or user and would 
        // result in a double count of the email limit.
        
    
        String body = bodyText;
        body = body.replaceAll('\n','<br>');
        body += '<p>Enquiry Number: '  + incident.Name;
        body += '<br>Subject: ';
        if(incident.COL_JIS_Subject__c != null){body += incident.COL_JIS_Subject__c;}
        body += '<br>Open Date: ';
        if(incident.BMCServiceDesk__openDateTime__c != null){body += incident.BMCServiceDesk__openDateTime__c;}
        body += '<br>Caller Name: ';
        if(incident.COL_JIS_Caller_Name__c != null){body += incident.COL_JIS_Caller_Name__c;}
        body += '<br>Enquiry: <p>';
        if(incident.BMCServiceDesk__incidentDescription__c != null){body += incident.BMCServiceDesk__incidentDescription__c.replaceAll('\n', '<br>');}
        body += '<p>Please reply to this email with any updates on this issue.<p>';
        if(incident.COL_JIS_Service_Desk_Signature__c != null){body += incident.COL_JIS_Service_Desk_Signature__c;}
        body += '<p><hr/><p>';
        if(lastEmailBody != null){body += lastEmailBody.replaceAll('\n', '<br>');}
        
        return body;
        
    }
    
    private String buildPlaintextBody(){
        // we cannot use templates as this would require a contact or user and would 
        // result in a double count of the email limit.
        
        String body = bodyText;
        body += '\n\nEnquiry Number: '  + incident.Name;
        body += '\nSubject: ';
        if(incident.COL_JIS_Subject__c != null){body += incident.COL_JIS_Subject__c;}
        body += '\nOpen Date: ';
        if(incident.BMCServiceDesk__openDateTime__c != null){body += incident.BMCServiceDesk__openDateTime__c;}
        body += '\nCaller Name: ';
        if(incident.COL_JIS_Caller_Name__c != null){body += incident.COL_JIS_Caller_Name__c;}
        body += '\nEnquiry: \n';
        if(incident.BMCServiceDesk__incidentDescription__c != null){body += incident.BMCServiceDesk__incidentDescription__c;}
        body += '\nPlease reply to this email with any updates on this issue.\n\n';
        if(incident.COL_JIS_Service_Desk_Signature__c != null){body += incident.COL_JIS_Service_Desk_Signature__c;}
        body += '\n----------------------------------------------------------------\n\n';
        if(lastEmailBody != null){body += lastEmailBody;}

        return body;
        
    }
    
Hi Team,

Could you advise how to include the case email thread into email alert?

When there is a new email received by a case, SF has a standard function to send out a notificaiton to case owners, and in that notification it includes the customer's new email. We just need the same notification to be sent to another case related user besides the case owner, and we've set up a workflow rule to trigger an email alert. Howver, the merge field {!Case.Email_Thread} don't work in the email template and as confirmed with SF support this is not possible through standard configuration as today.

Would be appreciated if anyone can help with this by coding, thanks in advance.

Hi,

 

I have a visualforce email template which is related to a custom object. In the template I have the following line where Agenda_Objective__c is a long text area.

 

 

<apex:outputText value="{!relatedTo.Agenda_Objective__c}"/>

 

 If there are any line breaks in the field in the custom object, they do not come through in the email template.

E.G. if the field contains the text:

 

Test1

Test2

Test3

 

the mail will display

 

Test1 Test2 Test3

 

Is there any way of preserving the line breaks? I could use outputfield instead of outputtext but this puts extra javascript into the mail which causes an error in my email client.

 

  • December 14, 2009
  • Like
  • 0
I want to check if i am thinking in right direction and if not would like some guidance on approach. My use case is as follows: A user will upload an excel/csv file using a force.com unauthenticated sites. However, we would like to ensure that right user is uploading by doing a pseudo user validation like entering a pin which upon validation allows user to file upload screen to upload the csv file. This will then need to parse the file and upsert after performing few file checks. can we use flows to capture the user pin and validation and there by invoke a visualforce page from flow for file upload and insert?
Thanks !
User-added image

Hi guys  I need to remove customer portal user from standard user look field and only show User and Partner user.Can you please suggest some solution to achieve it.

Hello All,

Just want to share my experience in creating Visualforce Email template where you want to display date and time in User timezone

 

***Overview
You are in MST time zone.
Let's say we have Date/Time field TaskDateTime__c and use it in Visualforce email template to show recipient the time in email.

<apex:outputText value="{0,date,EEEE, MMMM d, yyyy, HH:mm:ss}"><apex:param value="{!RelatedTo.TaskDateTime__c}" /></apex:outputText>

 

In email time will be converted and showed to GMT instead of EST.

 

The outputField (which convert time to user locale automatically) does not
work in Visualforce Email templates (not supported).

 

So how do I tell to display in Visualforce Email template time in User
timezone? For example MST?

 

***Implementation Details (worarounds)***

 

I found two workarounds:

 

Workaround 1: Use Controller class for the Component to use in template

In order to format the date in various TimeZone in Email Template, we can follow the steps:

1. First create a Controller class for the Component

Setup|App Setup|Develop|Apex Classes|New

Formatted_DateTime_Controller Class Code
----------------------------------------------------------

public class controller_formatted_datetime
{
public DateTime date_time { get; set; } //property that reads the datetime value from component attribute tag
public String defined_format { get; set;} //property that reads the string value from component attribute tag
public String getFormattedDatetime()
{
if (date_time == null) {return ''; }
else { if (defined_format == null) {
return date_time.format(); //return the full date/time in user's locale and time zone
}
else { return date_time.format(defined_format,'MST'); //Specify Time zone like IST,CST
}}}}

 

2. Create a Component

Setup|App Setup|Develop|Components

VF Component Code (Name: VFEmailTempComp)

<apex:component access="global" controller="controller_formatted_datetime">{!FormattedDatetime}
<apex:attribute assignTo="{!date_time}" description="The DateTime value to be rendered" name="date_time_value" type="DateTime"></apex:attribute>
<apex:attribute assignTo="{!defined_format}" description="The optional format to use for the DateTime value to be rendered" name="date_time_format" type="String"></apex:attribute>
</apex:component>

 

 

3. Create an Email Template and embed the component.

Setup|Administration Setup|Communication Templates|Email Templates

Email Template Code
---------------------------------

<messaging:emailTemplate subject="Testing DateTime Format" recipientType="Contact" >
<messaging:plainTextEmailBody >
Formatted: <c:VFEmailTempComp date_time_value="{!NOW()}" date_time_format="EEE MMM d kk:mm:ss z yyyy" />
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

 

It will display current time in MST timezone.


Workaround 2: Calculate difference in the apex:param value (for MST (-7) it will be 7/24=0.291666666

Date: <apex:outputText value="{0,date,EEEE, MMMM d, yyyy}"><apex:param value="{!RelatedTo.Scheduled_Clock_In__c - 0.291666666}" /></apex:outputText>
Time: <apex:outputText value="{0,date,h:ma}"><apex:param value="{!RelatedTo.Scheduled_Clock_In__c - 0.291666666}" /></apex:outputText> MST

  

  • August 28, 2012
  • Like
  • 4