• JO_Dev
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 2
    Likes Given
  • 18
    Questions
  • 2
    Replies
The following code gives me an error because the final character for the string '<img src="data:image\' contains \

How do I fix this?

myLog.EmailHTML__c.replaceAll('<img src="data:image\', '<img src="data:image/');
  • February 07, 2017
  • Like
  • 0
This exception usually happens when a batch is being run or alerts are coming into our Salesforce instance too quickly. When inserting a case, we try to lock down the contact and account associated with the case before inserting the case to prevent the 'UNABLE_TO_LOCK_ROW' exception from happening.

Here is the exact exception:
'System.QueryException: Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again.'
Class.Utility.DoCaseInsertion: line 98, column 1

I've done a lot of research on the 'UNABLE_TO_LOCK_ROW' exception and 'Record Currently Unavailable' exception and I can't seem to find a great solution to this issue.

What I've tried to accomplish is a loop to attempt the insert 10 times, but I'm still getting the 'Record Currently Unavailable' exception. Does anyone else have a suggestion for this?

Below is the code:

    Public static void DoCaseInsertion(case myCase) { try { insert myCase; } catch (System.DmlException ex) { boolean repeat = true; integer cnt = 0; while (repeat && cnt < 10) { try { repeat = false; List<Contact> contactList = [select id from Contact where id =: myCase.ContactId for update]; // Added for related contact to overcome the 'UNABLE_TO_LOCK_ROW issues' List<Account> accountList = [select id from Account where id =: myCase.AccountId for update]; // Added for related account to overcome the 'UNABLE_TO_LOCK_ROW issues' insert myCase; } catch (System.DmlException e) { repeat = true; cnt++; } } } }
  • February 03, 2017
  • Like
  • 0
How do I edit the formula of a Custom Field Definition that is managed?

User-added image

 
When using the Salesforce Data Loader and trying to login with the oauth option. I get a blank screen. Why is that?

User-added image

 
  • April 27, 2016
  • Like
  • 2
Is there any way that I can access Java or .Net code from a static resource?
  • April 18, 2016
  • Like
  • 0
For some reason, when I go to the developer console in my sandbox, I don't see the new classes I created listed in the Overall Code Coverage section on the bottom right. Do I need to refresh anything in the sandbox?

User-added image
  • April 18, 2016
  • Like
  • 0
Are there any good examples of using a PDF Parser in Apex?
  • April 18, 2016
  • Like
  • 0
Do you have an example code that searches through the PDF or Doc Content for specific information?
  • April 18, 2016
  • Like
  • 0
I need to know how to read the uploaded PDF or DOC file content in Apex. Is there any way to do it? The code below doesn't seem to work for me

public static String blobToString(Blob input, String inCharset){
    String hex = EncodingUtil.convertToHex(input);
    System.assertEquals(0, hex.length() & 1);
    final Integer bytesCount = hex.length() >> 1;
    String[] bytes = new String[bytesCount];
    for(Integer i = 0; i < bytesCount; ++i)
       bytes[i] =  hex.mid(i << 1, 2);
    return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset);
    }         
  • April 18, 2016
  • Like
  • 0
Is there a way to find out the size of the Messaging.EmailFileAttachment?

I also need to know the combined size of a List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();

 
  • April 17, 2016
  • Like
  • 0
I need to figure out how to download a file to a specific directory. Is there a way to do this?
  • April 17, 2016
  • Like
  • 0
Is there a way in Apex that I can get the results without writing a SOQL Query?

public List<KnowledgeArticleVersion> getArticlesByKeyword(List<KnowledgeArticleVersion> kavListPreFiltered, string keyword)
        {
            List<KnowledgeArticleVersion> resultList = new List<KnowledgeArticleVersion>();
            List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();  
            for(Schema.SObjectType f : gd)
            {
                if(f.getDescribe().getName().endsWith('__ka'))
                {system.debug('---f:'+f);
                    Map<String, Schema.SObjectField> FieldMap = f.getDescribe().fields.getMap();
                    for (String FieldName: FieldMap.keySet()) 
                    {                    
                        system.debug('---fieldMap.get(fieldName).getDescribe().getLabel():'+fieldMap.get(fieldName).getDescribe().getLabel());
                        }
                }
            }
            
            return resultList;
        }
  • April 17, 2016
  • Like
  • 0
Why can't I use the 'In' operator for this query?
SELECT KnowledgeArticleId from KnowledgeArticleVersion WHERE PublishStatus in ('Draft','Online','Archived') AND Language = 'en_US' 

I get the following error:

Invalid PublishStatus filter value. Valid values are 'Draft','Online' and 'Archived'
  • April 14, 2016
  • Like
  • 0
I need to know how to how to attach a zip file to an email

for (KnowledgeArticleVersion k : kavListFiltered)
    {
        string trimId = '' + k.KnowledgeArticleId;
        trimid = trimid.substring(0,15);
        PageReference pdf = new PageReference('/knowledge/articlePrintableView.apexp?id='+trimid);
        Blob body;
        try 
        {
              body = pdf.getContentAsPDF();
        } 
        catch (VisualforceException e) 
        {    
              body = Blob.valueOf('Some Text');
        }
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.setContentType('application/pdf');
        attach.setFileName(k.Title+'.pdf');
        attach.setInline(false);
        attach.Body = body;
          fileAttachments.add(attach);
    }

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setUseSignature(false);
    mail.setToAddresses(new String[] { 'test@test.com' });
    mail.setSubject('Article Export Results');
    mail.setHtmlBody('Attached are the Article Export Results');
    mail.setFileAttachments(fileAttachments);
    
    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  • April 11, 2016
  • Like
  • 0
I am trying to get the picklist values from a multi select picklist but for some reason it is not coming through when exporting:

VF Page section

    <apex:form >
        <apex:pageBlock title="Article Export" mode="edit">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!Export}" value="Email"/>
            </apex:pageBlockButtons>

            <apex:PageBlockSection title="" columns="2" collapsible="false">
            
            <apex:PageBlockSectionItem >
                    <span>Article Status: </span>
                    <apex:selectList value="{!selectedArticleStatusOptions}" size="7" multiselect="true">
                    <apex:selectOptions value="{! articleStatusOptions}" />    
                    </apex:selectList>
            </apex:PageBlockSectionItem>
            
            </apex:PageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Apex:

public with sharing class ArticleExport
{
        public Set<String> selectedArticleStatusOptions = new Set<String>();
    public ArticleExport()
    {
        this.articleStatusOptions = new SelectOption[]{‘Published’,’Draft’};
    }
 
    public SelectOption[] articleStatusOptions
    {
          public get;
          private set;
    }
    public PageReference Export()
    {
       selectedArticleStatusOptions
    }
}

 
  • April 11, 2016
  • Like
  • 0
How do I write a SOQL query for data categories?
  • April 11, 2016
  • Like
  • 0
How do I write a SOQL Query to get all Knowledge Article Types?
  • April 11, 2016
  • Like
  • 0
I can't seem to get debug logs working for Change Set Validation in PROD. I have checked in the regular Debug Logs section and the Developer Console. They don't show up. The debug logs show up for everything else and I have the User Trace Flag levels FINEST for everything. Is there something I'm missing?

I have done research with the following links with no luck:

How to view the detailed debug log of the change set validation in production

https://success.salesforce.com/ideaView?id=08730000000jcv1AAA

https://help.salesforce.com/apex/HTViewHelpDoc?id=code_setting_debug_log_levels.htm&language=en
  • November 13, 2015
  • Like
  • 0
When using the Salesforce Data Loader and trying to login with the oauth option. I get a blank screen. Why is that?

User-added image

 
  • April 27, 2016
  • Like
  • 2
This exception usually happens when a batch is being run or alerts are coming into our Salesforce instance too quickly. When inserting a case, we try to lock down the contact and account associated with the case before inserting the case to prevent the 'UNABLE_TO_LOCK_ROW' exception from happening.

Here is the exact exception:
'System.QueryException: Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again.'
Class.Utility.DoCaseInsertion: line 98, column 1

I've done a lot of research on the 'UNABLE_TO_LOCK_ROW' exception and 'Record Currently Unavailable' exception and I can't seem to find a great solution to this issue.

What I've tried to accomplish is a loop to attempt the insert 10 times, but I'm still getting the 'Record Currently Unavailable' exception. Does anyone else have a suggestion for this?

Below is the code:

    Public static void DoCaseInsertion(case myCase) { try { insert myCase; } catch (System.DmlException ex) { boolean repeat = true; integer cnt = 0; while (repeat && cnt < 10) { try { repeat = false; List<Contact> contactList = [select id from Contact where id =: myCase.ContactId for update]; // Added for related contact to overcome the 'UNABLE_TO_LOCK_ROW issues' List<Account> accountList = [select id from Account where id =: myCase.AccountId for update]; // Added for related account to overcome the 'UNABLE_TO_LOCK_ROW issues' insert myCase; } catch (System.DmlException e) { repeat = true; cnt++; } } } }
  • February 03, 2017
  • Like
  • 0
I am trying to get the picklist values from a multi select picklist but for some reason it is not coming through when exporting:

VF Page section

    <apex:form >
        <apex:pageBlock title="Article Export" mode="edit">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!Export}" value="Email"/>
            </apex:pageBlockButtons>

            <apex:PageBlockSection title="" columns="2" collapsible="false">
            
            <apex:PageBlockSectionItem >
                    <span>Article Status: </span>
                    <apex:selectList value="{!selectedArticleStatusOptions}" size="7" multiselect="true">
                    <apex:selectOptions value="{! articleStatusOptions}" />    
                    </apex:selectList>
            </apex:PageBlockSectionItem>
            
            </apex:PageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Apex:

public with sharing class ArticleExport
{
        public Set<String> selectedArticleStatusOptions = new Set<String>();
    public ArticleExport()
    {
        this.articleStatusOptions = new SelectOption[]{‘Published’,’Draft’};
    }
 
    public SelectOption[] articleStatusOptions
    {
          public get;
          private set;
    }
    public PageReference Export()
    {
       selectedArticleStatusOptions
    }
}

 
  • April 11, 2016
  • Like
  • 0
I have a unit test that is throwing UNABLE_TO_LOCK_ROW when it is doing an insert. I don't understand why that should happen. Here's the code (excerpted). The exception is thrown on the insert statement. Because this is a new record, and contained within a test class, how can it throw a UNABLE_TO_LOCK_ROW exception?

@istest
private class MyTest {
    ...
    theQuote = new Quote(Name='Test Quote',
                         OpportunityId = theOpp.Id,
                         Term__c=12,
                         pricebook2id=thePricebook.id);
    insert theQuote;
    ...
}


 

A client of one of our web service written in Apex reported an error.  It turns out there was an error --

 

Insert failed. First exception on row 9; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusie access to this record: []

 

I'm trying to think of what would cause an lock problem on an insert.  The method does to a start transaction and then inserts a row in Opportunity and then several in OpportunityLineItem. 

 

I don't see how the problem could be with the row being inserted.  Could it be with something locked a parent record like account?  Could something have already read the Opportunity record while the OpportunityLineItem records where being written?