• MnZ321
  • NEWBIE
  • 20 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 24
    Replies
I'm a beginner in webservices and future calls. I have been trying post parameters to an external system (ServiceNow). As of now I'm able to post a generic description field from Salesforce to ServiceNow.

Here's what I have tried so far, trigger....
 
trigger Case2ServiceNow on Case (after insert) {
  AuthCalloutPost.basicAuthCalloutPost(Trigger.newmap.keyset());
}
Apex...
public class AuthCalloutPost1{
public String Response { get; set;}

@future(callout=true)

 public static void basicAuthCalloutPost(Set<Id> caseids){

 //call to generate request body
 String requestbody = generateBody(caseids);
 System.debug('##requestbody##'+requestbody);
 HttpRequest req = new HttpRequest();
 req.setEndpoint('xxx/now/table/incident');
 
 req.setMethod('POST');
 req.setBody(requestbody);
 req.setTimeout(120000);

 String authorizationHeader = 'Basic xxx=';
 req.setHeader('Authorization', authorizationHeader);
 req.setHeader('Accept', 'application/json');
 req.setHeader('Content-Type', 'application/json'); 

 Http http = new Http();
 HTTPResponse res = http.send(req);

 System.debug('##res##'+res);
 System.debug('##res.getBody##'+res.getBody());
 // this.response=res.getBody();
 }
 //This method will generate request body.
 public static String generateBody(set<id> casesids)
 {
       JSONGenerator gen = JSON.createGenerator(true);
       gen.writeStartObject();
       gen.writeFieldName('My_Cases');
       gen.writeStartArray();
       for(Case c : [Select Id, RecordTypeId, RecordType.Name, Subject      
         From Case Where Id IN : casesids]) {
         if(c.RecordType.Name == 'Incident'){
           //define different fields which you want to pass.
           gen.writeStartObject();
           gen.writeStringField('short_description',c.Subject);
           gen.writeEndObject();   
         } 
         else{
         System.debug('not incident');
         }
      }  
           gen.writeEndArray();
           gen.writeEndObject();
           return gen.getAsString(); 
 }

}
I'm trying to post Salesforce Case parameters to the ServiceNow like name, description, because a description is enough to create an incident.
Currently I'm able to create a record in external system, but not able to post the parameters included (short_description in this case). Am I missing something? Thanks in advance.
I would really appreciate if I'm pointed to the right direction. Thanks in advance.
 
  • November 13, 2015
  • Like
  • 0
I'm unable to add a picklist of territories in visualforce page and render table. How do I proceed? Please refer any materials if possibles. Following is my code..
 
public class TrackingPartners{

    public List<Torders__c> orders {get; set;}
    public TrackingPartners() {   
    }
    
    
    public list<Torders__c> getstart() {

    Map<Id,UserTerritory> UserTerritoryCurrentUserMap = new  Map<Id,UserTerritory>([Select u.UserId, u.TerritoryId, u.IsActive, u.Id  From UserTerritory u Where 

u.isActive=true and u.userId =: UserInfo.getUserId()]);
    system.debug('-----UserTerritoryCurrentUserMap SIZE-------'+UserTerritoryCurrentUserMap.size());
    
    
    set<Id> TerritoryIdSet = new set<Id>();
    for(UserTerritory ut:UserTerritoryCurrentUserMap.values())
    {
          TerritoryIdSet.add(ut.TerritoryId);
    }    
    
    List<Territory> childTerritories = [Select Id from Territory where ParentTerritoryID in :TerritoryIdSet];
    
    for(Territory ct : childTerritories) {
            TerritoryIdSet.add(ct.Id);
        }
    
    

    list<Group> map_group = [Select Id, RelatedId from Group where (Type='Territory' OR Type='TerritoryAndSubordinates') AND RelatedId IN : TerritoryIdSet];
    system.debug('-----map_group -------'+map_group);
   




    List<SUBSCR_SYSTEMS__c> lst_PartnersAcc = [SELECT LEGACY_CUST_NUM__c,Account__c
                                                 FROM SUBSCR_SYSTEMS__c WHERE Account__c IN                                                  
                                                 (Select  AccountId from AccountShare where ( UserOrGroupId IN : map_group OR  UserOrGroupId =:UserInfo.getUserId()) 

AND RowCause IN ('Territory', 'TerritoryManual', 'TerritoryRule'))
                                                 ];
                                               
    
                                                
                                                 
    Set<String>tempList = new Set<String>();

    for(SUBSCR_SYSTEMS__c s : lst_PartnersAcc) {
        tempList.add(s.LEGACY_CUST_NUM__c);

        
    }
    
    system.debug('-----tempList-------'+tempList);

    
    List<Torders__c> orders =[SELECT Torders__c,id, 

customer_order_number__c,name,order_no__c,account__c,account__r.name,number_of_line_items__c,number_of_items_open__c,lines_items_shipped__c,number_of_items_delivered__

c,order_date__c,Bill_to__c,Payer__c,Ship_To__c,Sold_to__c FROM Torders__c   
                                 WHERE  Bill_to__c IN: tempList OR
                                        Payer__c IN: tempList OR 
                                        Ship_To__c IN: tempList OR
                                        Sold_to__c IN: tempList
                                     ]; 
                                     system.debug('-----orders-------'+orders);

     return orders;                                
  }                                
  
}

and the VF ...
<apex:page Controller="TrackingPartners" >
<apex:stylesheet value="{!URLFOR($Resource.jQueryDataTablesZip, 'jQueryDataTablesZip/css/jquery.dataTables.css')}"/>

 <apex:pageBlock >
         <apex:pageBlockTable value="{!start}" var="o" styleClass="dataTable">
                <apex:column >
                        <apex:facet name="header">Order No.</apex:facet>                        
                 <a href="Class?id={!o.id}" onMouseOver="setTimeout(function(){awin=window.open('OrderLines?id={!o.id}','Order Lines','height=300, 

width=1000, left=400, scrollbars=yes');},1000);" onmouseout="awin.close();">{!o.Torders__c}</a>
           
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Account</apex:facet>
                        <apex:outputText value="{!o.account__r.name}"/>
                </apex:column>                
                <apex:column >
                        <apex:facet name="header">Partner No.</apex:facet>
                        <apex:outputText value="{!o.Ship_To__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Customer PO</apex:facet>
                        <apex:outputText value="{!o.customer_order_number__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Open</apex:facet>
                        <apex:outputText value="{!o.number_of_items_open__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Shipped</apex:facet>
                        <apex:outputText value="{!o.lines_items_shipped__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Delivered</apex:facet>
                        <apex:outputText value="{!o.number_of_items_delivered__c}"/>
                </apex:column>   
                <apex:column >
                        <apex:facet name="header">Order Date</apex:facet>
                        <apex:outputText value="{0, date, MM/d/yyyy}"> 
                        <apex:param value="{!o.order_date__c}"/>
                        </apex:outputText>                         
                </apex:column>                                                                                               
        </apex:pageBlockTable>
        <apex:form>
        <apex:selectList id="mgr" value="" size="1" title="Manager">
                        <apex:selectOptions value=""></apex:selectOptions>
        </apex:selectList>
        </apex:form>
<script type="text/javascript" language="javascript" src="{!URLFOR($Resource.jQueryDataTablesZip, 'jQueryDataTablesZip/js/jquery.js')}"></script>
<script type="text/javascript" language="javascript" src="{!URLFOR($Resource.jQueryDataTablesZip, 'jQueryDataTablesZip/js/jquery.dataTables.js')}"></script>
     
 </apex:pageBlock>    

</apex:page>
Thanks in advance!
 
  • February 26, 2015
  • Like
  • 0
I'm unable to add a picklist of territories in visualforce page and render table. How do I proceed? Please refer any materials if possibles. Following is my code..
 
public class TrackingPartners{

    public List<Torders__c> orders {get; set;}
    public TrackingPartners() {   
    }
    
    
    public list<Torders__c> getstart() {

    Map<Id,UserTerritory> UserTerritoryCurrentUserMap = new  Map<Id,UserTerritory>([Select u.UserId, u.TerritoryId, u.IsActive, u.Id  From UserTerritory u Where 

u.isActive=true and u.userId =: UserInfo.getUserId()]);
    system.debug('-----UserTerritoryCurrentUserMap SIZE-------'+UserTerritoryCurrentUserMap.size());
    
    
    set<Id> TerritoryIdSet = new set<Id>();
    for(UserTerritory ut:UserTerritoryCurrentUserMap.values())
    {
          TerritoryIdSet.add(ut.TerritoryId);
    }    
    
    List<Territory> childTerritories = [Select Id from Territory where ParentTerritoryID in :TerritoryIdSet];
    
    for(Territory ct : childTerritories) {
            TerritoryIdSet.add(ct.Id);
        }
    
    

    list<Group> map_group = [Select Id, RelatedId from Group where (Type='Territory' OR Type='TerritoryAndSubordinates') AND RelatedId IN : TerritoryIdSet];
    system.debug('-----map_group -------'+map_group);
   




    List<SUBSCR_SYSTEMS__c> lst_PartnersAcc = [SELECT LEGACY_CUST_NUM__c,Account__c
                                                 FROM SUBSCR_SYSTEMS__c WHERE Account__c IN                                                  
                                                 (Select  AccountId from AccountShare where ( UserOrGroupId IN : map_group OR  UserOrGroupId =:UserInfo.getUserId()) 

AND RowCause IN ('Territory', 'TerritoryManual', 'TerritoryRule'))
                                                 ];
                                               
    
                                                
                                                 
    Set<String>tempList = new Set<String>();

    for(SUBSCR_SYSTEMS__c s : lst_PartnersAcc) {
        tempList.add(s.LEGACY_CUST_NUM__c);

        
    }
    
    system.debug('-----tempList-------'+tempList);

    
    List<Torders__c> orders =[SELECT Torders__c,id, 

customer_order_number__c,name,order_no__c,account__c,account__r.name,number_of_line_items__c,number_of_items_open__c,lines_items_shipped__c,number_of_items_delivered__

c,order_date__c,Bill_to__c,Payer__c,Ship_To__c,Sold_to__c FROM Torders__c   
                                 WHERE  Bill_to__c IN: tempList OR
                                        Payer__c IN: tempList OR 
                                        Ship_To__c IN: tempList OR
                                        Sold_to__c IN: tempList
                                     ]; 
                                     system.debug('-----orders-------'+orders);

     return orders;                                
  }                                
  
}
===========================================================================================




<apex:page Controller="TrackingPartners" >
<apex:stylesheet value="{!URLFOR($Resource.jQueryDataTablesZip, 'jQueryDataTablesZip/css/jquery.dataTables.css')}"/>

 <apex:pageBlock >
         <apex:pageBlockTable value="{!start}" var="o" styleClass="dataTable">
                <apex:column >
                        <apex:facet name="header">Order No.</apex:facet>                        
                 <a href="Class?id={!o.id}" onMouseOver="setTimeout(function(){awin=window.open('OrderLines?id={!o.id}','Order Lines','height=300, 

width=1000, left=400, scrollbars=yes');},1000);" onmouseout="awin.close();">{!o.Torders__c}</a>
           
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Account</apex:facet>
                        <apex:outputText value="{!o.account__r.name}"/>
                </apex:column>                
                <apex:column >
                        <apex:facet name="header">Partner No.</apex:facet>
                        <apex:outputText value="{!o.Ship_To__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Customer PO</apex:facet>
                        <apex:outputText value="{!o.customer_order_number__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Open</apex:facet>
                        <apex:outputText value="{!o.number_of_items_open__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Shipped</apex:facet>
                        <apex:outputText value="{!o.lines_items_shipped__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Delivered</apex:facet>
                        <apex:outputText value="{!o.number_of_items_delivered__c}"/>
                </apex:column>   
                <apex:column >
                        <apex:facet name="header">Order Date</apex:facet>
                        <apex:outputText value="{0, date, MM/d/yyyy}"> 
                        <apex:param value="{!o.order_date__c}"/>
                        </apex:outputText>                         
                </apex:column>                                                                                               
        </apex:pageBlockTable>
        <apex:form>
        <apex:selectList id="mgr" value="" size="1" title="Manager">
                        <apex:selectOptions value=""></apex:selectOptions>
        </apex:selectList>
        </apex:form>
<script type="text/javascript" language="javascript" src="{!URLFOR($Resource.jQueryDataTablesZip, 'jQueryDataTablesZip/js/jquery.js')}"></script>
<script type="text/javascript" language="javascript" src="{!URLFOR($Resource.jQueryDataTablesZip, 'jQueryDataTablesZip/js/jquery.dataTables.js')}"></script>
     
 </apex:pageBlock>    

</apex:page>
Thanks in advance!
 
  • February 26, 2015
  • Like
  • 0
Hi All. How to query for accounts in child territories? I can't seem to find any documentation for this 

Currently I'm able to query for the accounts in the current logged-in user's territrry only, but not from the sibling territories.

Following is my code...
 
public class TrackingPartners{

    public List<orders__c> orders {get; set;}
    public TrackingPartners() {   
    }
    
    
    public list<orders__c> getstart() {

    Map<Id,UserTerritory> UserTerritoryCurrentUserMap = new  Map<Id,UserTerritory>([Select u.UserId, u.TerritoryId, u.IsActive, u.Id  From UserTerritory u Where u.isActive=true and u.userId =: UserInfo.getUserId()]);

    
    
    set<Id> TerritoryIdSet = new set<Id>();
	
    for(UserTerritory ut:UserTerritoryCurrentUserMap.values())
    {
          TerritoryIdSet.add(ut.TerritoryId);
    }    

      list<Group> map_group = [Select Id, RelatedId from Group where (Type='Territory' OR Type='TerritoryAndSubordinates') AND RelatedId IN : TerritoryIdSet];


    List<SYSTEMS__c> lst_PartnersAcc = [SELECT CUST_NUM__c,Account__c
                                                 FROM SYSTEMS__c WHERE Account__c IN                                                  
                                                 (Select  AccountId from AccountShare where ( UserOrGroupId IN : map_group OR  UserOrGroupId =:UserInfo.getUserId()) AND RowCause IN ('Territory', 'TerritoryManual', 'TerritoryRule'))
                                                 ];

                                                 
    Set<String>tempList = new Set<String>();

    for(SYSTEMS__c s : lst_PartnersAcc) {
        tempList.add(s.CUST_NUM__c);

        
    }
    
    List<orders__c> orders =[SELECT Orders__c,id FROM orders__c   
                                 WHERE  Bill_to__c IN: tempList OR
                                        Payer__c IN: tempList OR 
                                        Ship_To__c IN: tempList OR
                                        Sold_to__c IN: tempList
                                     ]; 
                                    

     return orders;                                
  }                                
  
}

How to query accounts from the child territory? Any reference would be great. Thanks in advance! 
  • February 20, 2015
  • Like
  • 0
orders__c is a MD child with accounts.
How do I get orders__c(parent) and order_lines__c(child) records according to the logged in user's territory?
For now I'm retrieving parent and child from a parent ID. In what order do I need to query territory, accounthshare, my custom object?



 
  • December 09, 2014
  • Like
  • 0
Following is apex class
public class OrderTrackingList{
    public OrderTrackingList(ApexPages.StandardController controller) {}
    public list<wrapgroupwise> singlegroup;
    public List<wrapgroupwise> getStartHere(){
    singlegroup= new List<wrapgroupwise>();
    List<orders__c> tempacc=[SELECT Orders__c,CreatedBy.FirstName,CreatedDate, number_of_line_items__c, CurrencyIsoCode,account__r.name,contract__r.ContractNumber,customer_order_number__c,invoices__c,my_view__c,order_acknowlegment__c,order_date__c,order_value__c, order_no__c, requested_delivery_date__c,shipments__c,Id,Name,
                                 (SELECT Id, name,calculated_estimated_delivery_date__c,order_number__c,status__c,planned_ship_date__c,material_name__c,material_no__c, quantity_ordered__c From Order_Lines__r),
                                 (SELECT Id,Name,Order_Number__c,Actual_Delivery_Date__c, estimated_delivery_date__c,Shipment_Number__r.name, Shipment_Number__r.carrrier_name__c, Shipment_Number__r.carrier_website__c,Shipment_Number__r.tracking_number__c,quantity_shipped__c  From Shipment_Lines__r)
                                 FROM orders__c where id=:ApexPages.currentPage().getParameters().get('id')];
 
     for(Integer i=0; i<tempacc.size() ; i++){
        List <order_lines__c> tempOrderLines = tempacc[i].order_lines__r;
        List <shipment_lines__c> tempShipmentLines = tempacc[i].shipment_lines__r;
        
         System.debug('temp order '+tempacc.size());
         System.debug('temp order lines'+tempOrderLines.size());
         System.debug('temp shipment lines'+tempShipmentLines.size());
         
      if(tempOrderLines.size()==0 && tempShipmentLines.size()==0){
                  singlegroup.add(new wrapgroupwise(tempacc[i],null,null)); 
        }
        else{
         
         if(tempShipmentLines.size()==0)
         {
              if(tempOrderLines[i].status__c=='Open')
               {
                   tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
               }
                                 
            singlegroup.add(new wrapgroupwise(tempacc[i],tempOrderLines,null)); 
                  
          }//if condition for tempShipmentLines size check    
         else
         {
         //Estimated Delivery Date done

           if(tempOrderLines[i].status__c=='Open')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
           }
           if(tempOrderLines[i].status__c=='Invoiced')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }
           if(tempOrderLines[i].status__c=='Shipped but not billed')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }           
     
          singlegroup.add( new wrapgroupwise(tempacc[i],tempOrderLines,tempShipmentLines)); 
         }//size check of temp shipping order  
    
        }
       }
    return singlegroup; 
   }
     public class wrapgroupwise
     {
        public List<order_lines__c> con {get;set;}
        public orders__c acc {get;set;}
        public List<shipment_lines__c> opp {get;set;}
    
         public wrapgroupwise( orders__c a , list<order_lines__c> c,list<shipment_lines__c> o)
         {
            acc=a;
            con=c;
            opp=o;
          } 
      } 
}
Following is my attempted Test Class. If and else conditions are not being covered. How to cover?
@isTest
public class OrderTrackingList_Test{ 
    static testMethod void coverCode(){
             
              Profile pf= [SELECT Id FROM Profile WHERE name= 'System Administrator' LIMIT 1];
              
              Account acc = new Account(Name='ABC Corp.');
              insert acc;
              //System.assertEquals('ABC Corp.', acc.name);
              
              orders__c tempOrder = new orders__c();
              tempOrder.name = '0001234567';
              tempOrder.account__c = acc.id;
              insert tempOrder;
      
              List <orders__c> testO = [select id, name from orders__c limit 1];
              System.assertEquals(1, testO.size());
        
         	  order_lines__c tempOL = new order_lines__c();          
              tempOL.Name = '10';
              tempOL.number_of_order_lines__c = tempOrder.id;
              tempOL.status__c='Open';
        	  tempOL.calculated_estimated_delivery_date__c=date.today();
        	  tempOL.planned_ship_date__c = date.today();
              insert tempOL;
              
 
        	   
              order_lines__c tempOL2 = new order_lines__c();
              tempOL2.Name = '10';
              tempOL2.number_of_order_lines__c = tempOrder.id;
              tempOL2.status__c='Shipped but not billed';
        	  tempOL2.calculated_estimated_delivery_date__c=date.today();
              insert tempOL2;
        
              List <order_lines__c> testOL = [select id, name, status__c, number_of_order_lines__c  from order_lines__c limit 1 ];/*where id=:ApexPages.currentPage().getParameters().get('id')*/
              System.assertEquals(1, testOL.size());

              
              shipment_lines__c tempSL = new shipment_lines__c();
              tempSL.Name = '10'; 
              tempSL.CurrencyIsoCode = 'USD'; 
        	  tempSL.estimated_delivery_date__c = date.today();
              insert tempSL;
        

        
        
        	  List <shipment_lines__c> testSL = [select name, CurrencyIsoCode  from shipment_lines__c limit 1];
              System.assertEquals(1, testSL.size());

              Test.startTest();
        	  PageReference pageRef =Page.OrderTrackingList;
        	  pageRef.getParameters().put('id', tempOrder.id);
              Test.setCurrentPage(pageRef);

              OrderTrackingList gepwO  = new OrderTrackingList(new ApexPages.StandardController(tempOrder));  
 		      gepwO.getStartHere();
        	  Test.stopTest();
    }
    static testMethod void coverCode2(){
    	Account acc1 = new Account(Name='GE. Corp.');
        insert acc1;
              
        orders__c tempOrder1 = new orders__c();
        tempOrder1.name = '0001234567';
        tempOrder1.account__c = acc1.id;
        insert tempOrder1;
        
             order_lines__c tempOL1 = new order_lines__c();          
              tempOL1.Name = '10';
              tempOL1.number_of_order_lines__c = tempOrder1.id;
              tempOL1.status__c='Invoiced';
        	  tempOL1.calculated_estimated_delivery_date__c=date.today();
        	  tempOL1.planned_ship_date__c = date.today();
              insert tempOL1;
        
        	  shipment_lines__c tempSL1 = new shipment_lines__c();
              tempSL1.Name = '10'; 
              tempSL1.CurrencyIsoCode = 'USD'; 
        	  tempSL1.estimated_delivery_date__c = date.today();
              insert tempSL1;        
        
        
        
    }
  
    }
Actually only the if-else statements are not being covered. How to cover them?

  • October 10, 2014
  • Like
  • 0
I'm unable to have code coverage. Wrote a test class that has 24% coverage. How should I test loops and conditional statements?
public class OrderTrackingList{
    public OrderTrackingList(ApexPages.StandardController controller) {}
    public list<wrapgroupwise> singlegroup;
    public List<wrapgroupwise> getStartHere(){
    singlegroup= new List<wrapgroupwise>();
    List<orders__c> tempacc=[SELECT Id,Name FROM orders__c where id=:ApexPages.currentPage().getParameters().get('id')];
 
     for(Integer i=0; i<tempacc.size() ; i++){
        List <order_lines__c> tempOrderLines=[SELECT Id,name From order_lines__c Where order_number__c=:tempacc[i].id];
        List <shipment_lines__c> tempShipmentLines=[SELECT Id,Name From shipment_lines__c Where Order_Number__c=:tempacc[i].id];
         
      if(tempOrderLines.size()==0 && tempShipmentLines.size()==0){
              singlegroup.add(new wrapgroupwise(tempacc[i],null,null)); 
        }
        else{
         
         if(tempShipmentLines.size()==0)
         {
              if(tempOrderLines[i].status__c=='Open')
               {
                   tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
               }
                                 
            singlegroup.add(new wrapgroupwise(tempacc[i],tempOrderLines,null)); 
                  
          }   
         else
         {
    
           if(tempOrderLines[i].status__c=='Open')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
           }
           if(tempOrderLines[i].status__c=='Invoiced')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }
           if(tempOrderLines[i].status__c=='Shipped but not billed')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }           
     
          singlegroup.add( new wrapgroupwise(tempacc[i],tempOrderLines,tempShipmentLines)); 
         }
    
        }
       }
      return singlegroup; 
      }
     public class wrapgroupwise
     {
        public List<order_lines__c> con {get;set;}
        public orders__c acc {get;set;}
        public List<shipment_lines__c> opp {get;set;}
    
         public wrapgroupwise( orders__c a , list<order_lines__c> c,list<shipment_lines__c> o)
         {
            acc=a;
            con=c;
            opp=o;
          } 
      } 
     }
> ========================TEST CLASS===========================
@isTest
     public class GE_PW_OrderTrackingList_Test{ 
    static testMethod void coverCode(){
             
              //GE_PW_OrderTrackingList.wrapgroupwise wgw = new            GE_PW_OrderTrackingList.wrapgroupwise();
              Profile pf= [SELECT Id FROM Profile WHERE name= 'System Administrator' LIMIT 1];
              
              Account acc = new Account(Name='ABC Corp.');
              insert acc;
              System.assertEquals('ABC Corp.', acc.name);
              
              gew_orders__c tempOrder = new gew_orders__c();
              tempOrder.name = '0001234567';
              tempOrder.gew_account__c = acc.id;
              insert tempOrder;
              System.assertEquals('0001234567', tempOrder.name);
              
             
              gew_order_lines__c tempOL = new gew_order_lines__c();
              tempOL.Name = '10';
              tempOL.gew_number_of_order_lines__c = tempOrder.id;
              insert tempOL;
              System.assertEquals('10', tempOL.name);
              
              gew_shipment_lines__c tempSL = new gew_shipment_lines__c();
              tempSL.Name = '10'; 
              tempSL.CurrencyIsoCode = 'USD'; 
              insert tempSL;
              
              System.assertEquals('USD', tempSL.CurrencyIsoCode);
 
             GE_PW_OrderTrackingList gepwO = new GE_PW_OrderTrackingList(new ApexPages.StandardController(tempOrder));  
        	 GE_PW_OrderTrackingList gepwOL = new GE_PW_OrderTrackingList(new ApexPages.StandardController(tempOL));
             GE_PW_OrderTrackingList gepwSL = new GE_PW_OrderTrackingList(new ApexPages.StandardController(tempSL));
 			 gepwO.getStartHere();
             //gepwOL.singlegroup.add(gepwOL);
        	// gepwSL.singlegroup.add(gepwSL);
            // gepwO.singlegroup.add(gepwO);
            }
       }

What am I missing? Please guide.
Thanks.

  • October 09, 2014
  • Like
  • 0
Following is my apex class. I keep getting 0 coverage and keep getting this error  Error: Compile Error: Constructor not defined:
public class OrderTrackingList{
    public OrderTrackingList(ApexPages.StandardController controller) {}
    public list<wrapgroupwise> singlegroup;
    public List<wrapgroupwise> getStartHere(){
    singlegroup= new List<wrapgroupwise>();
    List<orders__c> tempacc=[SELECT Id,Name FROM orders__c where id=:ApexPages.currentPage().getParameters().get('id')];
 
     for(Integer i=0; i<tempacc.size() ; i++){
        List <order_lines__c> tempOrderLines=[SELECT Id,name From order_lines__c Where order_number__c=:tempacc[i].id];
        List <shipment_lines__c> tempShipmentLines=[SELECT Id,Name From shipment_lines__c Where Order_Number__c=:tempacc[i].id];
         
      if(tempOrderLines.size()==0 && tempShipmentLines.size()==0){
              singlegroup.add(new wrapgroupwise(tempacc[i],null,null)); 
        }
        else{
         
         if(tempShipmentLines.size()==0)
         {
              if(tempOrderLines[i].status__c=='Open')
               {
                   tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
               }
                                 
            singlegroup.add(new wrapgroupwise(tempacc[i],tempOrderLines,null)); 
                  
          }   
         else
         {
    
           if(tempOrderLines[i].status__c=='Open')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
           }
           if(tempOrderLines[i].status__c=='Invoiced')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }
           if(tempOrderLines[i].status__c=='Shipped but not billed')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }           
     
          singlegroup.add( new wrapgroupwise(tempacc[i],tempOrderLines,tempShipmentLines)); 
         }
    
        }
       }
    return singlegroup; 
   }
     public class wrapgroupwise
     {
        public List<order_lines__c> con {get;set;}
        public orders__c acc {get;set;}
        public List<shipment_lines__c> opp {get;set;}
    
         public wrapgroupwise( orders__c a , list<order_lines__c> c,list<shipment_lines__c> o)
         {
            acc=a;
            con=c;
            opp=o;
          } 
      } 
}
And following is my Test Class:

@isTest
public class OrderTrackingList_Test{ 
    static testMethod void coverCode(){
              OrderTrackingList ot = new OrderTrackingList();
              ApexPages.StandardController sc = new ApexPages.standardController(ot);  
             
              
              //GE_PW_OrderTrackingList.wrapgroupwise wgw = new GE_PW_OrderTrackingList.wrapgroupwise();
              Profile pf= [SELECT Id FROM Profile WHERE name= 'System Administrator' LIMIT 1];
              
              Account acc = new Account(Name='ABC Corp.');
              insert acc;
              
              orders__c tempOrder = new orders__c();
              tempOrder.name = '0001234567';
              tempOrder.account__c = acc.id;
              insert tempOrder;
              
              List<orders__c> orderList = [SELECT Id, Name FROM orders__c limit 1];
              ApexPages.StandardController sc = new ApexPages.standardController(orderList ); 
              
              order_lines__c tempOL = new order_lines__c();
              tempOL.Name = '10';
              tempOL.number_of_order_lines__c = tempOrder.id;
              insert tempOL;
              
              shipment_lines__c tempSL = new shipment_lines__c();
              tempSL.Name = '10'; 
              tempSL.CurrencyIsoCode = 'USD'; 
              insert tempSL;
                                        

     }
    }

How can I remove the ERROR Compile Error: Constructor not defined. and also make data coverage

Thanks in advance
  • October 09, 2014
  • Like
  • 0
I have two custom objects lookup to Accounts object. Accounts and Users are assigned manually in my org. How to I control their visibility/security according to territories?

Are there any samples that I refer to? That would be very helpful.

Thanks.
  • September 28, 2014
  • Like
  • 0
This is one of few situations I came across : How would you import csv files into Salesforce from an external source that are kept on a FTP server?
I have a picklist called Status, displayed in a Visualforce table with fields like ..

Closed
Open
Critical
How can make all fields GREEN except the ones that are Critical RED? I have tried this code so far... 

<style>
.errorClass {
    background-color: red;
}
.normalClass {
    background-color: green;
}
</style>
=================================
<apex:pageBlock>
    <apex:pageBlockTable value="{!fb}" var="item">
        <apex:column value="{!item.name}"
                     styleClass="{!IF(item.status__c == 'Critical','errorClass','normalClass')}"/>
        <apex:column value="{!item.status__c}"
                     styleClass="{!IF(item.status__c == 'Critical','errorClass','normalClass')}"/>
    </apex:pageBlockTable>
</apex:pageBlock>
=================================
public class dataTableCon {
    List<Feedback__c> fb;
     public List<Feedback__c> getAccounts() {
        if(fb== null) fb= [select Name, Description__c, Importance__c, Resolution__c, Status__c,Owner.name from Feedback__c];
        return fb;
    }
}
=================================
ERROR..
Error: Formula expression is required for attribute value in <apex:pageBlockTable> in vf_table at line 49 column 56
  • April 16, 2014
  • Like
  • 0
I have a picklist called Status, displayed in a Visualforce table with fields like ..

Closed
Open
Critical

  <div id="col1">
    <apex:column >
        <apex:facet name="header">Status</apex:facet>     
        <apex:outputText value="{!account.Status__c}"/>
    </apex:column>
  </div>

How can make all fields GREEN except the ones that are Critical RED? Thanks.
  • April 16, 2014
  • Like
  • 0
Wondering if its possible to send HTML emails only from a trigger. Any help or reference would be helpful. Thanks
  • April 16, 2014
  • Like
  • 0
“Have been trying to learn Javascript Remoting since hours. I have manipulated this example to display a table of records with remoting an apex class. Following is the controller and VF.. My controller pulls all records from custom object Feedback. But i'm unable to display in VF. Please guide.

global with sharing class AccountRemoter {

public String accountName { get; set; }
public Feedback__c account { get; set; }
public AccountRemoter() { }

@RemoteAction
global static List<Feedback__c> getAccount(String accountName) {
List<Feedback__c> account = [SELECT Name FROM Feedback__c ];
return account;
}
}
and the Visualforce page...

<apex:page controller="AccountRemoter">
<script type="text/javascript">
function getRemoteAccount() {
    var accountName = document.getElementById('acctSearch').value;

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.AccountRemoter.getAccount}',
        accountName,
        function(result, event){
            if (event.status) {
                // Get DOM IDs for HTML and Visualforce elements like this
                document.getElementById('remoteAcctId').innerHTML = result.Id
                document.getElementById(
                    "{!$Component.block.blockSection.secondItem.acctNumEmployees}"
                    ).innerHTML = result.NumberOfEmployees;
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML =
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
            }
         },
         {escape: true}
     );
   }
  </script>

    <input id="acctSearch" type="text"/>
    <button onclick="getRemoteAccount()">Get Feedbacks</button>
    <div id="responseErrors"></div>

    <apex:pageBlock id="block">
    <apex:pageBlockSection id="blockSection" columns="2">
        <apex:pageBlockSectionItem id="firstItem">
            <span id="remoteAcctId"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="secondItem">
            <apex:outputText id="acctNumEmployees"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:page>
The closest to a table on click of the "Get Feedback" button, I have achieved so far with undefined results.... enter image description here

Any help will be appreciated. Thanks

UPDATE: Fields in Feedback

Client_Feedback_App__c

Description__c

Importance__c

Resolution__c

Status__c

Summary__c
  • April 15, 2014
  • Like
  • 0
Whenever I create a custom object without the use of wizard it doesn't appear in the list of objects to be able to add it as tab. Did I miss any step? Or should I always use the wizard?I didn't reached governor limits for number of tabs also. Thanks
  • February 20, 2014
  • Like
  • 0
Can we use a wrapper class to control style in visualforce? I couldn't find any documentation. Could very well be a pipe dream, but worth asking!
  • February 12, 2014
  • Like
  • 1
Imagine this scenario...customer calls sales rep and automatically customer details are on screen.Can this be made possible? Has this been already been implemented?
  • February 12, 2014
  • Like
  • 0
How to display a picklist combining picklists from two Salesforce accounts (one company has two branches). For eg.,

Salesforce Account picklist 1
Item 1
Item 3

Salesforce Account picklist 2
Item 2
Item 4

Combined picklist
Item 1
Item 2
Item 3
Item 4

What feature do I have to use? Is Salesforce to Salesforce one option? How far can I achieve this without any coding?
  • February 07, 2014
  • Like
  • 0
The VF that I'm sharing is working perfectly. Can any body explain me how this VF is actually working? That would be great help. Thanks !

<apex:page standardController="account" recordSetVar="accounts" sidebar="false" showHeader="false">
    <apex:panelGrid columns="2">
        <apex:form >
            <apex:pageBlock >
                <apex:pageBlockTable value="{!accounts}" var="a">
                    <apex:column headerValue="Name" >
                        <apex:commandLink value="{!a.name}" reRender="out">
                            <apex:param name="id" value="{!a.id}"/>
                        </apex:commandLink>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:form>
        <apex:outputPanel id="out">
            <apex:detail subject="{!$CurrentPage.parameters.id}" relatedList="false" title="false"/>
        </apex:outputPanel>
    </apex:panelGrid>
</apex:page>
  • January 23, 2014
  • Like
  • 0
Can anybody help me with a Visualforce Search Box on user object searchable on user's first name or last name. 
Thanks in advance.
MNZ

  • January 23, 2014
  • Like
  • 0
Can we use a wrapper class to control style in visualforce? I couldn't find any documentation. Could very well be a pipe dream, but worth asking!
  • February 12, 2014
  • Like
  • 1
I'm a beginner in webservices and future calls. I have been trying post parameters to an external system (ServiceNow). As of now I'm able to post a generic description field from Salesforce to ServiceNow.

Here's what I have tried so far, trigger....
 
trigger Case2ServiceNow on Case (after insert) {
  AuthCalloutPost.basicAuthCalloutPost(Trigger.newmap.keyset());
}
Apex...
public class AuthCalloutPost1{
public String Response { get; set;}

@future(callout=true)

 public static void basicAuthCalloutPost(Set<Id> caseids){

 //call to generate request body
 String requestbody = generateBody(caseids);
 System.debug('##requestbody##'+requestbody);
 HttpRequest req = new HttpRequest();
 req.setEndpoint('xxx/now/table/incident');
 
 req.setMethod('POST');
 req.setBody(requestbody);
 req.setTimeout(120000);

 String authorizationHeader = 'Basic xxx=';
 req.setHeader('Authorization', authorizationHeader);
 req.setHeader('Accept', 'application/json');
 req.setHeader('Content-Type', 'application/json'); 

 Http http = new Http();
 HTTPResponse res = http.send(req);

 System.debug('##res##'+res);
 System.debug('##res.getBody##'+res.getBody());
 // this.response=res.getBody();
 }
 //This method will generate request body.
 public static String generateBody(set<id> casesids)
 {
       JSONGenerator gen = JSON.createGenerator(true);
       gen.writeStartObject();
       gen.writeFieldName('My_Cases');
       gen.writeStartArray();
       for(Case c : [Select Id, RecordTypeId, RecordType.Name, Subject      
         From Case Where Id IN : casesids]) {
         if(c.RecordType.Name == 'Incident'){
           //define different fields which you want to pass.
           gen.writeStartObject();
           gen.writeStringField('short_description',c.Subject);
           gen.writeEndObject();   
         } 
         else{
         System.debug('not incident');
         }
      }  
           gen.writeEndArray();
           gen.writeEndObject();
           return gen.getAsString(); 
 }

}
I'm trying to post Salesforce Case parameters to the ServiceNow like name, description, because a description is enough to create an incident.
Currently I'm able to create a record in external system, but not able to post the parameters included (short_description in this case). Am I missing something? Thanks in advance.
I would really appreciate if I'm pointed to the right direction. Thanks in advance.
 
  • November 13, 2015
  • Like
  • 0
Hi All. How to query for accounts in child territories? I can't seem to find any documentation for this 

Currently I'm able to query for the accounts in the current logged-in user's territrry only, but not from the sibling territories.

Following is my code...
 
public class TrackingPartners{

    public List<orders__c> orders {get; set;}
    public TrackingPartners() {   
    }
    
    
    public list<orders__c> getstart() {

    Map<Id,UserTerritory> UserTerritoryCurrentUserMap = new  Map<Id,UserTerritory>([Select u.UserId, u.TerritoryId, u.IsActive, u.Id  From UserTerritory u Where u.isActive=true and u.userId =: UserInfo.getUserId()]);

    
    
    set<Id> TerritoryIdSet = new set<Id>();
	
    for(UserTerritory ut:UserTerritoryCurrentUserMap.values())
    {
          TerritoryIdSet.add(ut.TerritoryId);
    }    

      list<Group> map_group = [Select Id, RelatedId from Group where (Type='Territory' OR Type='TerritoryAndSubordinates') AND RelatedId IN : TerritoryIdSet];


    List<SYSTEMS__c> lst_PartnersAcc = [SELECT CUST_NUM__c,Account__c
                                                 FROM SYSTEMS__c WHERE Account__c IN                                                  
                                                 (Select  AccountId from AccountShare where ( UserOrGroupId IN : map_group OR  UserOrGroupId =:UserInfo.getUserId()) AND RowCause IN ('Territory', 'TerritoryManual', 'TerritoryRule'))
                                                 ];

                                                 
    Set<String>tempList = new Set<String>();

    for(SYSTEMS__c s : lst_PartnersAcc) {
        tempList.add(s.CUST_NUM__c);

        
    }
    
    List<orders__c> orders =[SELECT Orders__c,id FROM orders__c   
                                 WHERE  Bill_to__c IN: tempList OR
                                        Payer__c IN: tempList OR 
                                        Ship_To__c IN: tempList OR
                                        Sold_to__c IN: tempList
                                     ]; 
                                    

     return orders;                                
  }                                
  
}

How to query accounts from the child territory? Any reference would be great. Thanks in advance! 
  • February 20, 2015
  • Like
  • 0
“Have been trying to learn Javascript Remoting since hours. I have manipulated this example to display a table of records with remoting an apex class. Following is the controller and VF.. My controller pulls all records from custom object Feedback. But i'm unable to display in VF. Please guide.

global with sharing class AccountRemoter {

public String accountName { get; set; }
public Feedback__c account { get; set; }
public AccountRemoter() { }

@RemoteAction
global static List<Feedback__c> getAccount(String accountName) {
List<Feedback__c> account = [SELECT Name FROM Feedback__c ];
return account;
}
}
and the Visualforce page...

<apex:page controller="AccountRemoter">
<script type="text/javascript">
function getRemoteAccount() {
    var accountName = document.getElementById('acctSearch').value;

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.AccountRemoter.getAccount}',
        accountName,
        function(result, event){
            if (event.status) {
                // Get DOM IDs for HTML and Visualforce elements like this
                document.getElementById('remoteAcctId').innerHTML = result.Id
                document.getElementById(
                    "{!$Component.block.blockSection.secondItem.acctNumEmployees}"
                    ).innerHTML = result.NumberOfEmployees;
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML =
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
            }
         },
         {escape: true}
     );
   }
  </script>

    <input id="acctSearch" type="text"/>
    <button onclick="getRemoteAccount()">Get Feedbacks</button>
    <div id="responseErrors"></div>

    <apex:pageBlock id="block">
    <apex:pageBlockSection id="blockSection" columns="2">
        <apex:pageBlockSectionItem id="firstItem">
            <span id="remoteAcctId"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="secondItem">
            <apex:outputText id="acctNumEmployees"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:page>
The closest to a table on click of the "Get Feedback" button, I have achieved so far with undefined results.... enter image description here

Any help will be appreciated. Thanks

UPDATE: Fields in Feedback

Client_Feedback_App__c

Description__c

Importance__c

Resolution__c

Status__c

Summary__c
  • April 15, 2014
  • Like
  • 0
          Is there any particular syntax I should follow like in stackoverflow? How do i post code in this forum?
  • April 15, 2014
  • Like
  • 0
Whenever I create a custom object without the use of wizard it doesn't appear in the list of objects to be able to add it as tab. Did I miss any step? Or should I always use the wizard?I didn't reached governor limits for number of tabs also. Thanks
  • February 20, 2014
  • Like
  • 0
The VF that I'm sharing is working perfectly. Can any body explain me how this VF is actually working? That would be great help. Thanks !

<apex:page standardController="account" recordSetVar="accounts" sidebar="false" showHeader="false">
    <apex:panelGrid columns="2">
        <apex:form >
            <apex:pageBlock >
                <apex:pageBlockTable value="{!accounts}" var="a">
                    <apex:column headerValue="Name" >
                        <apex:commandLink value="{!a.name}" reRender="out">
                            <apex:param name="id" value="{!a.id}"/>
                        </apex:commandLink>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:form>
        <apex:outputPanel id="out">
            <apex:detail subject="{!$CurrentPage.parameters.id}" relatedList="false" title="false"/>
        </apex:outputPanel>
    </apex:panelGrid>
</apex:page>
  • January 23, 2014
  • Like
  • 0

Hi,

 

Suppose if i do three manage releases 1.0, 2.0, 3.0 of my app. After the third release, if i want to revert back the code which i had released in 1.0.

Is there any version control system through which i can get back the earlier code .

 

How can i achieve this?

 

Any help on this will be highly appreciated.

 

Thanks,