• Abdel-Ali BOULIKA
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
Here is my method, code works fine till line 65 and its getting executed the conditions 6 to 10(debug staments) but the fields are not getting updated , any clue?
  1.   public static void AccountUltimateRevenue(Map<ID,Account> newActMap,Map<ID,Account> oldActMap,List<Account>newActList){
  2.            List<Account>actList=new List<Account>();
  3.            List<Account>aList;
  4.            Set<ID>parentActList=new Set<ID>();
  5.            List<Account>uParents=new List<Account>();
  6.            Map<ID, List<Account>> uActListMap = new Map<ID, List<Account>>();
  7.             for(Account a:newActList) 
  8.             {
  9.             Account a1=oldActMap.get(a.id);
  10.            // To check whether Parent Account was updated and not null
  11.            if((newActMap.get(a.Id).parentID!=oldActMap.get(a.Id).parentID && newActMap.get(a.Id).parentID<>null))
  12.             {
  13.             ActList.add(a);
  14.             parentActList.add(newActMap.get(a.Id).parentID);
  15.             System.debug('old+++++++++'+a1.parentID+'new++++++++++++++++'+a.parentID);
  16.             System.debug('ActList+++++++++'+ActList);
  17.             }
  18.             else 
  19.             if(newActMap.get(a.Id).parentID==null)
  20.             {   System.debug('No Parent**:');
  21.              uParents.add(a);
  22.                
  23.             }
  24.      }       
  25.    // Checking if Parent Account list not null pulling all corresponding Ultimate parent revenue and Ultimate parent vertical values from parent accounts.
  26.         if(parentActList!= null && parentActList.size()>0){
  27.             //system.debug( 'Parent Account list:'+parentActList);               
  28.             map<Id, Account> uActMap=new map<Id, Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
  29.                                                            ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
  30.                                                            Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
  31.                                                            Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
  32.                                                            Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue
  33.                                                            from Account where ID IN :parentActList]);     
  34.                for(Account a: newActList)
  35.                {
  36.                 Account ParentAccount = uActMap.get(a.ParentId);
  37.                 System.debug('Parent ID**:'+ a.ParentId);
  38.                 if (ParentAccount.ParentId ==null){
  39.                 System.debug('Condition 1**:');
  40.                     a.Ultimate_Parent_Vertical__c = ParentAccount.OS_Industry_Sector__c;
  41.                     a.Ultimate_Parent_Revenue__c = ParentAccount.AnnualRevenue;
  42.                     }
  43.                 else if (ParentAccount.Parent.ParentId ==null){
  44.                 System.debug('Condition 2**:');
  45.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.OS_Industry_Sector__c;
  46.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.AnnualRevenue;
  47.                          }
  48.                 else if (ParentAccount.Parent.Parent.ParentId ==null){
  49.                 System.debug('Condition 3**:');
  50.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.OS_Industry_Sector__c;
  51.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.AnnualRevenue;
  52.                          }
  53.                 else if (ParentAccount.Parent.Parent.Parent.ParentId ==null){
  54.                 System.debug('Condition 4**:');
  55.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.OS_Industry_Sector__c;
  56.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.AnnualRevenue;
  57.                          }
  58.                 else if (ParentAccount.Parent.Parent.Parent.Parent.ParentId ==null){
  59.                 System.debug('Condition 5**:');
  60.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  61.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.Parent.AnnualRevenue;
  62.                          }
  63.                }
  64.         }
  65.                              
  66.                 if(uParents.size()>0)
  67.                 {  
  68.                  List<Account> uChild=new List<Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
  69.                                                            ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
  70.                                                            Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
  71.                                                            Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
  72.                                                            Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue from Account where ParentId IN :uParents OR Parent.ParentId IN :uParents OR Parent.Parent.ParentId IN :uParents OR Parent.Parent.Parent.ParentId IN :uParents]);
  73.            for(Account a: uChild)
  74.                {
  75.                if (a.ParentId ==null){
  76.                 System.debug('Condition 6**:');
  77.                     a.Ultimate_Parent_Vertical__c = a.OS_Industry_Sector__c;
  78.                     a.Ultimate_Parent_Revenue__c = a.AnnualRevenue;
  79.                     }
  80.                 else if (a.Parent.ParentId ==null){
  81.                 System.debug('Condition 7**:'+a.Parent.OS_Industry_Sector__c+a.Parent.AnnualRevenue);
  82.                   //a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  83.                          a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  84.                          a.Ultimate_Parent_Revenue__c = a.Parent.AnnualRevenue;
  85.                          }
  86.                 else if (a.Parent.Parent.ParentId ==null){
  87.                 System.debug('Condition 8**:');
  88.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.OS_Industry_Sector__c;
  89.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.AnnualRevenue;
  90.                          }
  91.                 else if (a.Parent.Parent.Parent.ParentId ==null){
  92.                 System.debug('Condition 9**:');
  93.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.OS_Industry_Sector__c;
  94.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.AnnualRevenue;
  95.                          }
  96.                 else if (a.Parent.Parent.Parent.Parent.ParentId ==null){
  97.                 System.debug('Condition 10**:');
  98.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  99.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.Parent.AnnualRevenue;
  100.                          }
  101.                }
  102.                }
  103.                
  104.            
  105.         }
Hi,
Please help me out with trigger…

In the contact object if we are giving the details of contact (for e.g., email) if we are giving the same email id which was given for first time then it should accept(i.e., accepting the dupliactes).
When the same thing (mentioned above) is doing in the Account object related list of contact then it should not allow the duplicates.
  • May 07, 2014
  • Like
  • 0
how to increase code coverage now i am geeting a 55% in apex trigger...
trigger test on Case (before update )
{
  Map<string, Schema.SobjectField> caseFields = Schema.SObjectType.Case.fields.getMap();

  case caseold=trigger.old[0];
  For (Case cs : Trigger.new)
  {
    for (string fieldName : caseFields.keySet())
     {
       
        if ( cs.get(fieldName) != Trigger.oldMap.get(cs.id).get(fieldName))
        {
           // cs.Track_status_history__c = 'Field ' + fieldName + ' changed from ' + string.valueOf(Trigger.oldMap.get(cs.id).get(fieldName)) + ' to '  +string.valueOf(cs.get(fieldName));
             string oldvalue = string.valueOf(caseold.get(fieldName));------------->doesnot executing
            
             string newvalue= string.valueOf(cs.get(fieldName));------------->doesnot executing
           
             cs.Track_status_history__c = 'Changed '+fieldName +' From '+oldvalue +' to '+ newvalue;
         
             break;
          }   
       }
  }
}
=============================================
@isTest
private class Testcasehistory
{

   static testMethod void updatefields()
    {
     list<Case> cslist=new list<case>();
     case cs=new case();
     cs.Origin='Web';
     cs.Reason='other';
     cs.Priority='Medium';
     cs.Status='New';
     cs.Type='Other';
     cslist.add(cs);
     test.startTest();
      insert cslist;
    
     Case updcase = [SELECT Id,Origin,Reason,Priority,Status,Type  FROM Case WHERE Id=:cs.Id];
     update updcase;
     test.stopTest();
    }
}=====================
Hi,

As the inputFile component cannot be customized in visualForce, I have implemented a binding to a custom button and hidden the original inputFile.
When I click on the button I trigger the click event on the inputFile.

Here is my VF page:
<apex:form >
        <script language="JavaScript" type="text/javascript">
            function HandleBrowseClick()
            {
                var fileinput = document.getElementById("{!$Component.SnapshotInputfile}");
                fileinput.click();
            }
            
            function Handlechange()
            {
                var fileinput = document.getElementById("{!$Component.SnapshotInputfile}");
                var textinput = document.getElementById("filename");
                textinput.innerHTML = fileinput.value;
            }
        </script>

    
        <apex:inputfile id="SnapshotInputfile" value="{!snapshot_attachment.body}"  onChange="Handlechange();" accept="image/*" filename="{!snapshot_attachment.Name}">            
        </apex:inputfile>
        <label id="filename" readonly="true"/>
        <input type="button" value="select" id="fakeBrowse" onclick="HandleBrowseClick();" class="btn"/>

        <apex:commandButton id="uploadButton" action="{!UploadPicture}" value="upload"/>
    </apex:form>
So I have a commandButton that will post the file to the server, where in the controller I create an attachment with the file.
It worked like a charm in Firefox and Chrome, however in ie8, when the file is picked after clicking on the custom button, everytime the commandButton is clicked, the value of the inputFile is cleared, and the page doesn't postback.

So I'm wondering whether there is a workaround to fix the behavior in ie8.

Thx.


Hi all,

Schedulable class send attachment email, it taken attachment body empty. but this class run from developer console working fine.what i am wrong here.

schedulable class:

global class ActivesummaryReportsend implements Schedulable
{
  
   global void execute (SchedulableContext ctx)
   {
     sendmail();
   }
 
 
   public void sendmail()
   {
     Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
     PageReference excl=  Page.Report;
     excl.setRedirect(true);
    
     Blob b;
 
       b = excl.getContent();

    
    // Create the email attachment
     Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
     efa.setFileName('Report.xls');
     efa.setContentType('application/vnd.ms-excel');
     efa.setBody(b);
    
     email.setSubject( 'Activity Summary Report');
     email.setToAddresses(new String[] { 'gopikrishna04@gmail.com' });
     email.setPlainTextBody( 'Please Find Attachment  Summary Report.');
     email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
    // email.setSaveAsActivity(true);
     Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        
   } 
}
Here is my method, code works fine till line 65 and its getting executed the conditions 6 to 10(debug staments) but the fields are not getting updated , any clue?
  1.   public static void AccountUltimateRevenue(Map<ID,Account> newActMap,Map<ID,Account> oldActMap,List<Account>newActList){
  2.            List<Account>actList=new List<Account>();
  3.            List<Account>aList;
  4.            Set<ID>parentActList=new Set<ID>();
  5.            List<Account>uParents=new List<Account>();
  6.            Map<ID, List<Account>> uActListMap = new Map<ID, List<Account>>();
  7.             for(Account a:newActList) 
  8.             {
  9.             Account a1=oldActMap.get(a.id);
  10.            // To check whether Parent Account was updated and not null
  11.            if((newActMap.get(a.Id).parentID!=oldActMap.get(a.Id).parentID && newActMap.get(a.Id).parentID<>null))
  12.             {
  13.             ActList.add(a);
  14.             parentActList.add(newActMap.get(a.Id).parentID);
  15.             System.debug('old+++++++++'+a1.parentID+'new++++++++++++++++'+a.parentID);
  16.             System.debug('ActList+++++++++'+ActList);
  17.             }
  18.             else 
  19.             if(newActMap.get(a.Id).parentID==null)
  20.             {   System.debug('No Parent**:');
  21.              uParents.add(a);
  22.                
  23.             }
  24.      }       
  25.    // Checking if Parent Account list not null pulling all corresponding Ultimate parent revenue and Ultimate parent vertical values from parent accounts.
  26.         if(parentActList!= null && parentActList.size()>0){
  27.             //system.debug( 'Parent Account list:'+parentActList);               
  28.             map<Id, Account> uActMap=new map<Id, Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
  29.                                                            ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
  30.                                                            Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
  31.                                                            Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
  32.                                                            Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue
  33.                                                            from Account where ID IN :parentActList]);     
  34.                for(Account a: newActList)
  35.                {
  36.                 Account ParentAccount = uActMap.get(a.ParentId);
  37.                 System.debug('Parent ID**:'+ a.ParentId);
  38.                 if (ParentAccount.ParentId ==null){
  39.                 System.debug('Condition 1**:');
  40.                     a.Ultimate_Parent_Vertical__c = ParentAccount.OS_Industry_Sector__c;
  41.                     a.Ultimate_Parent_Revenue__c = ParentAccount.AnnualRevenue;
  42.                     }
  43.                 else if (ParentAccount.Parent.ParentId ==null){
  44.                 System.debug('Condition 2**:');
  45.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.OS_Industry_Sector__c;
  46.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.AnnualRevenue;
  47.                          }
  48.                 else if (ParentAccount.Parent.Parent.ParentId ==null){
  49.                 System.debug('Condition 3**:');
  50.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.OS_Industry_Sector__c;
  51.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.AnnualRevenue;
  52.                          }
  53.                 else if (ParentAccount.Parent.Parent.Parent.ParentId ==null){
  54.                 System.debug('Condition 4**:');
  55.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.OS_Industry_Sector__c;
  56.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.AnnualRevenue;
  57.                          }
  58.                 else if (ParentAccount.Parent.Parent.Parent.Parent.ParentId ==null){
  59.                 System.debug('Condition 5**:');
  60.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  61.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.Parent.AnnualRevenue;
  62.                          }
  63.                }
  64.         }
  65.                              
  66.                 if(uParents.size()>0)
  67.                 {  
  68.                  List<Account> uChild=new List<Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
  69.                                                            ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
  70.                                                            Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
  71.                                                            Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
  72.                                                            Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue from Account where ParentId IN :uParents OR Parent.ParentId IN :uParents OR Parent.Parent.ParentId IN :uParents OR Parent.Parent.Parent.ParentId IN :uParents]);
  73.            for(Account a: uChild)
  74.                {
  75.                if (a.ParentId ==null){
  76.                 System.debug('Condition 6**:');
  77.                     a.Ultimate_Parent_Vertical__c = a.OS_Industry_Sector__c;
  78.                     a.Ultimate_Parent_Revenue__c = a.AnnualRevenue;
  79.                     }
  80.                 else if (a.Parent.ParentId ==null){
  81.                 System.debug('Condition 7**:'+a.Parent.OS_Industry_Sector__c+a.Parent.AnnualRevenue);
  82.                   //a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  83.                          a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  84.                          a.Ultimate_Parent_Revenue__c = a.Parent.AnnualRevenue;
  85.                          }
  86.                 else if (a.Parent.Parent.ParentId ==null){
  87.                 System.debug('Condition 8**:');
  88.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.OS_Industry_Sector__c;
  89.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.AnnualRevenue;
  90.                          }
  91.                 else if (a.Parent.Parent.Parent.ParentId ==null){
  92.                 System.debug('Condition 9**:');
  93.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.OS_Industry_Sector__c;
  94.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.AnnualRevenue;
  95.                          }
  96.                 else if (a.Parent.Parent.Parent.Parent.ParentId ==null){
  97.                 System.debug('Condition 10**:');
  98.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  99.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.Parent.AnnualRevenue;
  100.                          }
  101.                }
  102.                }
  103.                
  104.            
  105.         }
Issue: If a parent object is deleted, the Date fields on the now-orphan children show as today in VF when binded using outputFields. If using outputText the proper value (empty) is shown.


Scenario:
2 objects: Car__c is the parent for Part__c

Excerpt from controller (partly pseudo):
public Schema.FieldSetMember[] carFields { get; set; }
public Part__c[] parts { get; set; }

public Controller()
{
    carFields = list of fields from Fieldset containing Model__c, CreatedDate, Intro_Date__c
    parts = [select Name, Car__r.Model__c, Car__r.CreatedDate, Car__r.Intro_Date__c from Part__c];
}

Excerpt from VF page (a table with a list of part Names + their corresponding Car info):
<apex:pageBlockTable value="{!parts}" var="part">

    <!-- Part Name -->
    <apex:column value="{!part.Name}">

    <!-- Car Fields -->
    <apex:repeat value="{!carFields}" var="f">
        <apex:column>
            <apex:outputField value="{!part.Car__r[f]}"/>
        </apex:column>
    </apex:repeat>

</apex:pageBlockTable>

The resulting table looks like this:
Name____Model__Created Date__Intro Date
=======================================
Gear____Benz___4/9/2013______1/4/2013
Knob____BMW____6/8/2012______6/7/2012
Screw__________5/5/2014______5/5/2014 < CHILD DELETED >
Pedal__________5/5/2014______5/5/2014 < CHILD DELETED >
Bushing_Audi___3/5/2011______________
This seems like a bug to me. Anything I'm missing?