• pankaj kabra
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

In Opportunity, If the stage is changed from another value  to CLOSED_WON or CLOSED_LOST, populates the Close Date field with Today().

//Class for Calculating Working Dates between Two Days
public with sharing class TotalWorkingDyasBetweenTwoDates {
     public static Double totalWorkingDays(Date startDate,Date endDate){
        Double totalWorkingDays = 0;
        Double temps; 
        Date tempDate = date.newInstance(1985, 6, 24); 
        //Calculating mod of no of days between random date and start date
        Double temp = Math.mod(tempDate.daysBetween(startDate) , 7);
        if(temp==0){
             System.debug('hello 0');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
            else if(temps == 2 ){
                totalWorkingDays = 3;
            }
            else if(temps == 3 ){
                totalWorkingDays = 4;
            }
            else if(temps == 4 ){
                totalWorkingDays = 5;
            }
            else if(temps == 5 ){
                totalWorkingDays = 5;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
        }
       else if(temp==1){
                    System.debug('hello 1');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 3;
            }
            else if(temps == 3 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 5;
            }
            else if(temps == 5 ){
                totalWorkingDays = 4;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
            
        } 
       else if(temp==2){
                    System.debug('hello 2');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 3;
            }
           else if(temps == 3 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
            
        } 
       else if(temp==3){
                    System.debug('hello 3');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
           
        } 
       else if(temp==4){
                    System.debug('hello 4');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 6 ){
                totalWorkingDays = 5;
            }  
            else
                totalWorkingDays = 1;          
        } 
        else if(temp==5){
                     System.debug('hello 5');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 0;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 0;
            
        } 
       else if(temp==6){
                    System.debug('hello 6');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 4;
            }
          else   if(temps == 5 ){
                totalWorkingDays = 5;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 0; 
        } 
        else{
                System.debug('sffsf');
                totalWorkingDays = 999;
        }
       
        totalWorkingDays = totalWorkingDays + math.floor(startDate.daysBetween(endDate)/7*5);  
        return totalWorkingDays;
    }
 }
//Class for Calculating Working Dates between Two Days
public with sharing class TotalWorkingDyasBetweenTwoDates {
     public static Double totalWorkingDays(Date startDate,Date endDate){
        Double totalWorkingDays = 0;
        Double temps; 
        Date tempDate = date.newInstance(1985, 6, 24); 
        //Calculating mod of no of days between random date and start date
        Double temp = Math.mod(tempDate.daysBetween(startDate) , 7);
        if(temp==0){
             System.debug('hello 0');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
            else if(temps == 2 ){
                totalWorkingDays = 3;
            }
            else if(temps == 3 ){
                totalWorkingDays = 4;
            }
            else if(temps == 4 ){
                totalWorkingDays = 5;
            }
            else if(temps == 5 ){
                totalWorkingDays = 5;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
        }
       else if(temp==1){
                    System.debug('hello 1');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 3;
            }
            else if(temps == 3 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 5;
            }
            else if(temps == 5 ){
                totalWorkingDays = 4;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
            
        } 
       else if(temp==2){
                    System.debug('hello 2');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 3;
            }
           else if(temps == 3 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
            
        } 
       else if(temp==3){
                    System.debug('hello 3');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 1;
           
        } 
       else if(temp==4){
                    System.debug('hello 4');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
           else  if(temps == 6 ){
                totalWorkingDays = 5;
            }  
            else
                totalWorkingDays = 1;          
        } 
        else if(temp==5){
                     System.debug('hello 5');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 0;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 5 ){
                totalWorkingDays = 4;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 0;
            
        } 
       else if(temp==6){
                    System.debug('hello 6');
            temps =  Math.mod(startDate.daysBetween(endDate) , 7);
            if(temps == 1 ){
                totalWorkingDays = 1;
            }
           else  if(temps == 2 ){
                totalWorkingDays = 2;
            }
           else  if(temps == 3 ){
                totalWorkingDays = 3;
            }
           else  if(temps == 4 ){
                totalWorkingDays = 4;
            }
          else   if(temps == 5 ){
                totalWorkingDays = 5;
            }
            else if(temps == 6 ){
                totalWorkingDays = 5;
            }
            else
                totalWorkingDays = 0; 
        } 
        else{
                System.debug('sffsf');
                totalWorkingDays = 999;
        }
       
        totalWorkingDays = totalWorkingDays + math.floor(startDate.daysBetween(endDate)/7*5);  
        return totalWorkingDays;
    }
 }

Hey Guys,

 

Im struggling abit with figuring out how to parse some xml into a custom object. Ive been working with the xmlstreamreader example, but I cant quite wrap my head around how step through the xml elements values that I want to insert into my custom object....

 

The xml response Im getting back from my webcallout looks like this:

 

<advertisers type="array">
  <advertiser>
    <id type="integer">7</id>
    <name>ABC Telecom</name>
  </advertiser>
  <advertiser>
    <id type="integer">106</id>
    <name>ABC_Ozone</name>
  </advertiser><advertiser>
    <id type="integer">13</id>
    <name>Acme Corp</name>
  </advertiser>
</advertisers>

 

My goal is loop through this and extract the value of id and name of each advertiser. I would then like to insert the id and name of each advertiser into a custom object. I would use the name field for the name of the advertiser and I have a custom field realationship setup to store the id value.

 

Any help is much appreciated.

  • August 05, 2011
  • Like
  • 0