Authored by Zishan Razzaq

Thursday, November 29, 2012

How to use 'NOT LIKE' in SALESFORCE SOQL

Hi everyone:
    Business Scenario:
        They would like something update where a field on the record is NOT LIKE "adviser." Or in simplest terms does not contain "Adviser".

Solution for developers in APEX:

APEX will not allow someone to write a simple query such as:
SELECT Name From ABC where id=:Ownerid and Name NOT Like '%adviser%';

So solution is simple:
SELECT NAME From ABC where id=:Ownerid and (NOT Name Like  '%adviser%');

If you are utilizing GROUP By statements here is an example of one:


 AggregateResult[] groupedResults = 
         [SELECT Ownerid,Count(Id) ce 
         FROM Opportunity Where 
         Withdrawn__c = True 
         AND StageName = 'Closed Won' 
         AND Withdrawal_Status__c ='Withdrawn' 
         AND Withdrawn_Date__c = THIS_MONTH  
         AND Ownerid=:id 
         AND (NOT Name Like '%COMP%')
         GROUP BY Ownerid];  

Hope this Helps.
Thanks
Zishan



FLOOR Function in Salesforce Alternative Way

Hi everyone:
    Business Scenario:
       The business would like a formula field that will calculate a number to the nearest lowest 10.
Which means:
If the number is 129 the new number would be 120
If the number is 64 the new number would be 60.

The issue:
   In Salesforce, FLOOR Functionality does not work the same way in Excel.
In Excel you would do something like this to get the top results:
=FLOOR(129,10) which equals 120

In Salesforce, within a formula field it would be:
FLOOR(129) which equals 129, does not work. Do not know why, when Salesforce states the following:
"Returns a number rounded down to the nearest integer."
  

Solution:
   Navigate to the Object that you are placing this formula field in: For me its:
Setup | Create | Object | Test | New Field

Click on Formula Attribute type and Click Next.
For data type click on Number, no decimal if you want you can have it.

The field I will utilize is an existing field within my formula that is a Number(18,0) field already named Net_Enrollment__c.

This is my final formula for the new field I created named Level__c:
IF(Net_Enrollment__c <1 1="1" et_enrollment__c="et_enrollment__c" span="span">

Breakdown of the formula:
I utilize If then statement to conditionalize it to work properly (you do not have to)
I start with:

IF(Net_Enrollment__c<1 0="0" 1="1" be="be" do="do" end="end" greater="greater" if="if" is="is" it="it" math="math" means="means" net_enrollment="net_enrollment" result="result" should="should" span="span" the="the" then="then" which="which" zero="zero">

FLOOR(Net_Enrollment__c) <== which returns me my number


VALUE(RIGHT(TEXT(Net_Enrollment__c), 1) <== Reasons of utilizing TEXT functionality and RIGHT Function

RIGHT Function only works on TEXT and not number data types. 
So I had to convert the Net_Enrollment__c field into a TEXT and then utilize the RIGHT function to get me the Last Digit in my Net Enrollment number and VALUE function returns it to a number

So if I have 129, by using the formula
VALUE(RIGHT(TEXT(129), 1) would give me "9"

So then I take the whole number 129 - 9 = 120
Which is
FLOOR(129)-VALUE(RIGHT(TEXT(129), 1))


Hope this helps and remember always think outside the box.

Thanks
Zishan

 

Tuesday, September 11, 2012

How to copy Record Owner from Cloning Functionality in Salesforce

Hello everyone:

Scenario:
   the business wants to clone an Opportunity record but the Opportunity Owner of the cloned record should follow thru into the new Opportunity record.
Currently, when an user clones any record that user becomes the owner of the new record in Salesforce. URLFOR functionality does not work on this standard field Ownerid, I shall explain more see below for the solution. Also a workflow rule will not work as you would have to specify the Owner of the record.

Solution:
This was tricky but its a solution with less code and utilizing more of the functions within salesforce.
Step 1:
  • On the Opportunity Object:
    • Create a new field:
      • OriginalOwner | OriginalOwner__c | Text(20) | Read Only | Visible to all 
      • The OriginalOwner field would take the cloned Opportunity Record Owner Id and place it in here when an user clicks on the clone button.
      • Notice in the URL the field ID, note it down because you will need that for the next Step. In my case the field ID is "00N50000002kItx".
      • Screenshot:
    • Create a customize Clone Button utilizing the "{!URLFOR" statement:
      • This would be a URL button with the following formula:
        • {!URLFOR( $Action.Opportunity.Clone,Opportunity.Id, [cloneli=1,opp11='Open'])}&00N50000002kItx={!Opportunity.OwnerId}
        • Breakdown of the formula: 
          • {!URLFOR($Action.Opportunity.Clone ==> The URLFOR leads the functionality of the action that would take place. $Action.Object.Functionality determines the Functionality that would happen. In this case, clone functionality for the Object "Opportunity"
          • cloneli=1 ==> This if you like the associated cloned Opportunity Products to follow thru to the new record. If you do not want to then cloneli=0. It will redirect them to select products after clone.
          • opp11='Open' ==> This determines the Stage. You can add more fields by utilizing opp1, 2, 3 and so fourth. Please utilize this website to get the list of standard fields for this formula. How to obtain a field id 
          •  &00N50000002kItx={!Opportunity.OwnerId} ==> This is the new custom field we created and the {!Opportunity.Ownerid} is the field we need to copy over from existing record.
        • Screenshot:
        •   
      •  Now to write a small trigger to do the work after the clone. The button will get you the ownerid for the existing record but it will not update the ownerid. The trigger will.
      •  
        trigger owneridchange on Opportunity (before insert) {
        Opportunity[] a = Trigger.new.clone();
        if(a[0].OriginalOwner__c!=null){
            if (Trigger.new[0].OriginalOwner__c!=null || 
                Trigger.new[0].OriginalOwner__c!='' 
                || Trigger.new[0].OriginalOwner__c<>'')
                {
                    Trigger.new[0].Ownerid=Trigger.new[0].OriginalOwner__c; 
                }
            }
        }
        Screenshot:
         This trigger will only kick off on clone functionality only and 
        not when a new opportunity record is created.
        • Now place the customize clone button on the page layout and go to a record that is not yours and clone the opportunity you will notice that the id gets filled into the new field OriginalOwner and then the trigger will fire off and change the Owner by placing in the id from the OriginalOwner field.
        Hope this helps.
        Watch Me Fight 
        Join My Facebook on Cage Assassin Fight Gear  Like my fan page Cage Assassin Fight Gear  

Thursday, August 23, 2012

How to check code coverage for a NON Developer on Salesforce.com

Hi everyone:
Scenario:
As a Project Manager/Program Coordinator or BA of a company, you do not have the skill set of checking if code meets coverage for salesforce.com best practices or the company's policy on code coverage. Sometimes you must rely on the developer's word on test coverage for Apex Trigger/Controller or Visualforce page.
But it is your responsibility to make sure that test coverage is met, no matter what.

Solution:
Now Salesforce best practices on test classes is always 100% or 95%.
Now salesforce passing grade is 75% but it reccommends 100% or 95% and above.
How does one check to make sure its is meeting your standards or even salesforce standards.

  1. When a developer is showing you a trigger/Apex Controller/VisualForce Page and how it is working, as a Non Developer always asked May I see the test class for this trigger or Apex Controller.
  2. Tips for Non Developer:
    1. If the developer wrote a trigger then the Test Controller must be in a separate class.
    2. The test controller can be in a global class that houses all trigger test scenarios all in one.
    3. If the developer wrote a Apex Controller with a Visual force page then the test controller can be in the same class as the Apex Controller.
    4. The test controller can be in a global class or a separate class as well.
  3. I will show you a couple of scenarios here:
    1. I wrote a Apex Controller that does something and then within the same class i wrote the test scenario. As a Non Developer ask the following:
      1. Is this a Apex Controller?
        1. If yes, please show me the Apex Controller.
        2. Once the developer goes to that screen (not in edit mode) Look for "Run test" button, this means the test controller was written inside the same class.
        3.   
        4. Once you see that ask the developer to click on that button to show you test coverage.
        5. Once the developer does, it will bring up all triggers/controllers everything in your instance but your main concern is the apex controller that he/she is showing you at that time. Look for the name of the Apex Controller.
        6. In this case it is "AccountProcessor"
        7. You can see by the screenshot it is at 100%.
9. Now lets say it was at 0% or 60% when the developer ran it, how can you as a  non developer check what is the developer lacking in his test coverage.
10. I made changes and now I will show you the test class ran and it is at 0% meaning nothing is covered by the controller. So maybe the developer did not do a test class or he/she is not done with test class, and from my previous company that is not the Definition of Done (DOD), it would be back to the drawing board for this person.
11. You as the Non Developer should ask the developer to click on the 0 link as you see in the screenshot:
12. Once he/she clicks on it then it pops open a box and tells you as the developer or non developer in colors red being not covered and blue being covered.
Since my Controller class and test coverage was in the same class, it shows from the main class where the developer showing the functionality of what needs to be presented and in red it shows what have i missed.

This is one of many ways to test out for NON coders or developers of how to ask for test coverage.
Just a few tips:
Test coverage within a Apex Controller always starts with:
"public static testmethod void testControllerName(){" in the above example it is "
public static testmethod void testProcessAccount(){"
 
or if it is in a separate class that it 
would start with the following:

"@isTest(SeeAllData=true)
publicclass TestDataAccessClass {

    // This test accesses an existing account.  
    
    // It also creates and accesses a new test account. 
    
    static testmethod void myTestMethod1() {"
Always check for Run Test on classes. They only appear on 
Apex Classes not on Triggers.
For Triggers the developer must write a 
separate class for test coverage.
 
Thank you

I hope this helped.

Watch Me Fight 
Join My Facebook on Cage Assassin Fight Gear  Like my fan page Cage Assassin Fight Gear  





Monday, July 30, 2012

How to get the latest Case Comment on an Email Template/Alert

Hi everyone:

Recently, I was asked on how would one get the most latest case comment onto a Email Template for an Email alert to go out.
Of course as you know if you place in {!CaseComment.Comments} it will not work. No such thing.
So how do you do get the case comments to show in a email alert.

Solution:
Step 1:
   Create a new field on the Case Object. Name it whatever you want and make sure it is Text Area(Long) as an attribute for the field.

Navigate to:
Setup | App Setup | Customize | Cases | Fields | New Field
Create your new field make sure you select Text Area(Long) for the attribute.




Step 2:
Create a workflow rule off the Case Comment Object to update the new field.
Navigate to:
Setup | App Setup | Create | Workflow Rules & Approvals | Workflow Rules | New Rule



  1. Select Case Comment as the object
  2. Place in the Rule Name
  3. Select the first option:
  4. When a record is created, or when a record is edited and did not previously meet the rule criteria
  5. For criteria:
  6. Case Comment: Body is not equal to null

Click Save & Next.
Under Workflow Action Click on Field Update.
Place in a Name.
Field to Update, Select Case Object and select the new field that was created in Step 1.
Select Use a formula to set the new value
Place in the formula:
 CommentBody 
Click Save.
Click Done and Activate.
Final view of your workflow rule should look like:

Go to an existing case, create a new case comment.
The workflow rule should fire and update the new field.

Step 3:
   Now that we know it is working, lets go to an email template.

Place it the new field from the case object within that email template.

Now if you have an existing workflow rule that does Email alert as an workflow action for that rule, you should receive the latest comments on that email template now.


Thank you
I hope this helped.
Watch Me Fight 
Join My Facebook on Cage Assassin Fight Gear 
Like my fan page Cage Assassin Fight Gear 




Sunday, July 8, 2012

SLA - Service Level Agreement Case Times

Hi:
   Scenario:
     Business wants to know the following:
  1. How many hours a case has been open?
  2. How many days a case been open?
All for SLA - Service Level Agreement amongst the business units who you support.

Solution:
We can utilize many methods, I will list out number of hours a case been open and number of days a case been open.

"DATEVALUE" <== a formula method that "Creates a date from its datetime or text representation"

To get the number of hours a case been open, we will not utilize "DateValue" but just common mathematical formula.
Let's say the 2 fields we are utilizing are CreatedDate and LastModifiedDate

Knowing there are 24 hours in a day worldwide... lets use that:

(24* (LastModifiedDate - CreatedDate  ))

 This formula will give you the number of hours between the 2 fields.

The Number of Days a Case been open:

Let's say you are utilizing a formula field which based on the type of case that comes in counts off the number of days SLA should meet for that case.

Lets say for "User Profile Change" type of case that comes in, the number of days to get back to the user is 1 day.

Field: SLA Expectations | SLA_Expectations__c | Attribute - Number (2,0) | Formula

Formula is:
IF(Type='User Profile Change',1,0)

Now we will use that field to figure out if the SLA was met or was it over 1 day.

Create another formula field named: SLA | SLA__c | Attribute - Number (2,0)

Formula is:
(DATEVALUE (CreatedDate) + SLA_Expectations__c) - TODAY()

This shall give you the result you need to figure out SLA which you can then set up an escalation rule to send out an email to the manager of operations let say that SLA was not met.

Great for reporting purposes as well :)

Thank you everyone
Hope this helped
Zishan

Wednesday, June 20, 2012

Queues & Supported Objects

Hi:
   A very quick Blog on Queues and Supported Objects.

Scenario:
   Admins have to create queues that are related to an object. This object must have its own queues to work.

Issue:
   The object has a Master-Detail relationship field on it.

Solution:
   Let say you have 2 objects:
Object 1: "ABC"
Object 2: "DEF"

On Object 2: "DEF" you create a Master-Detail Relationship field to ABC.
When you go to create a queue for the object "DEF", the Supported Object WILL NOT come up in the "Available Object" list. Supported Object is a required control when creating a Queue.

The reason of why "DEF" object will not show within the list of Supported Objects is because of the Master Detail Relationship Field on the object itself.
This makes this object a detail to the parent and as we know detail objects takes the parent traits, such as Sharing Rules.
In this particular Case it does not get the same privileges as the Master for Queues.

Solution:
   If a queue is really needed for this object, change the master-detail relationship to a Lookup and you can now create custom queues for this object.

Some tips on creating Queues:

  • Click Your Name | Setup | Administration Setup | Manage Users | Queues.

 Click New and start creating your queue.
Thank you
Zishan
Watch Me Fight 
Join My Facebook on Cage Assassin Fight Gear 
Like my fan page Cage Assassin Fight Gear