Showing posts with label CRM. Show all posts
Showing posts with label CRM. Show all posts

Saturday, January 3, 2015

Adding Multiple Contact, Opportunities to Account with action status and Jquery example.

Adding Multiple Contact, Opportunities to Account with action status and Jquery example.


Hi,

In this post i am going to show how to change the back ground of the page when command button (Save) is clicked, to achieve this i used JQuery with Action Status.

 Steps:    
1). Include JQuery library in VF page.
2). Create command button with action status
3). Calling JQuery methods from action stats 


Output: 




Once the user clicks on the save button changing the back ground with JQuery and CSS.


Visualforce Page:

<apex:page controller="AddContactsOpportunitiesCLS" id="thePage" action="{!init}">

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"/>
<script>
    j$ = jQuery.noConflict();
    
    function showLoadingDiv() {
        var newHeight = j$("[id$=theFm]").css("height");//Just shade the body, not the header
        j$("[id$=loading-curtain-div]").css("background-color", "black").css("opacity", 0.50).css("height", newHeight).css("width", "90%");
    }
    function hideLoadingDiv() {
        j$("[id$=loading-curtain-div]").css("background-color", "black").css("opacity", "1").css("height", "0px").css("width", "90%");
    }
    
</script>
<style>
    #loading-curtain-div {
        height:0px;
        width:100%;
        position:absolute;
        z-index:5;
        //-webkit-transition: all 0.30s ease-out;
        //-moz-transition: all 0.30s ease-out;
    }
</style>



 <apex:form id="theFm">
   <div id="loading-curtain-div"/>
   <apex:pageBlock title="Account--Contacts--Opportunities Creation" >
   <apex:actionStatus id="save-lead-status" onstart="showLoadingDiv();" onstop="hideLoadingDiv();"/>
    <apex:pageblockButtons >
     <apex:commandButton value="Save" action="{!Save}" status="save-lead-status" reRender="theFm" />
     <apex:commandButton value="Cancel" action="{!Cancel}" immediate="true"/>
    </apex:pageblockButtons>
     
     
     <apex:pageBlockSection id="pbs" columns="2" title="Account Details">      <apex:inputField value="{!acc.Name}"/>
      <apex:inputField value="{!acc.accountNumber}"/>
     <apex:inputField value="{!acc.Type}"/>
     <apex:inputField value="{!acc.Industry}"/>
     </apex:pageBlockSection>
     
     <apex:pageBlockSection title="Contact Details" columns="1" collapsible="false">
       <apex:outputPanel id="contactHead">
      <apex:variable value="{!0}" var="rowNum"/>  
        <apex:pageBlockTable value="{!waConList}" var="eachRecord"> 
         <apex:column headerValue="Action">
        <apex:commandLink value="Remove" style="color:red" action="{!removeRowFromConList}" rendered="{!rowNum > 0}" rerender="contactHead" immediate="true" status="conRemoveLink" >
             <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
         </apex:commandLink>
         <apex:actionStatus id="conRemoveLink" >
                <apex:facet name="start" >
                  <img src="/img/loading.gif" />                    
                </apex:facet>
         </apex:actionStatus>
         <apex:variable var="rowNum" value="{!rowNum + 1}"/>
      </apex:column>
      <apex:column headerValue="First Name">
                            <apex:inputField value="{!eachRecord.record.FirstName}" required="true"/>
       </apex:column>
       <apex:column headerValue="Last Name">
                            <apex:inputField value="{!eachRecord.record.LastName}" required="true"/>
       </apex:column>
       <apex:column headerValue="Phone">
                            <apex:inputField value="{!eachRecord.record.phone}" required="true"/>
       </apex:column>
       <apex:column headerValue="Email">
                            <apex:inputField value="{!eachRecord.record.email}" required="true"/>
       </apex:column>
      
        </apex:pageBlockTable>
        <apex:commandButton value="Add More" action="{!addNewRowToConList}" rerender="contactHead" Status="conStatusId" immediate="true" />
        <apex:actionStatus id="conStatusId" >
                <apex:facet name="start" >
                  <img src="/img/loading.gif" />                    
                </apex:facet>
         </apex:actionStatus>
     </apex:outputPanel>
     </apex:pageBlockSection>
     
     
     <!-- Opportunity Table Goes here -->
          <apex:pageBlockSection title="Opportunity Details" columns="1" collapsible="false">
       <apex:outputPanel id="opportunityHead">
      <apex:variable value="{!0}" var="rowNum"/>  
        <apex:pageBlockTable value="{!waOppList}" var="eachRecord"> 
         <apex:column headerValue="Action">
        <apex:commandLink value="Remove" style="color:red" action="{!removeRowFromOppList}" rendered="{!rowNum > 0}" rerender="opportunityHead" immediate="true" status="oppRemoveLink" >
             <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
         </apex:commandLink>
         <apex:actionStatus id="oppRemoveLink" >
                <apex:facet name="start" >
                  <img src="/img/loading.gif" />                    
                </apex:facet>
         </apex:actionStatus>
         <apex:variable var="rowNum" value="{!rowNum + 1}"/>
      </apex:column>
      <apex:column headerValue="Name">
                            <apex:inputField value="{!eachRecord.record.Name}" required="true"/>
       </apex:column>
       
       <apex:column headerValue="Amount">
                            <apex:inputField value="{!eachRecord.record.Amount}" required="true"/>
       </apex:column>
       <apex:column headerValue="Stage">
                            <apex:inputField value="{!eachRecord.record.StageName}" required="true"/>
       </apex:column>
       <apex:column headerValue="CloseDate">
          <apex:inputField value="{!eachRecord.record.closeDate}" required="true"/>
       </apex:column>
       
       
      
        </apex:pageBlockTable>
        <apex:commandButton value="Add More" action="{!addNewRowToOppList}" rerender="opportunityHead" Status="oppStatusId" immediate="true" />
        <apex:actionStatus id="oppStatusId" >
                <apex:facet name="start" >
                  <img src="/img/loading.gif" />                    
                </apex:facet>
         </apex:actionStatus>
     </apex:outputPanel>
     </apex:pageBlockSection>
   </apex:pageBlock>

 </apex:form>

</apex:page>


Controller Class:

public class AddContactsOpportunitiesCLS {

public Account acc {get;set;}
public List<WrapperContactsList> waConList {get;set;}
public List<WrapperOpportunitiesList> waOppList {get;set;}
public Integer rowToRemove {get;set;}

public AddContactsOpportunitiesCLS (){
acc= new Account();
}

public void init(){
if(waConList ==null){
waConList = new List<WrapperContactsList>();
}
if(waOppList ==null){
 waOppList = new List<WrapperOpportunitiesList>();
}

}

public void addNewRowToConList(){
waConList = AddContactsOpportunitiesHelperCLS.addNewRowToContactList(waConList );
    
}

public void removeRowFromConList(){
  waConList = AddContactsOpportunitiesHelperCLS.removeRowToContactList(rowToRemove ,waConList );

}

public void addNewRowToOppList(){
     waOppList = AddContactsOpportunitiesHelperCLS.addNewRowToOpportunityList(waOppList );
}

public void removeRowFromOppList(){
   waOppList = AddContactsOpportunitiesHelperCLS.removeRowToOpportunityList(rowToRemove,waOppList );
}


Public class WrapperContactsList{
        public Integer index {get;set;}
        public Contact record{get;set;}
}

 public PageReference Cancel() {
  PageReference prf = new PageReference('/apex/AddContactsOpportunitiesVF');
  prf.setRedirect(true);
  return prf;
 }

public PageReference Save() {
 PageReference prf;
 boolean flag;
  if(acc.Name !=null && acc.Name !=''){
   upsert acc;
   if(acc.id != null ){
    flag = AddContactsOpportunitiesHelperCLS.save(acc.id,waConList,waOppList);
    if(flag){
      prf = new PageReference('/apex/AddContactsOpportunitiesVF');
      prf.setRedirect(true);
     
     }
   }
  }
   return prf;
}


public class WrapperOpportunitiesList{
        public Integer index{get;set;}
        public Opportunity record{get;set;}



}

Controller Helper Class:

Public class AddContactsOpportunitiesHelperCLS{

Public static List<AddContactsOpportunitiesCLS.WrapperContactsList> addNewRowToContactList(List<AddContactsOpportunitiesCLS.WrapperContactsList> waConObjList){
        AddContactsOpportunitiesCLS.WrapperContactsList newRecord = new AddContactsOpportunitiesCLS.WrapperContactsList();
        Contact newContactRecord = new Contact();        
        newRecord.record = newContactRecord;
        newRecord.index = waConObjList.size();
        waConObjList.add(newRecord);
        return waConObjList;
}


public static List<AddContactsOpportunitiesCLS.WrapperContactsList> removeRowToContactList(Integer rowToRemove, List<AddContactsOpportunitiesCLS.WrapperContactsList> waConList){
        waConList.remove(rowToRemove);
        return waConList;
}

/*  adding opportunities to the list */
Public static List<AddContactsOpportunitiesCLS.WrapperOpportunitiesList> addNewRowToOpportunityList(List<AddContactsOpportunitiesCLS.WrapperOpportunitiesList> waOppObjList){
        AddContactsOpportunitiesCLS.WrapperOpportunitiesList newRecord = new AddContactsOpportunitiesCLS.WrapperOpportunitiesList();
        Opportunity newOpportunityRecord = new Opportunity();        
        newRecord.record = newOpportunityRecord;
        newRecord.index = waOppObjList.size();
        waOppObjList.add(newRecord);
        return waOppObjList;
}



public static List<AddContactsOpportunitiesCLS.WrapperOpportunitiesList> removeRowToOpportunityList(Integer rowToRemove, List<AddContactsOpportunitiesCLS.WrapperOpportunitiesList> waOppList){
        waOppList.remove(rowToRemove);
        return waOppList;
}
    
public static boolean save(String accId,List<AddContactsOpportunitiesCLS.WrapperContactsList> waConList  ,List<AddContactsOpportunitiesCLS.WrapperOpportunitiesList> waOppList) {
  boolean statusFlag = true;    
  system.debug('==waConList==>'+waConList.size());
  system.debug('==waOppList==>'+waOppList.size());
    
    try{
        
        List<Contact> contactRecordsToBeInserted = new List<Contact>();
        if(waConList !=null && !waConList.isEmpty()){
            for(AddContactsOpportunitiesCLS.WrapperContactsList eachRecord : waConList ){
                Contact conTemp = eachRecord.record;
                conTemp.AccountId = accId;
                contactRecordsToBeInserted.add(conTemp);
               
          }
            system.debug('==contactRecordsToBeInserted==>'+contactRecordsToBeInserted.size());
            upsert contactRecordsToBeInserted;
        }
    List<Opportunity> opportunityRecordsToBeInserted = new List<Opportunity>();
     if(waOppList != null && !waOppList.isEmpty()) {
       for(AddContactsOpportunitiesCLS.WrapperOpportunitiesList eachRecord : waOppList ){
                Opportunity oppTemp = eachRecord.record;
                oppTemp.AccountId = accId;
                opportunityRecordsToBeInserted.add(oppTemp);
               
            }
         
          system.debug('==opportunityRecordsToBeInserted==>'+opportunityRecordsToBeInserted.size());
            upsert opportunityRecordsToBeInserted;
     }
        
    }catch(Exception e){
        system.debug('Exception occure in save method..of helper classs-->'+e);
        statusFlag =false;
    }
       
    return statusFlag;
    
    }    



}




Enjoy the coding...


Saturday, December 20, 2014

Dashboards in Salesforce.com

Dashboards in Salesforce.com

 

Dashboard is an amazing medium by which the companies whole information can be shared with the CEO as a SCREENSHOT. Some important things to know about Dashboard are:

 

*With Dashboard a user can even see the information to which he does not has the access, Thanks to the concept of Running User - ADM 201, CON 201, DEV 401 Certification Question

*One can have only 2 or 3 columns in a Dashboard - ADM 201 Certification Question
*In Home, Dashboard component you only see the FIRST ROW of the source dashboard - ADM 201 certification question

*You can restrict the access to a dashboard by restricting the access to a folder in which that dashboard is placed

*Dashboards can be scheduled to run any time during a day and you can get them delivered via an Email

*Dashboards can only be created with custom reports as the source reports. One can not have the standard reports as the source reports for the Dashboard – ADM 201 Certification Question

*Only 20 components can be added to a dashboard - ADM 201 Certification Question
*Deleted Dashboards can be retrieved from the Recyclebin




 

Friday, December 19, 2014

Can a Contact be part of Partner Portal as well as Customer Portal in salesforce.com?

Can a Contact be part of Partner Portal as well as Customer Portal in salesforce.com?

Answer: Customer Portal and Partner portal depend on the user object and are not related to the contact object. So to enable both portals for a Contact we need to create two users which will utilize two different salesforce.com licenses, one license for Customer portal and other for Partner portal. Yes, a contact can be part of a Partner Portal as well as Customer portal in salesforce.com. Both users created for a same contact will have two different profiles, One for Customer portal and other for Partner Portal. 






Monday, November 17, 2014

Faster Loops in Apex.

Faster Loops in Apex.














Tuesday, March 4, 2014

What is CRM?

What is CRM?




What is Salesforce CRM?

What is Salesforce CRM?



Thursday, February 20, 2014

What is Apex?

What is Apex?


Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Force.com platform server in conjunction with calls to the Force.com API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.



When Should I Use Apex?

The Salesforce prebuilt applications provide powerful CRM functionality. In addition, Salesforce provides the ability to customize the pre built applications to fit your organization. However, your organization may have complex business processes that are unsupported by the existing functionality. When this is the case, the Force.com platform includes a number of ways for advanced administrators and developers to implement custom functionality. These include Apex, Visualforce, and the SOAP API.





Apex


Use Apex if you want to:
• Create Web services.
• Create email services.
• Perform complex validation over multiple objects.
• Create complex business processes that are not supported by workflow.
• Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object.)
• Attach custom logic to another operation, such as saving a record, so that it occurs whenever the operation is executed,regardless of whether it originates in the user interface, a Visualforce page, or from SOAP API.

Visualforce

Visualforce consists of a tag-based markup language that gives developers a more powerful way of building applications and customizing the Salesforce user interface. With Visualforce you can:
• Build wizards and other multistep processes.
• Create your own custom flow control through an application.
• Define navigation patterns and data-specific rules for optimal, efficient application interaction.


SOAP API

Use standard SOAP API calls if you want to add functionality to a composite application that processes only one type of record at a time and does not require any transactional control (such as setting a Savepoint or rolling back changes).




 
| ,