+ Start a Discussion
Sharon CrenshawSharon Crenshaw 
I keep getting the following error while running my Apex Test Class. If I could please get assistance in resolving the problem I would appreciate it. I continue getting the following error:

System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, Alias: data value too large: Sminull90 (max length=8): [Alias]

Below is my code:

Apex Class:

public  class NewUtilStaffProcess {
       @future
       public static void createUtlUser(Id recid) {
            
           Contact gcon = [SELECT Email, Lastname, Firstname, Middlename, AcctId
                            FROM   Contact
                            WHERE  Id = :recid];
           
           Profile p = [SELECT Id FROM Profile WHERE Name='HAVNA City Public Utility Group'];
           
           Id acctsTypeId = [SELECT Id
                            FROM   RecordType
                            WHERE  SObjectType = 'Account'
                            AND    Name = 'Account Source'].Id;
           
           String groleId = [SELECT Id FROM UserRole WHERE Name = 'Utility Staff' LIMIT 1].Id;
           
           
           String formatUsrName;
           String setUsrLoc;
           
           Account retAcct = [SELECT Id, HAVNA_Country__r.HAVNA_Letter_Code__c, Hav_Locality__c, Hav_Street__c
                               FROM   Account
                               WHERE  Id = :gcon.AcctId
                               AND    recordTypeId = :acctsTypeId
                               LIMIT 1];
           
           if (retAcct.Hav_Street__c == 'Local/Surveyor')
              setUsrLoc = retAcct.HAVNA_Country__r.HAVNA_Letter_Code__c+retAcct.Hav_Locality__c;
        
           if (retAcct.Hav_Street__c == 'City/Surveyor')
              setUsrLoc = retAcct.HAVNA_Country__r.HAVNA_Letter_Code__c+'C1';
         
           if (retAcct.Hav_Street__c == 'State/Surveyor')
              setUsrLoc = retAcct.HAVNA_Country__r.HAVNA_Letter_Code__c+'C2';
        
             
           if (gcon.middlename == null) {
               formatUsrName = gcon.Lastname.deleteWhitespace().toLowercase().trim()+'.'+gcon.Firstname.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
           } else {
               Integer midSize = gcon.Middlename.length();
               if (midSize == 1) {
                   formatUsrName = gcon.Lastname.deleteWhitespace().toLowercase().trim()+'.'+gcon.Firstname.deleteWhitespace().toLowercase().trim()+'.'+gcon.middlename.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
               } else {
                   formatUsrName = gcon.Lastname.deleteWhitespace().toLowercase().trim()+'.'+gcon.Firstname.deleteWhitespace().toLowercase().trim()+'.'+gcon.middlename.deleteWhitespace().trim().substring(0,1).toLowercase()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
               }    
           }

           System.debug('Formatted Username: '+formatUsrName);
      
           User u       = new User(Alias    = gcon.Lastname.deleteWhitespace().trim().length() > 4 ? gcon.Lastname.deleteWhitespace().trim().substring(0,3)+setUsrLoc: gcon.lastname+setUsrLoc,
                         Email              = gcon.Email,
                         EmailEncodingKey   = 'UTF-8',
                         LastName           = gcon.Lastname,
                         FirstName          = gcon.Firstname,
                         MiddleName         = gcon.Middlename,         
                         LanguageLocaleKey  = 'en_US',
                         LocaleSidKey       = 'en_US',
                         ProfileId          = p.Id,
                         UserRoleId         = groleid,          
                         TimeZoneSidKey     = 'America/New_York',
                         UserName           = formatUsrName);
          
           Insert(u);
           System.debug(u.id);
           
           UtilStaffPermSet.assgnPermissionSet(recId, u.Id);  
           System.resetPassword(u.Id, True);

      }
}

Apex Test Class:

@isTest
public class NewUtilStaffProcessTest {

   public static testMethod void InitialTest() {

        /* Get Record Id Type */   
        Id conTypeId;
        Id acctTypeId;
        String formatUsrName;
        String setUsrLoc;
        
        conTypeId = [SELECT Id  
                     FROM   RecordType
                     WHERE  SObjectType = 'Contact'
                     AND    Name = 'Utility Staffer'].Id;  

       
        Id acctsTypeId = [SELECT Id
                      FROM   RecordType
                      WHERE  SObjectType = 'Account'
                          AND    Name = 'Account Source'].Id;

        Profile p = [SELECT Id FROM Profile WHERE Name='HAVNA City Public Utility Group'];
        String groleId = [SELECT Id FROM UserRole WHERE Name = 'Utility Staff' LIMIT 1].Id;

        Integer midsize;
       
        //Create new State record; initialize required field(s), then insert
        HAV_State_and_Country__c state  = new HAV_State_and_Country__c();
        state.Name                = 'Oregon';
        state.HAV_Letter_Code__c = 'OR';
        state.HAV_Type__c        = 'State';
        Insert state;
        
        //Create new Account record; initialize required field(s), then insert
        Account acct = new Account(Name='Oregon Local 7');
        acct.Hav_Locality__c     = '90';
        acct.Hav_Street__c     = 'Local/Surveyor';
        acct.RecordTypeId     =  AcctTypeId;
        acct.HAV__Country__c    = state.id;
    insert acct;

        //Create new Contact record; initialize required field(s), then insert
        Contact con  = new Contact();   
        con.FirstName       = 'Ralph';  
        con.LastName        = 'Smith';
        con.Middlename      = 'Otis';
        con.RecordTypeId    =  conTypeId;
        con.email           = 'rsmith8@verizon.com';
        con.AcctId          = acct.id;
          
        //Insert Contact
        Insert con ;
       
          System.debug(con.id);
 
       Account retAcct = [SELECT Id, HAV_Country__r.HAV_Letter_Code__c, Hav_Locality__c, Hav_Street__c
                          FROM   Account
                          WHERE  Id           = :con.AcctId
                          AND    recordTypeId = :nomsTypeId
                          LIMIT 1];
                          
       if (retAcct.Hav_Street__c == 'Local/Surveyor')
              setUsrLoc = retAcct.HAV_Country__r.HAV_Letter_Code__c+retAcct.Hav_Locality__c;
 
       if (con.middlename == null) {
           System.debug('3: '+setUsrLoc);
               formatUsrName = con.Lastname.deleteWhitespace().toLowercase().trim()+'.'+con.Firstname.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
           } else {
               System.debug('4: '+setUsrLoc);
               midSize = con.Middlename.length();
               if (midSize == 1) {
                   System.debug('5: '+setUsrLoc);
                   formatUsrName = con.Lastname.deleteWhitespace().toLowercase().trim()+'.'+con.Firstname.deleteWhitespace().toLowercase().trim()+'.'+con.middlename.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
               } else {
                   System.debug('6: '+setUsrLoc);
                   formatUsrName = con.Lastname.deleteWhitespace().toLowercase().trim()+'.'+con.Firstname.deleteWhitespace().toLowercase().trim()+'.'+con.middlename.deleteWhitespace().trim().substring(0,1).toLowercase()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
               }    
           }
           
 User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
 system.runAs(thisUser){
         User u       = new User(Alias      = con.LastName.deleteWhitespace().trim().length() > 4 ? con.LastName.deleteWhitespace().trim().substring(0,4)+setUsrLoc: con.LastName+setUsrLoc,
                         Email              = con.email,
                         EmailEncodingKey   = 'UTF-8',
                         LastName           = con.LastName,
                         FirstName          = con.Firstname,
                         MiddleName         = con.Middlename,         
                         LanguageLocaleKey  = 'en_US',
                         LocaleSidKey       = 'en_US',
                         ProfileId          = p.Id,
                         UserRoleId         = groleid,          
                         TimeZoneSidKey     = 'America/New_York',
                         UserName           = formatUsrName);
          
           Insert(u);
           System.debug(u.id);  

                        
        Test.startTest();
       
        NewUtilStaffProcess.createUtlUser(con.id);
 
        Test.stopTest();
        system.debug('Done');
    }
     }
}

Thanks.
Best Answer chosen by Sharon Crenshaw
Maharajan CMaharajan C
Hi Sharon,

The User Alias field has default size limit which is Maximum 8 characters. But code generating more than 8 character (Sminull90). 

Your code generating the alias dynamically so you have to handle the characters limit. And also avoid the null by using proper null check because am seeing null got genereated in alias Sminull90.
Alias      = con.LastName.deleteWhitespace().trim().length() > 4 ? con.LastName.deleteWhitespace().trim().substring(0,4)+setUsrLoc: con.LastName+setUsrLoc

Thanks,
Maharajan.C
AneeshaAneesha 

I have certain list views on the custom objects which I want only certain group of people to see. For example I have two list views LV1 and LV2. Certain group of users should only see LV1 and certain others should see only LV2.I have created two public groups and restricted the visibility to 'Certain groups' but still the users are able to see both the list views LV1 and LV2.

 

Upon investigation I found that the users have system permission 'Manage Public List Views' in their profile.

 

What can I do to restrict the users from viewing the list views they are not supposed to see?

Best Answer chosen by Aneesha
VaasuVaasu
I think only way is removing "Manage Public List Views" permissions on the profile coz profile permissions will be taken high priority.
Sharmila Sahu 12Sharmila Sahu 12 
I want to set record type while creating record in lightning component through e.force:createRecord. But I am not able to do so.
I tried using custom label and even I tried hardcoding still It is not showing correct record type and it is showing default record type for record creation.
Please find below code for javascript controller:
({
    doInit: function (component, event, helper) {
        var recId = component.get("v.recordId");
        console.log(recId);

        var action = component.get("c.getdetails");
        action.setParams({
            "sId": recId
        });
        action.setCallback(this, function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                $A.get("e.force:closeQuickAction").fire();
                console.log("Success" + JSON.stringify(response.getReturnValue()));
                component.set("v.sampleRequest", response.getReturnValue());
                var sampProd = component.get("v.sampleRequest");
                
                 if(sampProd.Lead__c === sampProd.Contact__c){
                    var Name = sampProd.Contact__r.Name;
                }
                else
                {
                   var Name = sampProd.Lead__r.Name; 
                }
                


                var createSampleProduct = $A.get("e.force:createRecord");
                var staticRecordLabel = $A.get("$Label.c.UsCanSampleProductRecordType");
                createSampleProduct.setParams({
                    "entityApiName": "Sample_Product__c",
                    "RecordTypeId": '0121b0000004aeSAAQ',
                    "defaultFieldValues": {
                        'Sample_Request__c' : component.get("v.recordId"),
                        'Name__c': Name,                    
                    }
                });
                createSampleProduct.fire();
            } else {
                console.log("Fail");
            }
        });
        $A.enqueueAction(action);
    }
})

I tried hardcoding:
              var staticRecordLabel = $A.get("$Label.c.UsCanSampleProductRecordType");
                createSampleProduct.setParams({
                    "entityApiName": "Sample_Product__c",
                    "RecordTypeId": '0121b0000004aeSAAQ',

I have tried using:

            var staticRecordLabel = $A.get("$Label.c.UsCanSampleProductRecordType");
                createSampleProduct.setParams({
                    "entityApiName": "Sample_Product__c",
                    "RecordTypeId": staticRecordLabel ,

it is just showing for 1 sec 
UsCanSampleProductRecordType and then it is taking me to record creation page with default record type.

Please help. 
Best Answer chosen by Sharmila Sahu 12
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sharmila,

Greetings to you!

You need to use recordTypeId instead of RecordTypeId as lightning is based on aura framework which is a type of JavaScript and JavaScript is case sensitive so lightning is case sensitive.

Please refer to the below links which might help you further.

http://sfdcmonkey.com/2017/05/09/custom-record-type-selection-lightning-component/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
jadentjadent 

On the task there is a WhatId and a WhoId. Sometimes the WhatId is filled in and others have the WhoId filled in. In which situations is one used over the other?

 

Thanks 

Best Answer chosen by Admin (Salesforce Developers) 
dkorba2k5dkorba2k5

WhoID refers to people things.  So that would be typically a Lead ID or a Contact ID

WhatID refers to object type things.  That would typically be an Account ID or an Opportunity ID

Salesforce GeekSalesforce Geek 
Hi There,

I’m newbie to Salesforce.

I would like to know the syntax “How to subtract one minute and two minutes from the current time”? I have checked in Datemethods in Apex documentation. No luck found.

Can anyone help?

Thanks
 
Best Answer chosen by Salesforce Geek
PratikPratik (Salesforce Developers) 
Hi,

This will work:

For 1 minute:   NOW() - (1/1440)
For 2 minutes:  NOW() - (2/1440)

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
Naren9Naren9 
Hi All,
As of now, Case page layout has Product Pick list, and we can select only one Product and it mainted by Pick List Values.
What I am looking is that, When we create a Case, we should able to select Multiple Products to that Case. How we can achieve this?.

Do we need to create a Junction Object between Cases and Product?.
I think Junction Object is not going to support for Product as Product Standard object is going to be Detail Side of Junction Object, which is not supported by Salesforce.

Please correct me if I am wrong.
Also, please suggest me an alternative methods.

Thanks,
Naren
Best Answer chosen by Naren9
Boss CoffeeBoss Coffee
A Junction Object should work fine for this scenario. After a Case is created, you can create however many junction records as there are products you need to relate to the Case. You won't be able to make a Master-Detail Lookup to Product though, but you can use a regular Lookup and it should serve the same purpose of connecting the products to the Case.
Suzanne WasnerSuzanne Wasner 
I know I have completed the challenge correctly but keep getting this error. Note that the challenge has you create a "custom" object, not a "customer" object as stated in the error. I would like my 500 pts, please. :-)
Best Answer chosen by Suzanne Wasner
Ajay K DubediAjay K Dubedi
Hi Suzanne,

Remember, this module is meant for Lightning Experience. When you launch your hands-on org, switch to Lightning Experience to complete this challenge.

Please try the below steps:

1. You create new Trailhead Playground.
2. Click the Object Manager tab.
4. Click Create | Custom Object in the top right corner.
5. For Label, enter 'Offer'.
6. For Plural Label, enter 'Offers'.
7.Object Name 'Offer'.
8.Record Name 'Offer Name'.
9.Data type 'Auto Number'.
10.Display format 'OF-{0000}'.
11.string number 123.
12. Check the box for Launch New Custom Tab Wizard after saving this custom object.
13. Leave the rest of the values as default and click Save.
14. Select your desired Tab Style and click Next, Next, and Save.
15. Then goto Fields & Relationships in 'Offer' object and click 'New' button in top right corner.
16. In data type select Currency and click next.
17. For Label, enter 'Offer Amount'.
18. Select your desired Tab Style and click Next, Next, and Save.
19. In data type select Date and click next.
20. For Label, enter 'Target Close Date'.
21. Select your desired Tab Style and click Next, Next, and Save.

Please let me know if you have any query.
    
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi
Dippan PatelDippan Patel 
Hi All, 

I am using Source Code Scanner for scanning my code. But it isn't identifying all the issues that come with Salesforce's security report. 

How do I identify all the issues before submitting my app again? 

Thank you. 
Best Answer chosen by Dippan Patel
VinayVinay (Salesforce Developers) 
Hi Dippan,

Try to check below tools that can help you or can you re-try scanning again.

https://security.secure.force.com/security/tools/forcecom/scanner
https://sfcodeclean.herokuapp.com/
https://automationchampion.com/tag/scan-salesforce-code/

Thanks,
RiyajRiyaj 

How do I solve the error

REQUEST_LIMIT_EXCEEDED: TotalRequests Limit exceeded.

 

Riyaj

Best Answer chosen by Admin (Salesforce Developers) 
TheIntegratorTheIntegrator

You can check the API Requests from Setup->Administration Setup->Company Profile->Company Information

 

API Requests, Last 24 Hours , is the number there is exceeding MAX number in paranthesis, you get this error.

 

You either have to wait till that number goes down or purchase more licenses to raise the MAX limit if you expect the usage to always be higher that what your current MAX is.

 

Charlotte Gibson 10Charlotte Gibson 10 
Hi all,

We're thinking about activating Dev Hub in our production org, but I see that once it's been enabled, it can't be disabled. Is there any downside to enabling Dev Hub? Will we still have access to our old sandbox system? There's a lot of in-flight development in the current sandboxes and we don't want to change the way we work yet, we just want to explore Dev Hub and see it working in a practical environment.

Is there anything else we might need to bear in mind when activating Dev Hub? The documentation is a bit patchy on this subject.

Thanks!
Best Answer chosen by Charlotte Gibson 10
Ashish KumarAshish Kumar
Hi Denys,

Since By documentation, Salesforce claims that 
Enabling Dev Hub in a production or business org is completely safe and won’t cause any performance or customer issues. The Dev Hub is comprised of objects with permissions that allow admins to control the level of access available to a user and an org.

But Dev Hub is still in Beta Version. So now the question or let me say the solution is knowing how far you want to go with this. 
If you really want to give it a try in your sandboxes you should go ahead with that. There are no side effects of enabling Dev Hub but you can give it a lil bit more time untill things get settled down to stable releases as there could be more enhancements / modifications down the line, Untill then you can try out the trail period versions to go with the complex situations.

At last "It is your call, If you really want to try it in sandbox then you must Go Ahead There is completely no harm in that."

Best Regards,
Ashish Kr.