Wednesday, May 20, 2015

Sneak into Writing Test Classes

On a sunny day , working from my apartment Balcony :
working on test classes project i have to struggle for code coverage,Though it is said to be simple task but some times found people juggling with obtaining coverage .i would like to introduce some challenges that every developer faces:

a) if a object have many lookup and some complex trigger/classes structure may hit too many soql
b)After trying so many combination of conditional block  can lead  no +ve in code coverage.
c)May hit developer time span to write test class leading migration activity delay
d)In efficient code coverage without writing unit  test for  +ve and -ve scenario.
e) Improper Exceptions Handling


Here are ways to handle:

a/b) If object may have multiple lookups and complex structure with triggers/classe :
-do not provide all lookup at a time since lookup population may be distributed as business

for example : If custom object "aa__c" have lookup let suppose account/contact/case/....it is possible aa__c record may have account/contact for some business and for other business account with other lookup.

So Break single method in multiple as in 1 : populate two lookup or as per your convience in 2: other two....this should be staritgey .

Cover method code in start test/stop test

b) if calling Class method from trigger: in a complex situation while writing test if method not calling -->call that method within testclass while passing argument.

trigger
{
class_abc.pqr(trigger.new);
}

public class class_abc
{
pqr(list<sobject> lst)
}

@test
{
method1()
{
insert record;
list.add(record); // add to list
classinstance.pqr(list);
}
}

c/d)Include if /else condition : set up data for + and - coverage
e)There may be scenarion you are getting last line exception when executing unit test  and after juggling many hours not fixing it up and got no solution in that case use try-catch block.
f) You can call trigger-class methods in test class by passing parameters/argument if any.all method in class will be cover.

Thanks





Monday, April 20, 2015

Issue with RestUrl Salesforce

Point Regarding Rest Api Salesforce :


When sending rest request to the resturl , Make sure added the name space in Url.
if Name space not provided will throw the error :
[
    {
        "errorCode": "NOT_FOUND",
        "message": "Could not find a match for URL /Account/0019000001InXHd"
    }
]

So the request Url should be like :when Class is exposed as restresource:
     https://Instance.salesforce.com/services/apexrest/icoder/Account/AccountId
     https://Instance.salesforce.com/services/apexrest/namespace/Account/AccountId

Saturday, April 18, 2015

Email-to-Case Salesforce Engine

Email-to-Case functionality works like  success factor for company where customer can connect efficiently with quick interaction via email.
Customer can create ticket/cases while sending email to company support process  mail , ticket/inquiries can direct be placed to customer account in CRM.

It is process by which customer query can be resolved via interaction through email.

Process Flow Email-to Case SFDC:

  • When Customer send any  product malfunction/outage/breakdown  inquiries through email , Salesforce automatically logged a case and link the Account(Customer) and Contact(found by Email) to Case.
Feature can be setup:

Customize->Case->Email-to-case

  • Enable Email to Case
  • Enable Notify Case Owner on new Email

When sending Email from Case : Thread Id in subject & In Body

Thread Id : An id which is used for communication to & from for case to identify case related email thread.
if Customer reply to the mail having thread id in subject and in body, Email will automatically be linked to the Case.
All the email activities gone through this email(having ThreadID) communication will be recorded on case.

In Section Routing Address : 
Provide  support@company domain  in email,click on save--> an email notification will be received on "support@company domain"-->verify link-->
there will be email service address.

Set Email FWD setting on "support@company domain" -->Enter Email Service address (Recieived in  Section Routing Address).

Here its all done.

So when a customer send email @support it will forward email to Salesforce Email Service Address and Salesforce Engine eventually create a Case.

Thursday, April 2, 2015

Google Map : Simplifying Map In Visualforce

Salesforce spring15 release which bring some cheers to developer where implementing requirement
related to google map.

As earlier a lot of work needs to be done like div componant to create canvas for map binding dynamically data to marker ,use of javascript url(Map api)  on VF  to show location specific data.

Now we have quick solution to show google map on Vf using simple <apex:> Tag.We have <apex:map> component to show  a map canvas on Visualforce page.Using  <apex:map> and <apex:mapMarker> we can easily implement location on map.

There are certain attribute that need to be set while displaying map.
<apex:map>
Attriute : mapType
The type of map to display. Must be one of the following:

  • hybrid
  • roadmap
  • satellite



height: sets size
width : sets size

<apex:MapMarker>
position Object Specifies the location of the marker.

Code Snippet:

<apex:map width="600px" height="400px" mapType="roadmap"  center="Account Billing address">
   <apex:mapMarker title="{! contact.Name }"
     position="{!contact.MailingStreet},{!contact.MailingCity},{!contact.MailingState}"/>
</apex:map>

Note : Enable Map setting:
Customize-->Map and Location-->enable



http://docs.releasenotes.salesforce.com/en-us/spring15/release-notes/rn_vf_mapping_components.htm

Sunday, July 8, 2012

Rollup Summary In Validation: Avoid Trigger

There are certain simple scenarios where we think we have to write code and then again writing apex , test class and coverage..a lot hectic things.But if we thinks Configuration Power so many of such things can be avoided and can be handeled easily.
Here i am disscusssig some configuration Tips though simple but very efficient .

If You want to Validate Parent Object on behalf of Child Records.
Approach : Avoid Trigger
Create RollupSummary ,Set Filter Criteria On Rollup Field.
Use RollUp Summary In Validation Rule on Parent
Its Done.


Use  apex Trigger only when there is complex Scenarion.



Regards
Clouder
Simplifying enterprise architecture







Saturday, February 11, 2012

Hi ,
This is in regarding script statement,Script statement are nothing but Executable Line in Code .

Example :

1):Conditional Statement
2)Assignment
3)For loop
4)While
5)Transaction Statement

Example:


If(Name =='Mohit')
{
Statement 1;
}
Else
{
Statement 2;
}

In This Code Script Statement is 1 since it is conditional Either Statement 1 or Either 2 Statement will Execute.



Some more Illustration for Optimizing Script Statement..Write Effective code

List<account> lstact=[select id ,name from account where name='abc'];
for(integer i=0;i<lstact.size();i++)
{
string str=lstact[i].name;
}
 Result: Please Note Down Number of script Statement: 3











Code Listing 2: Please Note Down here Number of Script Statement :1

for(account varact:[select id ,name from account where name='abc'])
{
string str=varact.name;
}













Try To reduce : Number of Script Statement.Effective Code writing.

If you feel unappropriate please say,this is my first blog for any mistake i apologize.