+ Start a Discussion

Hi Team,


In Text type of Email Templates, i want to specify logged in user as merge field. Could anyone have any suggestions.

I have tried with the following lines. But it is not working.








Best Answer chosen by Admin (Salesforce Developers) 

Hi Anil,


You are using only '!', please use '!$' like {!$User.FirstName}

Hi All,
Help me on this, i want using validation rule "Dealer user cannot save if the selected picklist value in Status field in "Inquiry" record type in Case is "Uploaded".
Best Answer chosen by sanjusfdc
Prakash NawalePrakash Nawale

Use below code in validation rule to prevent creating of Case record based on your requirments.
            $User.Username = 'Dealer username',
            ISPICKVAL( Status , 'Uploaded') 

Please like the answer and mark it as best if this helps.
EQ AdminEQ Admin 
for(Apttus_Billing__Invoice__c invoice:invoiceObjectList1) // loop over invoices
                  List<InvoiceLineItems> listToStoreLineItems = new List<InvoiceLineItems>();
                  APTS_InvoiceJournalWrapper invoiceJournWrapper= new APTS_InvoiceJournalWrapper();
                  Decimal Sum=0;
                                    invoiceJournWrapper.AccountingJournalID=String.valueOf(invoice.Name + '_' +myDate);
                                    invoiceJournWrapper.JournalNumber=String.valueOf(invoice.Name + '_' +myDate);
                  list<Apttus_Billing__InvoiceLineItem__c> invlineitems=[Select id,Apttus_Billing__AssetLineItemId__r.Apttus_Config2__ProductId__r.ProductCode,Apttus_Billing__AssetLineItemId__r.Apttus_Config2__OptionId__r.ProductCode,Apttus_Billing__InvoiceId__r.Name,Apttus_Billing__ProductId__r.Name,Apttus_Billing__InvoiceId__r.CurrencyIsoCode,
                                                             from Apttus_Billing__InvoiceLineItem__c where Apttus_Billing__InvoiceId__c=:invoice.id and Apttus_Billing__Type__c='Contracted' and Apttus_Billing__Amount__c!=0];
                   InvoiceLineItems FirstInvItems= new InvoiceLineItems();

Best Answer chosen by EQ Admin
paul diracpaul dirac
I find some errors and the code does not compile (i mocked all of your custom object but anyway there might be some sintax errors).
Consider to split some "iterative tasks" in an helper (static) class, since your Rest service might grows in future, developers (you too ofc) may encounter difficulties to maintain that. For example, that part in which lineItems are collected and then modified can be delegated to the helper class to enhance code readability.
Further little optization can be done storing fixed numbers/strings in costants but I guess that there are not any improvements that significately reduce the execution time, I mean the optimization I will want to see here is in code readability first. Hope I helped you to solve your cancerns!
Hi, I'm running into an issue with getting an access token using a connected app with grant_type = password.  Here is my curl script:

curl https://test.salesforce.com/services/oauth2/token -H "Content-Type:application/x-www-form-urlencoded" -d "grant_type=password" -d "client_id=<my client_id>" -d "client_secret=<my client_secret>" -d "username=<myusername@domain.com>" -d "<my password+secret>"

I'm getting an invalid_grant error  "Authentication failure" 
Best Answer chosen by gs88834
SandhyaSandhya (Salesforce Developers) 

Going to connected apps in Salesforce and changing 'permitted users' from 'Admin approved users are pre-authorized' to 'All users may self-authorize' 

Please refer below link step 9 which worked for others it may help you.


Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution. 
Thanks and Regards

Julian KeefeJulian Keefe 
Error Message:
Challenge Not yet complete... here's what's wrong: 
The AccountTab Visualforce page does not include one or both of the following: the apex:slds tag in the page, or the slds-table value in the table.

Hello all. I am working on the new superbadge and getting stuck on Challenge 3 . I have tried several solutions but cannot get the data to display in table format. Here is my code below, my main issue is where to place the table class in realtion to the pageBlockTable.

<apex:page standardStylesheets="false" standardController="Account" recordSetVar="accounts" tabStyle="account" applyBodyTag="false">
    <apex:slds >
        <div class="slds-scope">
                    <table class="slds-table"> 
                    <apex:pageBlockTable  value="{!accounts}" var="a">
                        <apex:column headerValue="{!$ObjectType.Account.Fields.Name.Label}">
                            <apex:outputLink value="{!URLFOR($Action.Account.View, a.id)}">{!a.name}</apex:outputLink>

Best Answer chosen by Julian Keefe
David HamburgDavid Hamburg

<apex:page standardStylesheets="false" standardController="Account" recordSetVar="accounts" tabStyle="account">
<apex:slds />

    <div class="slds-scope">
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accounts}" var="a"  styleClass="slds-table" >
                <apex:column headerValue="{!$ObjectType.Account.Fields.Name.Label}">
                    <apex:outputLink value="{!URLFOR($Action.Account.View, a.id)}">{!a.name}</apex:outputLink>

I have a regular old PDF file on my desktop, and that same PDF file is attached to a record in Salesforce.  Now, when I change the PDF's extension on my computer to ".txt", I can then open it and read the texttual data that makes up the file.  I need to extract some data at the beginning of the ".txt" version of the file that details how many pages the PDF consists of, but I need to do this for many PDF files that are already in Salesforce.

I discovered the "String pdf = System.EncodingUtil.base64Encode(a.Body)" method, which apparently converts the base64 blob representation of the file into an unencoded string... but when I looked at the actual output, I realized that it was totally different compared to the ".txt" version of the PDF on my desktop.  It seems that I'm not encoding/decoding the attachment Body blob to the correct format, but I'm totally clueless as to what to convert it to, or what method I would need to use to convert it.

Does anyone have any ideas as to how I would convert the PDF data to whatever format it gets converted to when I just change the extension on my computer and view it in notepad?


Best Answer chosen by Chris760
Ray GuyRay Guy
This isn't easy at all unfortunately.   What you're trying to do is view the bytes of the attachment coverted into displayable characters where possible.   What opening it in a text editor is doing for you is ignoring the binary characters that don't make sense as display characters.   Unfortunately if you try and get there using apex, salesforce will stop you short since there's no way to tell it to ignore binary values that aren't character display data.   Instead of ignoring them, it will give you an error instead when it encounters them.  For example, you could try and convert the Attachment's Body field to a String directly using:

String pdf = attachment.Body.toString();

but it's going to give you an error saying the BLOB (binary data) is "not a valid UTF-8 string".   What it means by this is some of the values it's coming across in the binary data don't match to any character it could put in a String (Salesforce uses "UTF-8" string encoding) - so it rejects the whole lot.   Your text editor on the other hand just replaces these with whitespace and lets you view the valid ones.

You can turn binary data into a form that can be shown in a String but that's what you have already, and as you've found, in order to turn all the binary data into valid display characters it encodes the whole thing making it unreadable for your purposes.

It would be great if you were able to step through the binary data in the Attachment Body one byte at a time, extract the ones that are normal characters and ignore the others.   But this isn't possible in apex.

The convoluted workaround that some have done involves turning the binary data into encoded base64 format (as you have).   But then hand-rolling a base64 decoder which will pick through the encoded string piece by piece and give you access to the individual decoded byte values.    You would then be able to add your own logic to determine if the byte is in the normal ascii character range (0 to 128)  (This appears to be how the values are stored in the first part of a PDF)

Here's a stackexchange question where the accepted answer delves into this a bit: http://salesforce.stackexchange.com/questions/860/mimic-mysql-aes-encrypt-in-apex/910#910
But it's pretty heavy code work I'm afraid and far from simple.

ForceClarity Ltd.
Anthony Wheeler 1Anthony Wheeler 1 
I'm wondering if this is just a glitch in Salesforce and if anyone has any workaround. I currently have a Trigger on ContentDocumentLink that sends an email to the owner of a custom object record when a File or Note is created and attached to that record. The trigger also attaches file information and the body of the Note if it's a ContentNote being inserted. The trigger handles the logic in differentiating Notes from other file types. The problem is when the user hits the button to create a new Note in classic or in the Console, an empty, untitled, new note record is inserted instantly firing my trigger before the user has time to add content to the body. In Lightning it at least allows the user to fill out the header of the note before saving, but saves before the note body is filled out. Cancelling out of creating the note still leaves the blank note saved and attached to the record. Any help in understanding why the note saves before the user hits the save button would be appreciated.
Best Answer chosen by Anthony Wheeler 1
Ryan GreeneRyan Greene
This is an annoying way SF setup the Content Notes. It does save every secord or so after the user starts typing. The only way I could figure out how to overcome this issue is to run batch Apex, but then you loose the real time notifications. Might need to try hooking it up Chatter somehow.
I keep getting an error on Item #4 "The custom set of fields that are highlighted on account records must be assigned to the required profile."

The requirement is asking for having highlights based on profiles, but as we know compact layouts are applied to the whole system not by profile.

I am not sure how to fix this, any help is appreciated.
Best Answer chosen by Samy.Saied
@Carl That is exactly what I did, but the issue is that the requirement want to assign a different compact layout per profile, and the only way to do that is by assigning different record type to the corresponding profile.

Apparently in order to pass this question you have create the record type although I am not convinced that because one user in the org want to use it differently, I would create him a different record type considering this can be done in many other ways like grouping the fields he is interested in to the top of the page in a section. Creating a whole new record type sort of limit the other users from different profiles use the same accounts and see their highlights.

I believe this requirement is badly worded.
Ghulam Murtaza 5Ghulam Murtaza 5 

i am a newbie to salesforce and trying to complete this trailhead challenge and unable to find a way through apex to generate this method for creating new contacts with unique id. as one requirement to pass the challenge is "The 'generateRandomContacts' method must be capable of consistently generating contacts with unique first names."

If somebody successfully completed the task kindly help me.

Best Answer chosen by Ghulam Murtaza 5
Ghulam Murtaza 5Ghulam Murtaza 5
hi pankaj,
i have completed the task somehow. my friend completed it with a simple code i.e. 
public class RandomContactFactory{
   public static List<Contact> generateRandomContacts(integer n,string lastname){
       integer n1= n;
       list<contact> c=[select  FirstName from contact limit : n1];
       return c;

but for me it was giving error of class not created as static or either the method is not returning the first name. so for me it worked as follows:

public class RandomContactFactory{

    public static List<Contact> generateRandomContacts(integer n,string LastName){
    integer n1=n;
    List<contact> c1 = new list<contact>();
    list<contact> c2 =new list<contact>();
     c1 = [select FirstName from Contact Limit : n1];
     integer i=0;
     for(contact cnew : c1){
     contact cnew1 = new contact();
     cnew1.firstname = cnew.firstname + i;
    return c2;
James Kacerguis 5James Kacerguis 5 
I currently have apex class in lightning component that is getting a specific Queue Id to assign as owner of the record the component is launched from.

This is the current  way I'm getting the id, but I'm guessing there is a better way to do this, any ideas?
Group marketingQueue = [SELECT id,Name FROM Group WHERE Type = 'Queue' and DeveloperNAME = 'MarketingProspectLeads'];
         	ID marketingQueueId = marketingQueue.id;
            //l.OwnerId = UserInfo.getUserId();
            l.OwnerId = marketingQueueId;

I just need to make sure this can't break so I'm assuming I should add some error checking or be doing this a different way.  Thanks in advance.  
Best Answer chosen by James Kacerguis 5
Hi James,
If you don't require Name then you can modify your query as follows to reduce number of lines in code and add NULL check before assignment to avoid code break.
ID marketingQueueId = [SELECT id FROM Group WHERE Type = 'Queue' and DeveloperNAME = 'MarketingProspectLeads'].Id;

if(marketingQueueId != NULL) {
    l.OwnerId = marketingQueueId;

Kindly mark as resolved if you find this anser helpful.