Articles by "How to-in Salesforce"




how to hide approve/Reject links in the home page?


We can hide the approve/Reject links, If we want to restrict the user to approve the record from home page.
If we have implemented logic for the approval process (customized approval process) for that we have to override the all the links (Approve links) and buttons in the details page.
How we can restrict the user to approve from home page.
Steps:
  • Create a StaticResouce “StaticResourceName” upload a JS file. (File extension should be .JS)
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$(“table.list td.actionColumn”).html(”);
});
  • go to Setup > Home > Custom Links
  • create a new link call it “HideApproveLink”
  • Behaviour = “Execute JavaScript”
  • Content Source = “Onclick JavaScript”
  • at the body enter {!REQUIRESCRIPT(“/resource/StaticResourceName”)}
  • go to Setup > Home > Home Page Components à New
  • call it “HideApproveLink-Box”
  • pick type “Links”
  • click next
  • pick “HideApprovalLink” we created above à save
  • got to Setup > Home > Home Page Layouts
  • add “HideApprovalLink-box” to your layout
  • Click on home Tab you can see the Approva/Reject links are hidden in the page.
We can create a home page component and written script to hide the links. But from summer ‘15 we don’t have the capability to write the script in home page component.

Very often  it is observed that after creating the custom object which is related to other object, developers get surprise that where is the report option for my object with that custom object.
When creating a custom object, you can use the “Relationships” section to define relationships between this new object and other objects. For example let’s say you have a new object called “Expense” that you want to attach to an “Account“.
When you check the “enable reports” box and you go to the report wizard where you choose the type of data you want to report on,  after the standard sections like “Accounts & Contacts”,  “Opportunities”,  “Administrative Reports”  you’ll see a new section for “Other Reports”. When you choose that section you’ll see an “Expenses” report type only.
However, if you want to see a report linking “Expenses with Accounts” see below:
  1. Ensure that the relationship between accounts and expenses is a master-detail relationship.
  2. Look for the “Accounts with Expenses” report in the Accounts & Contacts section, not the “Other Reports” section because Account is the Parent object.
Lets take the example of our previously created application of the “Student and Courses“, in which course is the parent object.
As the parent object is not the standard object, in this case the report will be in the “Other reports” section as shown in below image.
Report of custom object with related object in Salesforce
Report of custom object with related object in Salesforce
Hi hope, this article will help to find the cause and solution that where is the custom objects report in salesforce.

How to create Roll-Up Summary fields in Salesforce : In this training tutorial we are going to learn what is Roll-Up Summary field in salesforce, Characteristic of Roll-Up Summary field and how to create Roll-Up Summary field in Salesforce.
Roll-Up Summary field : Roll-Up Summary field in salesforce calculates values from a set of related records.
Roll-Up Summary field can do the following functions.
  • Count : It calculates the total number of related records.
  • Sum : It totals the values of selected fields.
  • Min : Displays lowest value.
  • Max : Displays the highest value.
Characteristics of Roll-Up Summary.
  1. Roll-Up Summary field can be created only in a object which is referred as a object with a master detailed relationship field.
  2. Roll-Up Summary field can only created for Master-detail Relationship.
  3. Roll-Up Summary field can not be  created for Lookup Relationship.
  4. It Derives the data from child Object.
  5. We can’t change field type of a field that we reference in a roll-up summary field.
  6. Auto numbers are not available here.
  7. Roll-Up Summary fields are not available for mapping lead fields of converted fields.

How to create Roll-Up Summary Fields in Salesforce.

Here we are going to create Roll-Up Summary field in Custom object called “College”. Totally we are going to create Four Roll-Up Summary fields which are Total number of Students from Student Object, Total number of Employes from Employs Object, Total Fee Paid from Student Object and finally Total Courses from Course Object.
Step1 : Go to Detailed view of the object then go to Custom fields and Relationship section.
Custom fields and Relationship section => New => Roll-Up Summary.

Now enter all the details like Field Label and Field name and Select Next.

Enter Summarized object from picklist, Select Roll-Up Types select Next and finally Save it.

Below is the Roll-Up Summary field created to sum all fees paid by all students in a college.

Like wise create remaining 3 roll-up summary fields and also create some records in the objects.

A trigger is an Apex script that executes before or after specific data manipulation language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.

Triggers are stored as metadata in Salesforce.com. A list of all triggers in your organization is located at Setup | Develop | Apex Triggers. In addition to this list, triggers are associated and stored with specific objects.
To define a trigger:
  1. For a standard object, click Setup | Customize, click the name of the object, then click Triggers.For a custom object, click Setup | Create | Objects and click the name of the object.For campaign members, click Setup | Customize | Campaigns | Campaign Member | Triggers.For case comments, click Setup | Cases | Case CommentsTriggers.
    For email messages, click Setup | Cases | Email Messages | Triggers.
  2. In the Triggers related list, click New.
  3. Click Version Settings to specify the version of Apex and the API used with this trigger. If your organization has installed managed packages from the AppExchange, you can also specify which version of each managed package to use with this trigger. Generally, you should use the default values for all versions. This associates the trigger with the most recent version of Apex and the API, as well as each managed package. You can specify an older version of a managed package if you want to access components or functionality that differs from the most recent package version. You can specify an older version of Apex and the API to maintain specific behavior.
  4. Select the Is Active checkbox if the trigger should be compiled and enabled. Leave this checkbox deselected if you only want to store the script in your organization’s metadata. This checkbox is selected by default.
  5. In the Body text box, enter the Apex for the trigger. A single trigger can be up to “1 million” characters in length.
To define a trigger, use the following syntax:
trigger triggerName on ObjectName (trigger_events) {
   code_block
}
where trigger_events can be a comma-separated list of one or more of the following events:
  • before insert
  • before update
  • before delete
  • after insert
  • after update
  • after delete
  • after undelete
So, lets start with creating trigger.
I want that duplicate student should not be created on the basis of Email id. we can achieve this by other way also, like during creation of email field, we can specify it as unique field.
Open eclipse and right click on salesforce project and select Create new Trigger, as shown in below image
Creating Trigger in Salesforce using force.com IDE
Creating Trigger in Salesforce using force.com IDE
As you can see, to create trigger we have to select the Apex version and operations in wizard.
During Trigger creation, keep in mind that it may be required in bulk operations so governor limit may be problem.
So instead of getting query for all triggers individually, I created an array and after that created a set of email entered for all records, and loop through all records invidually and checked for duplicity.
Only one SOQL is fired instead of all triggers individually and thus can work for bulk insert.
1trigger DuplicateStudentCheck on Student__c (before insert) {
2
3       //Get all Student__c related to the incoming Student records in a single SOQL query.
4       Student__c[] studentsList = Trigger.new;
5       Set emailSet = new Set();
6       for(Student__c s : studentsList)
7       {
8        emailSet.add(s.Email__c);
9       }
10
11       //Get list of duplicate Students
12       List duplicateStudentList = [Select s.Name, s.Email__c From Student__c s
13where s.Email__c IN :emailSet];
14
15       Set duplicateEmailIds = new Set();
16
17       for(Student__c s : duplicateStudentList)
18       {
19        duplicateEmailIds.add(s.Email__c);
20       }
21
22       for(Student__c s : studentsList)
23       {
24            if(duplicateEmailIds.contains(s.Email__c))
25            {
26                s.Email__c.addError('Record already exist with same email Id');
27            }
28       }
29}
Note: You can add, edit, or delete Apex using the Salesforce.com user interface only in a Developer Edition organization, a Salesforce.com Enterprise Edition trial organization, or sandbox organization. In a Salesforce.com production organization, you can only make changes to Apex by using the Metadata API deploy call, the Force.com IDE, or theForce.com Migration Tool. The Force.com IDE and Force.com Migration Tool are free resources provided by salesforce.com to support its users and partners, but are not considered part of our Services for purposes of the salesforce.com Master Subscription Agreement.
Test Cases in Salesforce :

Test case integral part of code developement.
  • You must have at least 75% of your Apex scripts covered by unit tests to deploy your scripts to production environments. In addition, all triggers should have some test coverage.
  • Salesforce.com recommends that you have 100% of your scripts covered by unit tests, where possible.
  • Calls to
    System.debug are not counted as part of Apex code coverage in unit tests.
So, here we are going to create Test Case for trigger which we have written:
1@isTest
2private class TestTriggers {
3
4    static testMethod void myUnitTest() {
5        Student__c s = new Student__c();
6        s.Name = 'Om Test';
7        s.l_Name__c = 'LastName';
8
9        Course__c c = new Course__c();
10        c.Name = 'SFDC';
11        c.Fees__c = 2000;
12        insert c;
13
14        s.Course__c = c.Id;
15        s.Installment_1__c = 2000;
16        s.Email__c = 'admin@shivasoft.in';
17        try
18        {
19            insert s;
20        }
21        catch(System.DMLException e)
22        {
23            System.assert(e.getMessage().contains('Record already exist with same email Id'));
24        }
25    }
26}
To run the test case from Eclipse, right click on test class as shown in below image:
Run Test Case using Eclipse in Salesforce
Run Test Case using Eclipse in Salesforce
The output of the test case, Test coverage result:
Test Coverage result Eclipse in Salesforce
Test Coverage result Eclipse in Salesforce
Run test cases from salesforce.com browser:
click Setup | Develop | Apex Classes, click the name of the class, then click Run Test. If your class calls another class or causes a trigger to execute, those Apex scripts are included in the total amount used for calculating the percentage of code covered.
To run all the unit tests in your organization, click Setup | Develop | Apex Classes, then click Run All Tests.

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget