• Peter Martensen 8
  • NEWBIE
  • 95 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 43
    Questions
  • 40
    Replies
I need to do a query on a long text area field that contains special characters, "-" "(" ")".  I found an escape map that seems to have come from the Salesforce Developer site, but it won't save.  Can someone help me figure out how to fix it?  I changed all of the double quotes to single quotes and that didn't work.
Thanks

https://salesforce.stackexchange.com/questions/254017/sosl-query-with-special-characters
public class StringUtils {

    /**
     * Reserved characters which need to be escaped in SOSL
     * https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm
     */
    public static final CharSequenceTranslator ESCAPE_SOSL;

    static {
        final Map<CharSequence, CharSequence> escapeSoslMap = new HashMap<>();
        escapeSoslMap.put("?", "\\?");
        escapeSoslMap.put("&", "\\&");
        escapeSoslMap.put("|", "\\|");
        escapeSoslMap.put("!", "\\!");
        escapeSoslMap.put("{", "\\{");
        escapeSoslMap.put("}", "\\}");
        escapeSoslMap.put("[", "\\[");
        escapeSoslMap.put("]", "\\]");
        escapeSoslMap.put("(", "\\(");
        escapeSoslMap.put(")", "\\)");
        escapeSoslMap.put("^", "\\^");
        escapeSoslMap.put("~", "\\~");
        escapeSoslMap.put("*", "\\*");
        escapeSoslMap.put(":", "\\:");
        escapeSoslMap.put("\\", "\\\\");
        escapeSoslMap.put("\"", "\\\"");
        escapeSoslMap.put("'", "\\'");
        escapeSoslMap.put("+", "\\+");
        escapeSoslMap.put("-", "\\-");
        ESCAPE_SOSL = new AggregateTranslator(new LookupTranslator(Collections.unmodifiableMap(escapeSoslMap)));
    }

    /**
     * Escape SOSL reserved characters
     * https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm
     */
    public static final String escapeSosl(final String input) {
        return ESCAPE_SOSL.translate(input);
    }
}

 
I managed to modify some existing Apex, which should have been the hard part, but I can't get it to fail properly if the result = Null.  The Apex is used in a Flow and it performs a sosl query on a long text are field.  Then it updates the Opportunity.  Can someone help me terminate the Apex if the result = Null?
 
global class SearchDrugNameSynonyms {
   @InvocableMethod
   public static void getID(List<String> recordID) {
   Opportunity ThisOpportunity=[select Compound_Name__c from Opportunity where ID=:recordId[0] limit 1];
   
   String fieldValue = ThisOpportunity.Compound_Name__c;
String fieldName = 'Drug_Name_Synonyms__c';
String query = 'FIND {"'+ fieldValue + '"}  RETURNING ' +
                  ' Drug_Name__c (id, ' + fieldName + ' ) LIMIT 1';
 List<List<sObject>> result = System.Search.query(query);
system.debug('Search result: ' + result[0]);//Get search result

List<Drug_Name__c> ThisDrugName=new list<Drug_Name__c>();
    if(!result.isEmpty()){
    ThisDrugName=result[0];
       ThisOpportunity.Compound_Name2__c = ThisDrugName[0].id;
   Update ThisOpportunity;
    }
    else {}
     
   }
}

 
Hi everyone,
I need an Opportunity VF page that just shows the value of this field on the related Account:  CheckTermsAndConditionsText__c.
I want to use this VF page on the Opportunity Lightning App Builder page as a conditional component.
Would someone be willing to make that for me?
Thanks!
Peter
I have an aura component that I want to start from a list button.  Is there a way to get the URL for the aura component so I can create a url addressable List button to launch it?
Hi everyone,
I am using an api call to insert records in my org.  One of the fields returns a list on different lines.  I want to turn that into a multi-select picklist.  Is there a way to use the end of line character to determine where to add a semi-colon?  I want to do this in a Flow, not Apex.
Thanks
Hi everyone,
I've purchased the Event Monitoring subscription.  I would like to get a notification in near real time whenever some runs and/or exports a report.  I've found many articles in the Developer section about Streaming API, but it's really confusing to me.  Does anyone know if there is a (relatively) simple way to just get a chatter notification if a report is run or exported?  I can't find the Event subscription channel, /event/ReportEventStream, in Flow.  I have enabled Real Time Event Monitoring in my Profile.
Thanks
We use CPQ.  When adding a Product to an Opportunity, only a few fields copy to the OpportunityLineItem record while it is still being edited (Product Name, Sales Price).  CPQ states that I can't add a custom field to the OpportunityLineItem and populate it with a value before saving.  It's easy after saving, but I want the user to see the value before they save it.  The value is going to come from the Product that the new OpportunityLineItem record is being created from.
Thanks
I want to copy the Opportunity Score to a custom field that I can track with Field History Tracking.  Can someone tell me how to lauch a Flow or Process Builder when the Opportunity Score changes?  It doesn't work to simply use Opportunity Score ISCHANGED, I think because it is a system field.
I'm not a developer, so I don't really know what I'm doing, and this code is ugly.  When I run the Test Class, it says that I'm trying to de-reference a null object.  Can someone tell me what object hasn't been referenced?  The fatal error is at line 84 (I think).  This is from the failed Test: 
 Class.attachEmailToMIReports.handleInboundEmail: line 8, column 1
Class.attachEmailToMIReports_Test.testAttachEmail: line 84, column 1
Thanks!
@isTest(seeAllData=false)
public class attachEmailToMIReports_Test {
    //class level variables
    Static Account thisAccount;
    Static Contact thisContact;
    Static Opportunity thisOpportunity;
    Static Market_Intelligence_Reports__c thisMIReports;
    Static Messaging.InboundEmail email;
    Static Messaging.InboundEnvelope env;
    Static Messaging.InboundEmailResult result;
    
           
    //method to set all of the object values needed for testing.
    //This would be where you would call a test factory
    //to set values for the objects need for the test
    //for instance "thisContact = testFactory.InsertAccount();"
    //testFactory being a different test class that has
    //a function InsertAccount() that inserts an account object and returns it.
    static void init() {
        // Create a new email and envelope object.      
		//Email and envelope objects 
		Messaging.InboundEmail email = new Messaging.InboundEmail() ; 
		Messaging.InboundEnvelope env = new Messaging.InboundEnvelope(); 

       
        // Create Test record.
        thisAccount = new Account(Name = 'Test');
        insert thisAccount;
        system.debug('Account Id '+thisAccount.Id);
        thisContact = new Contact(firstName='john',
                                  lastName='smith',
                                  Email='test@test.com',
                                  AccountId = thisAccount.Id);
        insert thisContact ;
        system.debug('Contact Id '+thisContact.Id);
        thisOpportunity = new Opportunity(Name = 'TestOpp',
                                         AccountId = thisAccount.Id,
                                         ContactId = thisContact.Id,
                                         StageName = 'Qualification',
                                         CloseDate = (System.today()+5),
        								 Line_Of_Service__c = 'Agawam - Analytical',
        								 CurrencyIsoCode = 'USD',
                                         Compound_Name__c = 'TestOpp',
                                         New_Compound_For_Cambrex__c = 'Yes',
                                         Opportunity_Date__c = System.today(),
                                         LeadSource = 'Webinar',
                                         Proposal_Due_Date__c = System.today(),
                                         Description = 'TestOpp',
                                         Development_Phase__c = 'Discovery');								 
        insert thisOpportunity;
        system.debug('Opportunity Id '+thisOpportunity.Id);
        thisMIReports = new Market_Intelligence_Reports__c(Name = 'Market Intelligence Report for '+Opportunity.Name,
                                                           Account__c = thisAccount.Id,
            											   Opportunity__c = thisOpportunity.Id);
        insert thisMIReports;
        system.debug('MI Reports '+thisMIReports.Id);
        // Test email settings.
			//Simulate data for the email 
			EmailMessage	newEmail = new EmailMessage(
			Subject = 'My Subject', 
			FromAddress = 'emailaddress@address.com', 
			TextBody = 'My email body'); 

            insert newEmail;
            System.debug('Created Email '+newEmail.Id);
        
			//Simulate binary attachment 
			Messaging.InboundEmail.BinaryAttachment attachment = new 
			Messaging.InboundEmail.BinaryAttachment(); 
			attachment.body = blob.valueOf('my attachment text'); 
			attachment.fileName = 'file.txt'; 
			attachment.mimeTypeSubType = 'text/plain'; 
			email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment }; 
        
    }    
    //this is the method that test the email handler
    static testMethod void testAttachEmail()
    {
        //sets up the variables to be tested
	init();
        Test.startTest();
            attachEmailToMIReports testInbound = new attachEmailToMIReports();
        	testInbound.handleInboundEmail(email, env);
            //result is the return value of the function
            //result = testInbound.handleInboundEmail(email, env );
            //check to see that the result is not null
            System.assert(result != null);
        	//System.assertNotEquals(null,b);
        Test.stopTest();                    
    }
}

 
I'm using the included Apex Class to capture inbound emails using an Email Service.  When I send an email from a record, that email is immediately duplicated as a Task also.  How do I prevent that from happening?  When I send an email without using the Email Service email address in the CC field, this doesn't happen.
Thanks!
User-added image
global with sharing class attachEmail implements Messaging.InboundEmailHandler {
    //handler overwrite
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                        Messaging.InboundEnvelope env) {
    //local variables
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    String myPlainText= '';
    myPlainText = email.plainTextBody;
    Integer i = myPlainText.indexOf('ref:',0);                                                   
    String objectId = myPlainText.substring(i+5, i+20);
Task[] newTask = new Task[0];       
                                                            
    //try to do something here
    try {
      newTask.add(new Task(Description =  myPlainText,
           TaskSubtype = 'Email',
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1,
           WhatId = objectId));
      insert newTask;       
    }
    catch (Exception e) {
        System.debug('Email failed ' + e);
    }
    result.success = true;

    return result;
    }
}

 
I have a custom Object (Market_Intelligence_Reports__c) that has a lookup field to Opportunities.  I would like to use data from the Opportunity in a HTML email template.  I can't use a VF template because I need to use the template in an Activity Email from the Market Intelligence Reports record.  Is there a way to use the Opportunity data in the template?  I've tried things like
{!Market_Intelligence_Reports__c.Opportunity__r.Account.Name}, {!Opportunity__r.Account.Name}, {!Market_Intelligence_Reports__c.Opportunity__r.Account}
Thanks
I am trying to make a very simple VF page that shows some text and a "Back" button.  I can't figure out the "Back" button.  Can someone help fix this code?  Thanks!
<apex:page standardController="Opportunity">

  
  <h1>You need to create an Opportunity directly from a Contact.</h1>

<apex:form>
<apex:commandButton value="Cancel" oncomplete="doRedirect();"/>                

            <script type="text/javascript">
                function doRedirect(){
                    window.history.back();
                }

            </script>
</apexform>
</apex:page>
I had a developer re-write an Apex Class.  Now I need to disable a trigger that I already had in Production that runs another Apex Class.  Can someone tell me how to change this trigger so that I can deploy it but it won't do anything?
Thanks!
/****************************************************************************
* Name        - OpportunityTriggerLargeAwards
* Description - Opportunity Trigger for Large Awards
                   
* Modification Log :
* ---------------------------------------------------------------------------
* Developer             Date            Description
* ---------------------------------------------------------------------------
* jmasters             11-08-2016      Created 
****************************************************************************/
trigger OpportunityTriggerLargeAwards on Opportunity (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
   OpportunityTriggerHandlerLargeAwards handler = new OpportunityTriggerHandlerLargeAwards(true);

    /* Before Insert */
    if(Trigger.isInsert && Trigger.isBefore){
        handler.OnBeforeInsert(Trigger.new); 
    }
    /* After Insert */
    else if(Trigger.isInsert && Trigger.isAfter){
        handler.OnAfterInsert(Trigger.new, Trigger.newMap);
    }
    /* Before Update */
    else if(Trigger.isUpdate && Trigger.isBefore){
        handler.OnBeforeUpdate(Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap);
    }
    /* After Update */
    else if(Trigger.isUpdate && Trigger.isAfter){
        handler.OnAfterUpdate(Trigger.old, Trigger.new, Trigger.newMap, Trigger.oldMap);
    } 
    /* Before Delete */
    else if(Trigger.isDelete && Trigger.isBefore){
        handler.OnBeforeDelete(Trigger.old, Trigger.oldMap);
    }
    /* After Delete */
    else if(Trigger.isDelete && Trigger.isAfter){
        handler.OnAfterDelete(Trigger.old, Trigger.oldMap);
    }
    /* After Undelete */
    else if(Trigger.isUnDelete){
        handler.OnUndelete(Trigger.new); 
    }
  

}

 
if( ('Closed Won' == o.StageName) && ('Closed Won' != opportunityOldMap.get(o.Id).StageName) && (!o.Line_of_Service__c.contains('Agawam')))
Can someone help me break this IF statement into a nested IF statement so I can add system.debug between the conditions?  Thanks
 
I have an Apex Class and Apex Test Class that were written by a devloper.  I am not a developer.  I'm having trouble validating a change to the Apex Class in production but not in the sandbox.  Is there a non-developer guide to how Apex Test Classes work?  I thought the test class created a dummy record to run the Apex Class against.  I commented out the lines in the Test Class that deleted the dummy record, but I can't find it after running the test.  Am I misunderstanding how the Test Class works?
Thanks
We're using Jifflenow to schedule sales meetings.  They don't have a button on Contacts to scchedule meetings, but they have a button on Leads, Accounts, and Opportunities.  The button on Opportunities saves the Opportunity ID and Account ID, so I think I can modify this to save the Contact ID and Account ID.  But I'm getting an error that a field doesn't exist.  Can someone tell me if I'm making a simple mistake?
This is the Opportunity button URL:
/apex/jiffle__JNEvents?oppid={!CASESAFEID( Opportunity.Id )}&accid={!CASESAFEID( Opportunity.AccountId )}
This is how I changed it for the Contact:
/apex/jiffle__JNEvents?conid={!CASESAFEID( Contact.Id )}&accid={!CASESAFEID( Contact.AccountId )}
I'm getting this error:  "Error: Field Contact.AccountId does not exist. Check spelling."  I looked in "Insert Field" and AccountID is not listed.  I made a custom Contact formula field that copies the AccountID into AccountID__c and changed the URL to:
/apex/jiffle__JNEvents?conid={!CASESAFEID( Contact.Id )}&accid={!CASESAFEID( Contact.AccountID__c )}
I don't get an error, but the button doesn't work the way I want and save the Contact to the meeting.  Is that because the ability wasn't coded into the software by Jifflenow?
Any help is appreciated!

This is the JNEvents Visualforce page:
<apex:page Controller="jiffle.JNEventMeetingList" action="{!chkconfigsettings}" standardStylesheets="false" showHeader="true" sidebar="false" tabStyle="Jifflenow_Meetings__tab">
<link rel="stylesheet" href="{!URLFOR($Resource.JNResources, 'JNResources/application.css')}"/>
<html lang="en">
<apex:include pageName="jiffle__JNConsent"/>
<apex:include pageName="jiffle__JNGlobals"/>
<div id="sf-jiffle-now" class="jiffle-event-page iris-bootstrap hide">         
  <apex:outputPanel id="Errorpanel" rendered="{!displayerror}"> 
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12">
        <div class="dashboard-event-list">
          <div class="event-list-head">
            <div class="event-list-head-contnet">
              <h3 data-i18n="events">events</h3>
            </div>
            <div class="event-list-menu-option">
              <div class="event-menu-content">
              </div>
            </div>
          </div>
          <div class="event-list-content scroll-x" id="event-list-content">
            <div class="list-scroll" id="event-list">  
              <div class="event-list-item empty-state">
                <div class="event-item-visuals">
                  <div class="event-banner">
                  </div>
                </div>
                <div class="empty-info">
                 <div class="text">{!$Label.jiffle__jnconfigerrormsg}</div>
               </div>
             </div>
           </div>
         </div>
       </div>
     </div>
   </div>
 </div>
 </apex:outputPanel>
 <apex:outputPanel id="Errorpanel1" rendered="{!!displayerror}"> 
  <div class="modal modal-jiffle blue modal-select-activity fade" id="select_activity" tabindex="-1" role="dialog" aria-labelledby="select_activityLabel" aria-hidden="true" data-keyboard="false" data-backdrop="static">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="select_activityLabel" data-i18n="select_activity"></h4>
        </div>
        <div class="modal-body">
          <div class="activity-list">
            <ul id="meeting_type_list">
            </ul>
          </div>
        </div>
        <div class="modal-footer">
        </div>
      </div>
    </div>
  </div>
  <div id="company-home" class="page-pad-top">
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12">
          <div class="dashboard-event-list">
            <div class="event-list-head">
              <div class="event-list-head-contnet">
                <h3 data-i18n="events"></h3>
              </div>
              <div class="event-list-menu-option">
                <div class="event-menu-content">
                </div>
              </div>
            </div>
            <div class="event-list-content scroll-x" id='event-list-content'>
              <div class="list-scroll" id='event-list'>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="precondition-cont"></div>
      <div id="js-location-container" class="row hide">
        <div class="col-md-12">
          <div class="dashboard-ebc-event-list">
            <div class="event-list-head">
              <div class="event-list-head-contnet">
                <h3 data-i18n="exec_brie_center">executive briefing center</h3>
              </div>
              <div class="event-list-menu-option">
                <div class="event-menu-content">
                </div>
              </div>
            </div>
            <div class="event-list-content scroll-x" id='location-list-content'>
              <div class="list-scroll" id="location-list">
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="js-onGoingSales-container" class="row hide">
        <div class="col-md-12">
          <div class="dashboard-onGoingSales-event-list dashboard-event-list">
            <div class="event-list-head">
              <div class="event-list-head-contnet">
                <h3 data-i18n="ongoing_sales">Ongoing Sales</h3>
              </div>
              <div class="event-list-menu-option">
                <div class="event-menu-content">
                </div>
              </div>
            </div>
            <div class="event-list-content scroll-x" id='onGoingSales-list-content'>
              <div class="list-scroll" id="onGoingSales-list">
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div id="cover">
    <div class="loaders">
      <div id="circularG">
        <div id="circularG_1" class="circularG">
        </div>
        <div id="circularG_2" class="circularG">
        </div>
        <div id="circularG_3" class="circularG">
        </div>
        <div id="circularG_4" class="circularG">
        </div>
        <div id="circularG_5" class="circularG">
        </div>
        <div id="circularG_6" class="circularG">
        </div>
        <div id="circularG_7" class="circularG">
        </div>
        <div id="circularG_8" class="circularG">
        </div>
      </div>
    </div>
  </div>
  <script language="javascript" type="text/javascript" src="{!URLFOR($Resource.JNResources, 'JNResources/application.js')}"></script>
  <script language="javascript" type="text/javascript" src="{!URLFOR($Resource.JNEvent)}"></script>
  <script language="javascript" type="text/javascript" src="{!URLFOR($Resource.JNPreconditions)}"></script>
  <script type="text/javascript">
  Visualforce.remoting.timeout = 120000;
  </script>
  </apex:outputPanel>
</div>
<div class="iris-bootstrap" id='sf-not-authorized'>
  <div class="notification-modal modal fade green not-authorized" style="z-index: 1051;display: none;">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close js-modal-close" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
          <h4 class="modal-title"></h4>
        </div>
        <div class="modal-body"></div>
        <div class="modal-footer">
          <button type="button" data-dismiss="modal" class="btn btn-blue modal-done" data-i18n="YES"></button>
          <button type="button" data-dismiss="modal" class="btn btn-blue modal-cancel" data-i18n="NO"></button>
        </div>
      </div>
    </div>
  </div>
</div>
</html>
</apex:page>



 
I wrote a second trigger for the Opportunity object in the sandbox and it works, but I would like to combine it with an existing Trigger in Production.  Can someone help me combine them?  I read some posts about doing it, but I don't understand enough about coding to follow them.
They're basically the same.  I cloned the Trigger and Apex Class and changed the name.
Thanks
trigger OpportunityTrigger on Opportunity (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
   OpportunityTriggerHandler handler = new OpportunityTriggerHandler(true);
trigger OpportunityTriggerLargeAwards on Opportunity (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
   OpportunityTriggerHandlerLargeAwards handler = new OpportunityTriggerHandlerLargeAwards(true);


 
I have a VF page that creates a pdf with an outdated image link.  I can't find the image in my org, so I want to change the link to a known image.  This is the current code:
<td style="border:1px solid black; width: 33%;">
                  <apex:image id="logo" url="{!URLFOR($Resource.avistalogo)}" width="100%"/>
               </td>
This is the current document File location:
https://cambrex--scpq.my.salesforce.com/06961000006G2t9?retUrl=%2F_ui%2Fcore%2Fchatter%2Ffiles%2FFileTabPage
And this is the location if I preview the file, then right click the image, then copy the image location, the paste it into a browser window:
https://cambrex--scpq--c.cs30.content.force.com/sfc/servlet.shepherd/version/renditionDownload?rendition=ORIGINAL_Png&versionId=06861000006j6b4&operationContext=CHATTER&contentId=05T6100000JxdqP
Can someone help me get that image to show up on the pdf that the VF page creates?  I can also give the location in the old Classic Documents folder, but I thought I'd try with the new Files location first.  The file is currently a png file, or does it need to be a jpg file?
Thanks


 
I have a Classic URL button that launches a Flow.  I would like the new record to be shown after it is created.  Can someone help me modify this URL to do that?  The button is on the Opportunity page.  It creates a new Quote record and copies some data from the Opportunity into the Quote.  Thanks
/flow/New_Quote_with_Account_and_Contact_2?RecordId={!Opportunity.Id}

 
I need this trigger to fire after the record is edited also.  Can someone add "after update" to it?
Thanks
trigger QuoteTrigger on SBQQ__Quote__c (before insert, before update) {

    if(Trigger.isBefore) {
        QuoteTriggerHandler.setSignatureURL(Trigger.new);
    }
}

 
Hi everyone,
I've purchased the Event Monitoring subscription.  I would like to get a notification in near real time whenever some runs and/or exports a report.  I've found many articles in the Developer section about Streaming API, but it's really confusing to me.  Does anyone know if there is a (relatively) simple way to just get a chatter notification if a report is run or exported?  I can't find the Event subscription channel, /event/ReportEventStream, in Flow.  I have enabled Real Time Event Monitoring in my Profile.
Thanks
I want to copy the Opportunity Score to a custom field that I can track with Field History Tracking.  Can someone tell me how to lauch a Flow or Process Builder when the Opportunity Score changes?  It doesn't work to simply use Opportunity Score ISCHANGED, I think because it is a system field.
I'm using the included Apex Class to capture inbound emails using an Email Service.  When I send an email from a record, that email is immediately duplicated as a Task also.  How do I prevent that from happening?  When I send an email without using the Email Service email address in the CC field, this doesn't happen.
Thanks!
User-added image
global with sharing class attachEmail implements Messaging.InboundEmailHandler {
    //handler overwrite
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                        Messaging.InboundEnvelope env) {
    //local variables
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    String myPlainText= '';
    myPlainText = email.plainTextBody;
    Integer i = myPlainText.indexOf('ref:',0);                                                   
    String objectId = myPlainText.substring(i+5, i+20);
Task[] newTask = new Task[0];       
                                                            
    //try to do something here
    try {
      newTask.add(new Task(Description =  myPlainText,
           TaskSubtype = 'Email',
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1,
           WhatId = objectId));
      insert newTask;       
    }
    catch (Exception e) {
        System.debug('Email failed ' + e);
    }
    result.success = true;

    return result;
    }
}

 
I have a custom Object (Market_Intelligence_Reports__c) that has a lookup field to Opportunities.  I would like to use data from the Opportunity in a HTML email template.  I can't use a VF template because I need to use the template in an Activity Email from the Market Intelligence Reports record.  Is there a way to use the Opportunity data in the template?  I've tried things like
{!Market_Intelligence_Reports__c.Opportunity__r.Account.Name}, {!Opportunity__r.Account.Name}, {!Market_Intelligence_Reports__c.Opportunity__r.Account}
Thanks
I am trying to make a very simple VF page that shows some text and a "Back" button.  I can't figure out the "Back" button.  Can someone help fix this code?  Thanks!
<apex:page standardController="Opportunity">

  
  <h1>You need to create an Opportunity directly from a Contact.</h1>

<apex:form>
<apex:commandButton value="Cancel" oncomplete="doRedirect();"/>                

            <script type="text/javascript">
                function doRedirect(){
                    window.history.back();
                }

            </script>
</apexform>
</apex:page>
if( ('Closed Won' == o.StageName) && ('Closed Won' != opportunityOldMap.get(o.Id).StageName) && (!o.Line_of_Service__c.contains('Agawam')))
Can someone help me break this IF statement into a nested IF statement so I can add system.debug between the conditions?  Thanks
 
I have an Apex Class and Apex Test Class that were written by a devloper.  I am not a developer.  I'm having trouble validating a change to the Apex Class in production but not in the sandbox.  Is there a non-developer guide to how Apex Test Classes work?  I thought the test class created a dummy record to run the Apex Class against.  I commented out the lines in the Test Class that deleted the dummy record, but I can't find it after running the test.  Am I misunderstanding how the Test Class works?
Thanks
I wrote a second trigger for the Opportunity object in the sandbox and it works, but I would like to combine it with an existing Trigger in Production.  Can someone help me combine them?  I read some posts about doing it, but I don't understand enough about coding to follow them.
They're basically the same.  I cloned the Trigger and Apex Class and changed the name.
Thanks
trigger OpportunityTrigger on Opportunity (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
   OpportunityTriggerHandler handler = new OpportunityTriggerHandler(true);
trigger OpportunityTriggerLargeAwards on Opportunity (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
   OpportunityTriggerHandlerLargeAwards handler = new OpportunityTriggerHandlerLargeAwards(true);


 
I need this trigger to fire after the record is edited also.  Can someone add "after update" to it?
Thanks
trigger QuoteTrigger on SBQQ__Quote__c (before insert, before update) {

    if(Trigger.isBefore) {
        QuoteTriggerHandler.setSignatureURL(Trigger.new);
    }
}

 
This code works to open the new Record that was created by a Flow, but I want the Record to open in Edit mode.  Is it possible to modify this code so it opens the new Record in Edit mode?
({

	invoke : function(component, event, helper) {
    	var args = event.getParam("arguments");
        
        
        var destObject = component.get("v.SObject");
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
          "recordId": destObject,
          "slideDevName": "related"
        });
        navEvt.fire();
     
}
     
 })
I have a Lightning component that I use in a Flow that opens the new record the Flow creates.  It works in a screen Flow, but not in an auto-launched Flow.  I get this error:  OpenNewRecord (Action Call) - The action type "Local Actions" can't be used in flows with the process type "Autolaunched Flow". 
Is there a way to change the component so that I can use it in an auto-launched Flow?
The following formula will calculate the number of working days (inclusive) between 2 dates. A working day is defined as Monday to Friday. Even if the start or end dates are a weekend, these are accommodated.

IF(AND((5 - (CASE(MOD( Start_Date__c - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) < (CASE(MOD(  End_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) ),
((( End_Date__c  -   Start_Date__c ) + 1) < 7)),
((CASE(MOD(  End_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) - (5 - (CASE(MOD(  Start_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)))),
(((FLOOR((( End_Date__c  -  Start_Date__c ) - (CASE(MOD(  Start_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 6, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0))) / 7)) * 5) +
(CASE(MOD(  Start_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) +
(CASE(MOD(  End_Date__c  - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0))))


The Start Date and End Date fields are custom in the above example and can be replaced as required. If use of a DateTime field is required then the DATEVALUE function will be required.

I also recommend a simple field validation rule is added to check that the End Date is after the Start Date.
  • January 05, 2009
  • Like
  • 9

Simply put the following formula into a formula field of type "Text":

 

Id
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,1,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,2,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,3,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,4,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,5,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,6,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,7,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,8,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,9,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,10,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,11,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,12,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,13,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,14,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,15,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)

 

This is an optimized version of the code example "BPS: 18 digit external ID within the UI" you can find on the Online Help, but unlike the example provided there, it is small enough to fit into a formula field. Also, this code doesn't contain the error found in the online help example, where the second character byte equivalent of the first 5-character chunk was "4" instead of "2". I'd be more than happy if someone could come up with an even shorter version of this formula...Still, I hope you can use this.

 

Cheers,

Erik Mittmeyer