^ Click Here
Showing posts with label contact. Show all posts
Showing posts with label contact. Show all posts

Saturday, January 28, 2012

Showing Opportunities for each Contact (parent - child) through Map without using Wrapper Class

We can show map from controller on the visualforce page, We also can put one map inside another map or in other words nested map.

With the help of these two factors, I successfully showed the contact and corresponding opportunities without using the wrapper classes. Though it put some restriction however for
the purpose of showing all the opportunities corresponding to each Contact (or any parent - child relationship) it works fine.

The process is simple -
 -I created a map of Contact as key and another map of Opportunity with id as value say A.
 -I used a query which brings all the opportunities for Contacts.
 -Now in a loop get the list of opportunities for each Contact.
 -After checking if there are Opportunities put those Opportunities in a map with id say B.
 -And lastly the Contact and the map B was put into map A.



Visualforce Page :-

 <apex:page controller="MapClass" action="{!getValues}">
<apex:pageblock >
<apex:pageBlockTable value="{!checkMap}" var="con">
    <apex:column value="{!con.Name}"/>
    <apex:column headerValue="Opportunities">
        <apex:dataList value="{!checkMap[con]}" var="opp">
        <apex:outputField value="{!checkMap[con][opp].Name}"/>
        </apex:dataList>
    </apex:column>
    <apex:column value="{!con.Account.Name}"/>
    <apex:column value="{!con.createddate}"/>
   
</apex:pageBlockTable>
</apex:pageblock>
</apex:page>



Apex Class :-

public class MapClass{
  public transient Map<Contact,Map<id,Opportunity>> checkMap{get; set;}
  public void getValues(){
  checkMap  = new Map<Contact,Map<id,Opportunity>>();
  for(Contact s : Database.query('select id, name, Account.name, owner.Name,    createddate, (select id, name from Opportunities) from Contact')){
      List<Opportunity> opLi = s.getSobjects('Opportunities');
      map<id,Opportunity> opMap = new map<id,Opportunity>();
      if(opLi != null){
      for(Opportunity op: opLi){
      opMap.put(op.id,op);   
      }
      }
      checkMap.put(s,opMap);
  }   
}
}

 Last but not the least you can stretch this concept to look what else can be done. feel free to add on it.



Wednesday, June 29, 2011

Understanding the CRM workflow Account, Contact, opportunity and Leads

Disclaimer : The ideas are of my own and they might not be technically correct, It's mostly for understanding and not to be relied upon.
Q:What is an Account??

Account is actually an entity with which the concerned is having Business, It could be A company, A firm, A small group.

Q:What is a Contact

Contact is usually a person with whom we are dealing with, A contact is attached to and represent an Account.

Q:What is an Opportunity?

Opportunity is the the available business prospects for the concerned.

Q:What is a Lead?

A lead is one entity which can turn out into a usually long term business Activity. In normal business process a lead when confirmed is converted into an
Account, a Contact and an opportunity.

Now let's understand it by an example.

Suppose I have a business of Stationary products (Paper, pens, pencils etc.). Currently I am providing stationary items in two companies A and B. The person
A-first from the company A asked me for a consignment for his team-members. Also another person A-second from the same company A calls me for another
consignment for the staffs who works under him.

Now here the company A and B are the two Accounts and the person A-first and A-second are the contacts who belongs to the Account A. the consignments which
both the contacts asked for are the two Opportunities.

Now one fine day a friend of mine give me the phone number of a person C-first from the Company C who is probably looking for someone who can provide a
huge consignment.

here I got a Lead with whom I can have a business deal.

I called him and after much haggling I got the order for one more consignment, Then the lead is converted into an Account(C), a contact(C-first) and an
Opportunity (the order for consignment).

In 2 days I provided the consignment for A-first and got the payment Hence the Opportunity from A-first is Closed But I still have two open
opportunities
(from A-second and C-first).

These were the very basic of business process flow in CRM. I hope it would have been useful in clarifying the ideas