Wednesday, 21 May 2014

Based on Picklist i need to display On Text Field.


Picklist,   Text
PD (NA), 207.7
PD (UK), 174.95
CN (NA), 149
CN (UK), 157.4
CN (Ind), 24.4
CN (China), 24.4
CN (Japan), 120

Through Work flow i have done.
Work Flow Rule Criteria:  True
Field Updation:- 
CASE(Resource_Role__c,"PD(NA)", 207.7, 
"PD(UK)",174.95, "CN(NA)",149, "CN(UK)",157.4,"CN(Ind)",24.4, 
"CN(China",24.4, "CN(Japan)",120, "SS(NA)",134.95, "SS(UK)",128.95, "SS(Ind)",24.4,"EM(NA)",149,"EM(UK)",157.4,"EM(Ind)",24.4,"EM(Japan)",120,"Dev/QA(Ind)",24.4,"FTC Admin(Ind)",24.4, 
null)



Getting #Error! in a formula field


Basically i am getting this error(#Error!) on using formula field.


Is this happening when Total_Revenue__c is blank or equal to 0?  This would cause the error.  You need to add checks in the formula for if Total_Revenue__c is 0, to prevent trying to divide by 0.
Total_Revenue__c,Total_Cost__c these fields are Formula fields
Solution:-

IF(
     OR(
          ISBLANK(Total_Revenue__c),
          Total_Revenue__c = 0
     ),
     0,
     (Total_Revenue__c - Total_Cost__c) / Total_Revenue__c)
)

Tuesday, 20 May 2014

Based on picklist values i need to update Text field(Dynamically) in salesforce.


I have 2objects with Master-detail Relationship.

1st Object Paretn1,Paretn2,Paretn3,Paretn4,Paretn5 all are Number Fields.

I enter Partner2(Parent) some value
User-added image

2nd Object

In child i selected in picklist(partner2) i am not get the "Cost/Hr$(NumberField)" here.
Picklist Values :-

User-added image

When i select Partner1 with data when select on picklist for that Partner1 automatically need to display on "Cost(Number Field).



Like this Through Work flow i have done.

Rule Criteria:-  true

Field Update:-  
IF(ISPICKVAL(Resource_Role__c,"Partner1"), Opportunity_Margin_Template__r.Partner1__c,
IF(ISPICKVAL(Resource_Role__c,"Partner2"),
Opportunity_Margin_Template__r.Partner2__c,
IF(ISPICKVAL(Resource_Role__c,"Partner3"),
Opportunity_Margin_Template__r.Partner3__c,
IF(ISPICKVAL(Resource_Role__c,"Partner4"),
Opportunity_Margin_Template__r.Partner4__c,
IF(ISPICKVAL(Resource_Role__c,"Partner5"),
Opportunity_Margin_Template__r.Partner5__c,Null
)))))

I have done single Workflow for these requirement.

CASE(Resource_Role__c,"PD(NA)", 207.7, 
"PD(UK)",174.95, "CN(NA)",149, "CN(UK)",157.4,"CN(Ind)",24.4, 
"CN(China",24.4, "CN(Japan)",120, "SS(NA)",134.95, "SS(UK)",128.95, "SS(Ind)",24.4,"EM(NA)",149,"EM(UK)",157.4,"EM(Ind)",24.4,"EM(Japan)",120,"Dev/QA(Ind)",24.4,"FTC Admin(Ind)",24.4, 
IF(ISPICKVAL(Resource_Role__c,"Partner1"), Opportunity_Margin_Template__r.Partner1__c, 
IF(ISPICKVAL(Resource_Role__c,"Partner2"), 
Opportunity_Margin_Template__r.Partner2__c, 
IF(ISPICKVAL(Resource_Role__c,"Partner3"), 
Opportunity_Margin_Template__r.Partner3__c, 
IF(ISPICKVAL(Resource_Role__c,"Partner4"), 
Opportunity_Margin_Template__r.Partner4__c, 
IF(ISPICKVAL(Resource_Role__c,"Partner5"), 
Opportunity_Margin_Template__r.Partner5__c,Null 
))))) 

)


Sunday, 18 May 2014

Roll up summaries don't support summation of Cross Object formula.


  • Roll up summaries don't support summation of Cross Object formula. 
  • So we need to go through Trigger.

Monday, 12 May 2014

Select lookup icon the related data automatically display


When i select 'Gold' The related data display.

Apex Class:-
------------

public class TemplateTaskData {
 public TemplateTaskData(ApexPages.StandardController controller) {
        lookupDataPop = new Template_Tasks__c();
        //lookupDataPop = (Template_Tasks__c )controller.getrecord();
      }
    public Template_Tasks__c lookupDataPop {get;set;}
    public string lkpdata {get;set;}
    public List < Template_Tasks__c > templatetask {get;set;}

    public pagereference currentData() {
        system.debug('lookupDataPop.Template__c****' + lookupDataPop.Templates_Name__c);

        templatetask = new list < Template_Tasks__c > ();
        if (lkpdata == 'MAT-Maestro(SMB) - Gold') {
            for(Integer i=0; i<5; i++){
                lookupDataPop = new Template_Tasks__c();
          //      lookupDataPop.Templates_Name__c = lookupDataPop.Templates_Name__c;
         //      lookupDataPop.Billing_function__c = 'CN';
         //       lookupDataPop.Billing_HOURS__c = '82';
                templatetask.add(lookupDataPop);
            }
            templatetask[0].Template_Task_Name__c = 'Maestro 5 LMS Implementation Package';
            templatetask[0].Billing_HOURS__c = '82';
            templatetask[0].Billing_function__c = 'CN';
            templatetask[1].Template_Task_Name__c = 'Data Migration';
            templatetask[1].Billing_HOURS__c = '44';
            templatetask[1].Billing_function__c = 'CN';
            templatetask[2].Template_Task_Name__c = 'Data migration - Express';
            templatetask[2].Billing_HOURS__c = '44';
            templatetask[2].Billing_function__c = 'CN';
            templatetask[3].Template_Task_Name__c = 'Data Migration - Full';
            templatetask[3].Billing_HOURS__c = '84';
            templatetask[3].Billing_function__c = 'CN';
            templatetask[4].Template_Task_Name__c = 'Maestro Full data migration X3';
            templatetask[4].Billing_HOURS__c = '252';
            templatetask[4].Billing_function__c = 'CN';
           
        } else if (lkpdata == 'MAT-Maestro(SMB) - Bronze') {
            for(Integer i=0; i<5; i++){
                lookupDataPop = new Template_Tasks__c();
                templatetask.add(lookupDataPop);
             }
            templatetask[0].Template_Task_Name__c = 'Maestro 5 LMS Implementation Package';
            templatetask[0].Billing_HOURS__c = '44';
            templatetask[0].Billing_function__c = 'CN';
            templatetask[1].Template_Task_Name__c = 'Data Migration';
            templatetask[1].Billing_HOURS__c = '44';
            templatetask[1].Billing_function__c = 'CN';          
            templatetask[2].Template_Task_Name__c = 'Data migration - Express';
            templatetask[2].Billing_HOURS__c = '44';
            templatetask[2].Billing_function__c = 'CN';          
            templatetask[3].Template_Task_Name__c = 'Data Migration - Full';
            templatetask[3].Billing_HOURS__c = '84';
            templatetask[3].Billing_function__c = 'CN';          
            templatetask[4].Template_Task_Name__c = 'Maestro Full data migration X3';
            templatetask[4].Billing_HOURS__c = '252';
            templatetask[4].Billing_function__c = 'CN';          
        } else if (lkpdata == 'MAT-Maestro(SMB) - Silver') {
            for(Integer i=0; i<5; i++){
                lookupDataPop = new Template_Tasks__c();
              templatetask.add(lookupDataPop);              
            }
            templatetask[0].Template_Task_Name__c = 'Maestro 5 LMS Implementation Package';
            templatetask[0].Billing_HOURS__c = '61';
            templatetask[0].Billing_function__c = 'CN';
            templatetask[1].Template_Task_Name__c = 'Data Migration';
            templatetask[1].Billing_HOURS__c = '44';
            templatetask[1].Billing_function__c = 'CN';          
            templatetask[2].Template_Task_Name__c = 'Data migration - Express';
            templatetask[2].Billing_HOURS__c = '44';
            templatetask[2].Billing_function__c = 'CN';          
            templatetask[3].Template_Task_Name__c = 'Data Migration - Full';
            templatetask[3].Billing_HOURS__c = '84';
            templatetask[3].Billing_function__c = 'CN';          
            templatetask[4].Template_Task_Name__c = 'Maestro Full data migration X3';
            templatetask[4].Billing_HOURS__c = '252';
            templatetask[4].Billing_function__c = 'CN';        
        }
        return null;
    }
}


VF Page:-
---------
<apex:page StandardController="Template_Tasks__c" extensions="TemplateTaskData">
 <apex:Form >
  <apex:pageBlock >
   <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!Save}"/>
    <apex:commandButton value="Cancel" action="{!Cancel}"/>
   </apex:pageBlockButtons>
   <apex:pageBlockSection title="Template Tasks" columns="1">
    <apex:inputfield value="{!lookupDataPop.Templates_Name__c}" onchange="currentDataFecth();" id="lkp">
     <apex:actionFunction name="currentDatafn" action="{!currentData}" reRender="pgbsc" />
    </apex:inputfield>
 
   <apex:pageblocktable value="{!templatetask}" var="row" id="pgbsc" >
       <apex:column headerValue="Template Task name"  value="{!row.Template_Task_Name__c}"/>
       <apex:column headerValue="Billing Function"  value="{!row.Billing_Function__c}"/>
       <apex:column headerValue="Billing Hours"  value="{!row.Billing_hours__c}"/>  
   </apex:pageblocktable>
 
<apex:inputhidden value="{!lkpdata}" id="theHiddenInput" />
<script>
 var lkpvalue='';
  function currentDataFecth(){
      lkpvalue =document.getElementById("{!$Component.lkp}").value;
      document.getElementById("{!$Component.theHiddenInput}").value = lkpvalue ;
      currentDatafn();
  }
 </script>
   
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:Form>
</apex:page>


Saturday, 26 April 2014

Child to parent updation using Master- Detail relationship.


Child to parent updation using Master- Detail relationship. Not possible workflow, Only possible on Trigger.

Ex:-
---
trigger OpportunityStageUpdate on Opportunity (after update) {
 //create list of Opportunity IDs
    List < ID > oid = New List < ID > ();
    //find Opportunity to add to list
    for (Opportunity o: Trigger.new) {
        if (o.StageName== 'Closed Lost') {
            oid.add(o.ID);
        }
    }
    List < ProfessionalServicesRequest__c> PSRUpdateList= [SELECT Id,Status__c from ProfessionalServicesRequest__c WHERE Opportunity__c in : oid];
   
    for (ProfessionalServicesRequest__c objPSR: PSRUpdateList) {
        objPSR.Status__c = 'Request Cancelled';
    }
    update PSRUpdateList;
}

Monday, 7 April 2014

Choosing Workflow or Trigger for Field Updates

Keep in mind that you should always use a workflow when possible!  Only use triggers when you cannot accomplish something using a workflow.

See below for which to use and why:

----Master-detail Relationship----

1) Updating parent picklist value based on child picklist values (Workflow or Trigger)
>> Workflow, because with master-detail relationship a child object can update the parent

2) Updating child picklist value based on parent picklist values (Workflow or Trigger)
>> Trigger, because you cannot update all children records from a workflow rule, no mater what the relationship is

----Lookup Relationship----

 
3) Updating parent picklist value based on child picklist values (Workflow or Trigger)
>> Trigger, because you can only update the parent record in a workflow if it is a master-detail relationship

4) Updating child picklist value based on parent picklist values (Workflow or Trigger)
>> Trigger, because you cannot update all children records from a workflow rule, no mater what the relationship is

----No Relationship Between Objects----

5) Updating parent picklist value based on child picklist values (Workflow or Trigger)
>> Trigger, because without a relationship the workflow will not know which record to change

6) Updating child picklist value based on parent picklist values (Workflow or Trigger)
>> Trigger, because without a relationship the workflow will not know which record to change