• raji Galla
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
I have a picklist field on the Contact object. The only choice is 'Yes'. When the user selects Yes, I want Process Builder to create a new record for that Contact on a related object called WPA. Can't seemed to get this set up correctly. Any help would be greatly appreciated. 
Hi All,
Plese find the following  test coverclass  and testclass. The trigger is on 'Vistit_Line_items__C' and logic is finding the check in and check out longitude values of first visit to second visit based on Vist_date__C  field in visit object .
my test class cover only 43% User-added image
Complete class is
public class VisitdistanceCalculat {
    Public void visitdistancemethod(List<Visit_Line_Item__c> vltri){
    List<Visit_Line_Item__c> updatevisitlist  ;
    Date  vistdate ;
    set<id> triid = new set<id>();//inset record id -trigger.new 
  
    for(Visit_Line_Item__c vist : vltri){
         updatevisitlist  = new list<Visit_Line_Item__c>();
        triid.add(vist.id);
   // The first visit record  visitdistance is zero  
       System.debug('********checkintime ******'+ vist.check_in_location__Latitude__s); 
       System.debug('********checkout******'+vist.check_out_Location__Latitude__s );
        System.debug('********vistdate******'+vist.Vist_Date__c);

     
    //if check in value and checkout null add checkin
    If(string.valueof(vist.Check_in_Location__Longitude__s) !=null && string.valueof(vist.Check_Out_Location__Longitude__s) == null)
     {
          System.debug('********checkintime ----------'+ vist.Check_in_Location__Longitude__s ); 
        vist.Camparecheckinlocation__Longitude__s = vist.check_in_location__Longitude__s;
        vist.Camparecheckinlocation__Latitude__s = vist.check_in_location__Latitude__s;
        vistdate=vist.Vist_Date__c;
        updatevisitlist.add(vist);
     }
     
     //if checkin null and checkout value add chekout
     else if(string.valueof(vist.Check_in_Location__Longitude__s) ==null && string.valueof(vist.Check_Out_Location__Longitude__s) != null ){
         System.debug('********checkout----------'+vist.Check_out_Location__Longitude__s ); 
         vist.Camparecheckinlocation__Longitude__s=vist.check_out_Location__Longitude__s;
         vist.Camparecheckinlocation__Latitude__s=vist.check_out_Location__Latitude__s;
           vistdate=vist.Vist_Date__c;
           updatevisitlist.add(vist);       
     }
   /*  //Both checkin and check out null add usergeo location
     else if(string.valueof(vist.Check_in_Location__Longitude__s) ==null && string.valueof(vist.Check_Out_Location__Longitude__s) == null && string.valueof(userlist[0].User_Home_Geolocation__Longitude__s) != null){
        System.debug('********userlocation ----------'+ userlist[0].User_Home_Geolocation__Longitude__s ); 
         vist.Camparecheckinlocation__Longitude__s =userlist[0].User_Home_Geolocation__Longitude__s;
         vist.Camparecheckinlocation__Latitude__s = userlist[0].User_Home_Geolocation__Latitude__s;
           vistdate=vist.Vist_Date__c;
         updatevisitlist.add(vist);
     }*/
     //Both have values add chekin log
      else if(string.valueof(vist.Check_in_Location__Longitude__s) !=null && string.valueof(vist.Check_Out_Location__Longitude__s) != null){
         System.debug('********checkin-----'+vist.Check_in_Location__Longitude__s ); 
         vist.Camparecheckinlocation__Longitude__s=vist.Check_in_Location__Longitude__s;
         vist.Camparecheckinlocation__Latitude__s=vist.Check_in_Location__Latitude__s;
         vistdate=vist.Vist_Date__c;
        updatevisitlist.add(vist);
     }   
  
    }//end triggernew
    
     system.debug('******trigger.newlist****' + updatevisitlist);//user location not there then not do buillogic
     
    List<Visit_Line_Item__c> VisitlineitemList = new List<Visit_Line_Item__c>();
    VisitlineitemList=[select id,Camparecheckinlocation__c,Check_In__c,Check_out__c,
                       Camparecheckinlocation__latitude__s,Camparecheckinlocation__longitude__s , VisitDistance__c,
                       Check_in_Location__c,Check_Out_Location__c,ownerid,Vist_Date__c,Checkin_Time__c,Checkout_Time__c,
                       Account__c,Check_in_Location__longitude__s,Check_Out_Location__longitude__s,check_in_location__latitude__s,check_out_Location__Latitude__s from Visit_Line_Item__c where 
                       ownerid =: UserInfo.getUserId()and       
                       ( Checkin_Time__c != null or Checkout_Time__c != null) and 
                       Vist_Date__c =: vistdate and id not in : triid ];
    system.debug('Today updated recrods of Visitlineitems**********'+ VisitlineitemList);
    system.debug('Today updated recrods of Visitlineitems**********'+ VisitlineitemList.size());
    Map<DateTime, visit_Line_item__c>  unsortmapVistlatest = new Map<DateTime, visit_Line_item__c>();
        
    if(VisitlineitemList.size()>0 ){
     For(visit_Line_item__c lavist : VisitlineitemList){         
          if(lavist.Checkin_Time__c != null){
            unsortmapVistlatest.put( lavist.Checkin_Time__c, lavist);           
          }       
          else
            unsortmapVistlatest.put( lavist.Checkout_Time__c, lavist);
     }
  System.debug('***unsortmap****' + unsortmapVistlatest);
  Map<DateTime, visit_Line_item__c>  mapSortVistlatest = new Map<DateTime, visit_Line_item__c>();
    List<Datetime> mapkeys = new list<Datetime>();
     DateTime dd;//to find size of sortkeys 
      mapkeys.addall(unsortmapVistlatest.keyset());
      mapkeys.sort();
       if(mapkeys.size()>0)
        
        dd=mapkeys.get(mapkeys.size()-1);
        
      system.debug('********mapkeys sortlist**** '+ mapkeys);
      
      for(Datetime keyl:mapkeys){
         visit_Line_item__c vlt = unsortmapVistlatest.get(keyl);
        mapSortVistlatest.put(keyl,vlt);  
          
      }
      List<visit_Line_item__c > requvlist = new  List<visit_Line_item__c>();
        visit_Line_item__c  vlnm = new visit_Line_item__c ();
           vlnm=mapSortVistlatest.get(dd);
         requvlist.add(vlnm);  
       System.debug('*******mapSortVistlatest*** '+ mapSortVistlatest); 
        
        System.debug('*********** latest chin and chout updat records'+ vlnm);
      
      if(requvlist.size()>0 ){
           // convert to radians
           Double dDepartLat;
           Double dDepartLong ;
           
           if(string.valueof(requvlist[0].check_in_location__longitude__s)!= null &&  string.valueof(requvlist[0].check_out_Location__Longitude__s) == null){
               
                dDepartLat = requvlist[0].check_in_location__latitude__s* 3.14159 / 180;        
                dDepartLong = requvlist[0].check_in_location__longitude__s* 3.14159 / 180;
               
           }
            else if(string.valueof(requvlist[0].check_in_location__longitude__s)!= null &&  string.valueof(requvlist[0].check_out_Location__Longitude__s) != null){
                
                dDepartLat = requvlist[0].check_in_location__latitude__s* 3.14159 / 180;        
                dDepartLong = requvlist[0].check_in_location__longitude__s* 3.14159 / 180;
                
            }

           else if(string.valueof(requvlist[0].check_in_location__longitude__s) == null &&  string.valueof( requvlist[0].check_out_Location__Longitude__s) != null){
               
               dDepartLat = requvlist[0].check_out_Location__Latitude__s* 3.14159 / 180;        
               dDepartLong = requvlist[0].check_out_location__longitude__s* 3.14159 / 180;
               
           }
           
           
           System.debug('****Visitlit checkin'+ requvlist[0].check_in_location__latitude__s);   
           System.debug('****Visitlit checkout'+ requvlist[0].check_out_Location__Latitude__s); 
           system.debug('******triggnew** **** chekin***users*==> '+ updatevisitlist[0].Camparecheckinlocation__latitude__S); 
           system.debug('******triggnew****** chekin***user*==> '+ updatevisitlist[0].Camparecheckinlocation__longitude__s);         
        
        Double dArrivalLat = updatevisitlist[0].Camparecheckinlocation__latitude__S* 3.14159 / 180;
        Double dArrivalLong = updatevisitlist[0].Camparecheckinlocation__Longitude__S* 3.14159 / 180;
        
        Double dDeltaLong = dArrivalLong - dDepartLong;
        Double dDeltaLat = dArrivalLat - dDepartLat;
        
        // calculate angle using the haversine formula
        Double dHaversineResult = Math.Sin( dDeltaLat / 2 ) * Math.Sin( dDeltaLat / 2 ) 
                                  + Math.Cos( dDepartLat ) * Math.Cos( dArrivalLat ) 
                                    * Math.Sin( dDeltaLong / 2 ) * Math.Sin( dDeltaLong / 2 );
        
        // calculate distance by multiplying arc-tangent by the planet radius in miles
        Double dDistance = 1.60934 * 3958.76 * 2 * Math.Atan2( Math.Sqrt( dHaversineResult ), Math.Sqrt( 1 - dHaversineResult ) );
        
        System.debug('Distance============ ' + dDistance);

       updatevisitlist[0].VisitDistance__c=dDistance;
     
    }
    
    }
    // the the first record distance is zero i.e VisitlineitemListsoql is zero
    else
        for(visit_Line_item__c vt : vltri){
            vt.VisitDistance__c=0;
            
        }

        
        
    }

}
When i used test.runastest() method at  if condition VisitlineitemList.size()>0 that time system.nullpoint exception error for update dml  statems in class and testclass. following is my testclass
@isTest(SeeAllData=true)

public class TestCreatePlannedDateUpdate{

public static testmethod void VisitDateTest(){
 
      
      
      String[] mnth = new String[12];
        mnth [0] = 'January';
        mnth [1]= 'February';
        mnth [2]= 'March';
        mnth [3]= 'April';
        mnth [4]= 'May';
        mnth [5]= 'June';
        mnth [6]= 'July';
        mnth [7]= 'August';
        mnth [8]= 'September';
        mnth [9]= 'October';
        mnth [10]= 'November';
        mnth [11]= 'December';
    
    Profile p = [SELECT Id FROM Profile WHERE Name='Sales Officer']; 
    
    User u = new User(Alias = 'standt', Email='vkanneganti-5@hotmail.com', 
                      EmailEncodingKey='UTF-8', LastName='Testing', FirstName='T',LanguageLocaleKey='en_US', 
                      LocaleSidKey='en_US', ProfileId = p.Id, 
                      TimeZoneSidKey='America/Los_Angeles', UserName='vkanneganti-5@hotmail.com');
    insert u;
 
 
 
 Visit__c visitPlan = new Visit__c();
        visitPlan.Version__c = 'test';
        Integer nmnthNum = (System.Today().month());
        system.debug('-------'+ nmnthNum);
        if(nmnthNum ==12)
        nmnthNum =1;
        else
        nmnthNum = nmnthNum+1;
        
        String dt= '10/'+nmnthNum+'/2016';
        system.debug('-------'+dt);
        Date d= Date.parse(dt);
        visitPlan.Start_Date__c = d;
        visitPlan.End_Date__c =d+1;
        system.debug('-------'+visitPlan.Start_Date__c);
        visitPlan.Week_Number__c= '2';
        visitPlan.Month__c=mnth[nmnthNum-1];
           
        insert visitPlan;
    
    //fetch login user id
    user loginus=  new user();
    loginus=[select id, name from user where id =:UserInfo.getUserId()];
            //insert account
            Account acc = new account();
            acc.name='testacc';
            insert acc;
            
    
       // only give check in value
        Visit_Line_Item__c vli= new Visit_Line_Item__c();
        vli.Visit_Sequence__c='1';
        //commented below line for remove the Masterdetail relation of Visit and Visitplan casenum 12529
       // vli.Visit__c = visitPlan.Id;
        vli.Vist_Date__c = system.today();     
        vli.Account__c=acc.id; 
   
        insert vli;  
       vli.Check_In_Location__latitude__s = 17.428107699999998;
       vli.Check_In_Location__longitude__s = 78.43966999999999; 
         checkRecursive.runIsBeforeInsert = true;
      update vli;
    
    
     
    //only give checkout location
       Visit_Line_Item__c vli1= new Visit_Line_Item__c();
        vli1.Visit_Sequence__c='1';
        vli1.Vist_Date__c = system.today();
        vli1.Account__c=acc.id;
        vli1.ownerid=loginus.id;
        
        insert vli1;
        vli1.Check_Out_Location__Latitude__s = 78.43966999999999;
        vli1.Check_out_Location__longitude__s = 78.43966999999999;
        checkRecursive.runIsBeforeInsert = true;
        Update vli1;
      
    //both checkin and check out values
     Visit_Line_Item__c vli2= new Visit_Line_Item__c();
        vli2.Visit_Sequence__c='1';
        vli2.Vist_Date__c = system.today();     
        vli2.ownerid=loginus.id;
        vli2.Account__c=acc.id;
    
        insert vli2;    
        vli2.Check_In_Location__latitude__s = 17.428107699999998;
        vli2.Check_In_Location__longitude__s = 78.43966999999999;       
        vli2.Check_Out_Location__Latitude__s = 78.43966999999999;
        vli2.Check_out_Location__longitude__s = 78.43966999999999;
         checkRecursive.runIsBeforeInsert = true;
    Update vli2;
    }
    


}

Thansk and Regards,
Raji
Hi All,

Please provide lates dumps for "Community Cloud Consultant"  Exm.
Thanks in Advance.

Thanks,
Raji 
Hi All,
 
can any one please tell me how to write test code for  remoting method in Apex class.And I am passing argument from page.
Please find my code:
i getting error System.Null point Exception at remote method calling in testclass.

User-added image
Visualforce
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <meta charset="utf-8"/>
    <title>Geocoding service</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
        var geocoder;
        var map;
        //var latitude = place.geometry.location.lat();
        function initialize() {
        //alert (latitude);
          geocoder = new google.maps.Geocoder();
          var latlng = new google.maps.LatLng(37.4419, -122.1419);
          var mapOptions = {
            zoom: 15,
            center: latlng
          }
          map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
          codeAddress();
        }
        
        function codeAddress() {         
          var address = "{!Account.BillingStreet}, " + "{!Account.BillingCity}, " + "{!Account.BillingPostalCode}, " + "{!Account.BillingCountry}";
          alert(address);
          var infowindow = new google.maps.InfoWindow();
          geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                  map: map,
                  position: results[0].geometry.location
                });
                
                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.setContent(address);
                    infowindow.open(map, marker);
                });
                google.maps.event.trigger(marker, "click");
                alert(results[0].geometry.location.lat());
                if (navigator.geolocation) {
                 navigator.geolocation.getCurrentPosition(function(position){
                     lat = position.coords.latitude;
                     lon = position.coords.longitude; 
                     alert('lat =' +lat);
                     var accntLat = results[0].geometry.location.lat();
                     var accntLong = results[0].geometry.location.lng();
                     alert("accntLat11 =" +accntLat);
                     alert("accntLong11 =" +accntLong);
                     // Use Visualforce JavaScript Remoting to query for nearby warehouses      
                     Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.AutoCheckInController.autoCheckIn}', lat, lon, accntLat, accntLong, "{!Account.Name}",
                         function(result, event){
                             if (event.status) {
                                 console.log(result);
                                 //createMap(lat, lon, result);           
                             } else if (event.type === 'exception') {
                                 //exception case code          
                             } else {
                                            
                             }
                          }, 
                          {escape: true}
                      );
                  });
                }
            } else {
              alert('Geocode was not successful for the following reason: ' + status);
            }
          });
        }
        
        google.maps.event.addDomListener(window, 'load', initialize);
        
    </script>
  </head>

  <body>
    <div id="map-canvas" style="width: 1000px; height: 300px"></div>
  </body>
</html>
Class===================
 public static Account recAccount;
    public string Latitude{get; set;}
    
    public AutoCheckInController (ApexPages.StandardController controller) { 
        //recAccount = (Account)Controller.getRecord();
    }

    @RemoteAction
    // Auto checkin the user if the current user's location is in and around 0.5 kms radius of Account/Lead/Retailer address
    global static User_Tracking__c autoCheckIn(Double lat, Double lon, Double accntLat, Double accntLng, String strAccntName) {
              
        System.debug('User Latitude =' +lat);
        System.debug('User Longitude =' +lon);
        
        System.debug('Account Name=' + strAccntName);
        System.debug('Account Latitude =' +accntLat);
        System.debug('Account Longitude =' +accntLng);
        
        // convert to radians
        Double dDepartLat = lat * 3.14159 / 180;
        Double dDepartLong = lon * 3.14159 / 180;
        Double dArrivalLat = accntLat * 3.14159 / 180;
        Double dArrivalLong = accntLng * 3.14159 / 180;
        
        Double dDeltaLong = dArrivalLong - dDepartLong;
        Double dDeltaLat = dArrivalLat - dDepartLat;
        
        // calculate angle using the haversine formula
        Double dHaversineResult = Math.Sin( dDeltaLat / 2 ) * Math.Sin( dDeltaLat / 2 ) 
                                  + Math.Cos( dDepartLat ) * Math.Cos( dArrivalLat ) 
                                    * Math.Sin( dDeltaLong / 2 ) * Math.Sin( dDeltaLong / 2 );
        
        // calculate distance by multiplying arc-tangent by the planet radius in miles
        Double dDistance = 1.60934 * 3958.76 * 2 * Math.Atan2( Math.Sqrt( dHaversineResult ), Math.Sqrt( 1 - dHaversineResult ) );
        
        System.debug('Distance = ' + dDistance);
        
        GeoTagging_Distance__c gtd = GeoTagging_Distance__c.getValues('Geo Tagging');
        
        System.debug('Configured Distance = ' +gtd.Distance__c);
        
        If(dDistance <= gtd.Distance__c)
        {
            
            String strDate = String.valueOf(DateTime.Now());
            System.debug('strDate=' +strDate);
            
            User_Tracking__c recTrack = New User_Tracking__c();
            
            recTrack.User__c = Userinfo.getUserId();
            recTrack.Location__Latitude__s = Decimal.ValueOf(lat);
            recTrack.Location__Longitude__s = Decimal.ValueOf(lon);
            recTrack.Visited_Date__c = strDate;
            recTrack.Account_Name__c = strAccntName;
            //recTrack.Location_Date__c = System.Today();
            try
            {
                Insert recTrack;
                system.debug('@@@'+recTrack);
            }
            Catch(Exception e)
            {
                System.debug('Exception Raised ' +e.getMessage());
            }
        }
        return Null;
    }
}
My test class====================
@isTest
Public class TestClassforAutoCheckInController{

public static testMethod void testMyController() {

//our logic

Account acc = new Account();
    Double lat = 55.04;
    Double lon = 67.98;
    Double accntLat = 67.98;
    Double accntLng  =77.98 ;    
    acc.name = 'test';   
    insert acc;
  account  alist = [select id, name from account where name =: 'test'];
    String strAccntName = alist.id;
     AutoCheckInController.autoCheckIn(lat ,lon ,accntLat,accntLng , strAccntName );
         
    // convert to radians
        Double dDepartLat = lat * 3.14159 / 180;
        Double dDepartLong = lon * 3.14159 / 180;
        Double dArrivalLat = accntLat * 3.14159 / 180;
        Double dArrivalLong = accntLng * 3.14159 / 180;
        Double dDeltaLong = dArrivalLong - dDepartLong;
        Double dDeltaLat = dArrivalLat - dDepartLat;
        // calculate angle using the haversine formula
        Double dHaversineResult = Math.Sin( dDeltaLat / 2 ) * Math.Sin( dDeltaLat / 2 ) 
                                  + Math.Cos( dDepartLat ) * Math.Cos( dArrivalLat ) 
                                    * Math.Sin( dDeltaLong / 2 ) * Math.Sin( dDeltaLong / 2 );
                                    
   // calculate distance by multiplying arc-tangent by the planet radius in miles
        Double dDistance = 1.60934 * 3958.76 * 2 * Math.Atan2( Math.Sqrt( dHaversineResult ), Math.Sqrt( 1 - dHaversineResult ) );
         GeoTagging_Distance__c gtd = GeoTagging_Distance__c.getValues('Geo Tagging');
         If(dDistance <= gtd.Distance__c)
        {
            
            String strDate = String.valueOf(DateTime.Now());
            System.debug('strDate=' +strDate);
            
            User_Tracking__c recTrack = New User_Tracking__c();
            
            recTrack.User__c = Userinfo.getUserId();
            recTrack.Location__Latitude__s = Decimal.ValueOf(lat);
            recTrack.Location__Longitude__s = Decimal.ValueOf(lon);
            date  d = system.today();
             recTrack.Visited_Date__c = string.valueof(d);
            recTrack.Account_Name__c = 'test';
           
            try
            {
                Insert recTrack;
                system.debug('@@@'+recTrack);
            }
            Catch(Exception e)
            {
                System.debug('Exception Raised ' +e.getMessage());
            }
        }
         

}
Thanks in advance,
Raji
 
Hi All,
how to build Angular tags to visualforce tags?
Please find the following code. i didnt get values from script
<apex:page docType="html-5.0">

<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">
{{ firstName + " " + lastName }}
</div>

<script>
var app = angular.module('myApp', []);
app.controller("myCtrl", function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});
</script>

</body>
</html>

</apex:page>
I am getting  output as:      {{ firstName + " " + lastName }}
values are not binding?
Thanks in advance.
Raji
 
I have a picklist field on the Contact object. The only choice is 'Yes'. When the user selects Yes, I want Process Builder to create a new record for that Contact on a related object called WPA. Can't seemed to get this set up correctly. Any help would be greatly appreciated. 
Hi

Im using a URL hack for a lookup field to pre-populate the value when creating new record, unfortunately value being showed in the field is "_HL_ENCODED_/_HL_   _HL__blank_HL_" expected output should be the Name of a record.

Thanks
Hi All,
how to build Angular tags to visualforce tags?
Please find the following code. i didnt get values from script
<apex:page docType="html-5.0">

<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">
{{ firstName + " " + lastName }}
</div>

<script>
var app = angular.module('myApp', []);
app.controller("myCtrl", function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});
</script>

</body>
</html>

</apex:page>
I am getting  output as:      {{ firstName + " " + lastName }}
values are not binding?
Thanks in advance.
Raji