You are on page 1of 20

test class - trigger - addError method

Hello, I wrote a trigger to check if the url = 'https://sig-cb--Full.cs88.my.salesforce.com' and the profile of
the current user is a specific profile (SIG-FSM-Super User) and if so the trigger shows an error message
and also an image which I included in the addError function, it looks like this:

view source

print?

01 trigger ContactCreationForServiceMaxUsers on Contact (Before insert) {

02     

03        String baseURL = String.valueof(URL.getSalesforceBaseUrl());

04        

05        system.debug('<<baseURL>>' + baseURL);

06        Boolean isBaseURL = baseURL.contains('https://sig-cb--Full.cs88.my.salesforce.com');

07        System.debug(' >> String.valueof(URL.getSalesforceBaseUrl()) >>'+baseURL );

08        User currentUser = [SELECT Id, Profile.Name FROM USER WHERE Id =:UserInfo.getUserId()];

09        

       Contact c = new
10
Contact();

11        

12        System.debug(' >> isBaseURL >>'+isBaseURL );

13        System.debug(' >> currentUser.Profile.Name>>'+currentUser.Profile.Name );

14     

15      for(Contact c : Trigger.New){
16           if(isBaseURL == TRUE  && currentUser.Profile.Name == 'SIG-FSM-Super User'){

           c.addError(' <p style="color:red; font-size: 20px;">Service contact creation is only allowed from
“Account” tab using the blue button “Create Contact” after selecting a account”</p><img
17
id="theImage" src="https://sig-cb--full--c.cs88.content.force.com/servlet/servlet.FileDownload?
file=0159E0000002tNp" width="850px" height="100px" alt="Description of image here"/> ', false);

18           }

     
19
}

20 }

Can anyone help me with how to build the test class for the trigger? At least theoretical.

1. First I need to create a contact


2. I need to create a user with a profile = 'super-user'
3. somehow i need to check the addError function..

Something like this...

see more...

Sarah Paulson

March 30, 2020

Reply

Like

Follow

0
Continue reading or reply

Savita Singh

0 replies

I have saved password in custom object ,now i have to write a batch apex to auto check for passwords of
custom objects.

I have saved password in custom object ,now i have to write a batch apex to auto check for passwords
of records 

see more...

Savita Singh

March 30, 2020

Reply

Like

Follow

Continue reading or reply

Rishabh Bhardwaj
0 replies

Mapping user_id_token in managed package usage summary report with an actual user

I have been working on salesforce API integration for my org which deals with some use cases involving
usage and license reporting. I have been exploring managed package usage summary data for last
couple of days, which basically gives me a high level metric of how managed package are being used in
my org.
The data that is returned right now does not map the usage summary with each user ID, but returns
back a user_id_token which according to the documentation
"The hashed token representing the ID of the user who accessed the custom object. The ID persists over
time, and across any packages that the user interacts with.
The user ID token starts with the prefix 005-"

 Here is the link on documentation.


https://developer.salesforce.com/docs/atlas.en-
us.packagingGuide.meta/packagingGuide/app_analytics_custom_object_summaries.htm

Looking for help on how I can map this user_id_token with the actual user.

Thanks

see more...

Rishabh Bhardwaj

March 29, 2020

Reply

Like

·
Follow

Continue reading or reply

MUSFAR KT 6

1 replies

how to use field set in lightning component for form edit and view

how to use fieldset in lightning component for creation of  form edit and view in the account object

see more...

MUSFAR KT 6

March 29, 2020

Reply

Like

Follow

0
Continue reading or reply

Shubham Khajjepawar

0 replies

How to invoke workflow rule through apex trigger

Shubham Khajjepawar

March 29, 2020

Reply

Like

Follow

Continue reading or reply

srikanth yeturu 5

3 replies

 
2.Display list of accounts in a block with checkbox, if the user selects the accounts and click on "Show
Contacts " button the selected account related contacts should display in the pageBlocktable beside the
accounts list block

 Right side block should display Account name as a heading and its related contacts under that account
make those changes.
 page block 2 is not working ...?

// class
public class AccountSelectClassController {

    public list<wrapaccount> wrapaccountList { get; set; }


    public list<account> selectedAccounts{get;set;}     
    public list<id> selectedrecordsIds{get;set;}
    public list<Contact> records{get;set;}
    public list<Account> names{get;set;}

    public AccountSelectClassController ()
  {
      
       if(wrapaccountList ==null)
      {
                 wrapaccountList =new list<wrapaccount>();
                 for(account a:[select id,name from account limit 10])
                 {
                 wrapaccountlist.add(new wrapaccount(a));
        
         }
      }
     }
    
     public void ProcessSelected()
     {
       selectedAccounts=new list<account>();
       selectedrecordsIds =new list<id>();
       records =new List<Contact>();
       names =new List<Account>();
       for(wrapaccount wrapobj:wrapaccountlist)
     {
              if(wrapobj.isSelected==true)
        {
                   selectedAccounts.add(wrapobj.accn);
                }   
     }
          
          for(Account abc:selectedAccounts)
     {
            selectedrecordsIds.add(abc.id);   
     }
                names = [SELECT Name,label__c FROM ACCOUNT WHERE Id IN :selectedrecordsIds];
     
             records = [SELECT Name FROM Contact WHERE AccountId IN : selectedrecordsIds];
        
             System.debug('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'+records);

          System.debug('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'+selectedrecordsIds);
            System.debug('ccccccccccccccccccccccccccccccccccccccc'+names);

   }
      
  
  
   public class wrapaccount
   {
    
    public account accn{get;set;}
    public boolean isSelected{get;set;}
   
       public wrapaccount(account a)
       {
   
         accn=a;
         isselected=false;
       }
   }
}

vf pafe :-
<apex:page sidebar="false" controller="AccountSelectClassController">
    
    
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
        }
      }
    }
    
    </script>
 <apex:form >
    
     <apex:pageBlock id="block2">
    
       <apex:pageBlockSection columns="2">
         <apex:pageBlockTable value="{!wrapaccountList}" var="waccl">
            
           <apex:column >
              <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
            <apex:inputCheckbox value="{!waccl.isSelected}" id="InputId"/>
           </apex:column>
            
            <apex:column value="{!waccl.accn.name}"/>
         </apex:pageBlockTable>
           <apex:pageBlock >
      
  
          <apex:pageBlockTable value="{!names}" var="aaa">
             <apex:column value="{!aaa.Name}" headerValue="name"/>

                                
        
              <apex:pageBlockTable value="{!records}" var="qqq">
                  <apex:column value="{!qqq.name}"/>
              </apex:pageBlockTable>
              </apex:pageBlockTable>

           </apex:pageBlock>
       </apex:pageBlockSection>
     
         <apex:pageBlockButtons location="bottom">
          <apex:commandButton action="{!ProcessSelected}" value="Show Selected Contacts"
reRender="block2"/>
        </apex:pageBlockButtons>
     
     </apex:pageBlock>
    
   </apex:form>
</apex:page>

see more...

srikanth yeturu 5

March 29, 2020

Reply

Like

Follow

Continue reading or reply

Muoi T

0 replies

Improve Data Quality for Your Sales and Support Teams> Create a Validation Rule > "Error message is
not displayed above 'Close Date' field. Check the instructions."

I have this message on 

Learn Admin Essentials in Lightning Experience >


Improve Data Quality for Your Sales and Support Teams >
Create a Validation Rule Challenge
"Error message is not displayed above 'Close Date' field. Check the instructions."

What should I do? Thanks for your help!

see more...

Muoi T

March 29, 2020

Reply

Like

Follow

Continue reading or reply

Yogesh Biyani

1 replies

Bulk API 1.0 insert related object using external id

How I insert a related object using the external id field on the parent object?

I have a custom parent object License__c and related object Activation__c which have a
Related_License__c lookup field to the License__c object and the relations ship name is License
Activations.
License__c has l_id__c external id field. I would like to import the Activation__c object using the l_id__c
field so that the parent-child relationship is automatically created.

This works using the data import wizard but fails when I try to import use the Bulk Api 1.0 

Here is the sample CVS file 

Activation_Id__c,License_Activations__r.l_id__c 
9249,1665029 
9250,1665029 

see more...

Yogesh Biyani

March 29, 2020

Reply

Like

Follow

Continue reading or reply

AMRITA P Panda

0 replies
 

How to use the list from apex class in the helper?

Apex class:-
  @AuraEnabled
    public static List < sObject > fetchLookUpValues(String searchKeyWord, String ObjectName,
List<sObject> ExcludeitemsList, String UserId) 
  {
        try{
            
            List <Group > Careagentgroup;
            List <Group > noncareagentgroup;
            String searchKey = '' + searchKeyWord + '%';
            List <String> lstOfGroupIds = new List <String> ();
            List <Group> lstOfQueue;
            List <GroupMember> lstOfSubGroupId;
            Set<id> idGroup = new Set<id>();
            lstOfSubGroupId =  [SELECT GroupId from GroupMember WHERE UserOrGroupId=: UserId LIMIT
500];
            if(lstOfSubGroupId.size()>0){
            for(GroupMember gm : lstOfSubGroupId){
                idGroup.add(gm.GroupId); 
      }
      }
            lstOfQueue =  [SELECT Id from Group WHERE Id IN (Select Groupid from GroupMember where
userOrGroupId in : idGroup) LIMIT 500];
            if(lstOfQueue.size()>0){
            for(Group q : lstOfQueue){
                lstOfGroupIds.add(q.Id);
      }
      }
            
            List<string> lstExcludeitems = new List<string>();
            for(sObject item : ExcludeitemsList ){
                lstExcludeitems.add(item.id);
      }
            Careagentgroup=[select name from group where name like'care%' AND Name LIKE: searchKey
AND Id NOT IN : lstExcludeitems AND Id NOT IN : lstOfGroupIds];
            noncareagentgroup=[select name from group where Name LIKE: searchKey AND (NOT name LIKE
'care%') AND Id NOT IN : lstExcludeitems AND Id NOT IN : lstOfGroupIds];
            list<user> u=[select id,name,profile.name from user where id=:UserId];
            List <sObject> returnList = new List <sObject> ();    

                if(u[0].profile.name=='Service Care Agent'){


                    for (sObject obj: Careagentgroup) {
                                returnList.add(obj);
                            }
                }
                else{
                    for (sObject obj: noncareagentgroup) {
                                returnList.add(obj);
                            }                    
                    }
                return returnList;    
        }
        catch(Exception e){
                
            System.debug('The following exception has occurred: ' + e.getMessage());
            return null;
        }
  }

helper :-

({
     searchHelper : function(component,event,getInputkeyWord,UserId) {
        var action = component.get("c.fetchLookUpValues");
        action.setParams({
            'searchKeyWord': getInputkeyWord,
            'ObjectName' : component.get("v.objectAPIName"),
            'ExcludeitemsList' : component.get("v.lstSelectedRecords"),
            'UserId' : UserId
        });
        
        //String searchKeyWord, String ObjectName, List<sObject> ExcludeitemsList, List<Group> lstofgrp
        action.setCallback(this, function(response) {
            $A.util.removeClass(component.find("mySpinner"), "slds-show");
            var state = response.getState();
            console.log("state" + state);
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                  //console.log("storeResponse-----" +storeResponse[0].Name );
                if (storeResponse.length == 0) {
                    component.set("v.Message", 'No records found');
                } 
      
                else {
                    component.set("v.Message", '');
        }
                component.set("v.listOfSearchRecords", storeResponse); 

      }
            
        });
        $A.enqueueAction(action);
    },
})

Question is :- I want to take the values present in the "returnlist" from apex class and compare it in the
helper and based on the comparision will print the message as " not authorized".

see more...

AMRITA P Panda

March 29, 2020

Reply

Like

Follow

Continue reading or reply

PG 110

0 replies
 

need to access the logged in user info inside a global variable which can be accessed by javascript.

One of our end customers has a community. We need to access the logged in user info inside a global
variable which can be accessed by javascript. Can this be done? Something along the lines of a hidden
variable which can be stored on the page and accessed in javascript. 
Has anyone done this? AN example With and without requiring new code will be super helpful. 
Any one has any pointers or articles will be helpful too. Thanks in advance.

see more...

PG 110

March 29, 2020

Reply

Like

Follow

Continue reading or reply

Sarah Paulson

0 replies

test class - trigger - addError method


Hello, I wrote a trigger to check if the url = 'https://sig-cb--Full.cs88.my.salesforce.com' and the profile of
the current user is a specific profile (SIG-FSM-Super User) and if so the trigger shows an error message
and also an image which I included in the addError function, it looks like this:

trigger ContactCreationForServiceMaxUsers on Contact (Before insert) {

String baseURL = String.valueof(URL.getSalesforceBaseUrl());

system.debug('<<baseURL>>' + baseURL);

Boolean isBaseURL = baseURL.contains('https://sig-cb--Full.cs88.my.salesforce.com');

System.debug(' >> String.valueof(URL.getSalesforceBaseUrl()) >>'+baseURL );

User currentUser = [SELECT Id, Profile.Name FROM USER WHERE Id =:UserInfo.getUserId()];

Contact c = new Contact();

System.debug(' >> isBaseURL >>'+isBaseURL );

System.debug(' >> currentUser.Profile.Name>>'+currentUser.Profile.Name );

for(Contact c : Trigger.New){

if(isBaseURL == TRUE && currentUser.Profile.Name == 'SIG-FSM-Super User'){

c.addError(' <p style="color:red; font-size: 20px;">Service contact creation is only allowed from
“Account” tab using the blue button “Create Contact” after selecting a account”</p><img id="theImage"
src="https://sig-cb--full--c.cs88.content.force.com/servlet/servlet.FileDownload?
file=0159E0000002tNp" width="850px" height="100px" alt="Description of image here"/> ', false);

Can anyone help me with how to build the test class for the trigger? At least theoretical.

1. First I need to create a contact


2. I need to create a user with a profile = 'super-user'
3. somehow i need to check the addError function..

Something like this...


see more...

Sarah Paulson

March 30, 2020

Reply

Like

Follow

Continue reading or reply

Savita Singh

0 replies

I have saved password in custom object ,now i have to write a batch apex to auto check for passwords of
custom objects.

I have saved password in custom object ,now i have to write a batch apex to auto check for passwords
of records 

see more...

Savita Singh

March 30, 2020

·
Reply

Like

Follow

Continue reading or reply

Rishabh Bhardwaj

0 replies

Mapping user_id_token in managed package usage summary report with an actual user

I have been working on salesforce API integration for my org which deals with some use cases involving
usage and license reporting. I have been exploring managed package usage summary data for last
couple of days, which basically gives me a high level metric of how managed package are being used in
my org.
The data that is returned right now does not map the usage summary with each user ID, but returns
back a user_id_token which according to the documentation
"The hashed token representing the ID of the user who accessed the custom object. The ID persists over
time, and across any packages that the user interacts with.
The user ID token starts with the prefix 005-"

 Here is the link on documentation.


https://developer.salesforce.com/docs/atlas.en-
us.packagingGuide.meta/packagingGuide/app_analytics_custom_object_summaries.htm

Looking for help on how I can map this user_id_token with the actual user.

Thanks

see more...
Rishabh Bhardwaj

March 29, 2020

Reply

Like

You might also like