• Srinivas Bandi 4
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 1
    Replies
Class:    
 public static void CountOpentask(list<BMCServiceDesk__Task__c> tsklist)
      {
         if( !isexecutedInc){
         List<BMCServiceDesk__Incident__c> listIncidents = new List<BMCServiceDesk__Incident__c>();
   
         Set<Id> setIncidentIds = new Set<Id>();
        // Set<Id> setIncidentIds1 = new Set<Id>();
         Set<Id> tskIncidentIds = new Set<Id>(); 
         Set<Id> tskIncidentIds1 = new Set<Id>(); 
         for(BMCServiceDesk__Task__c  Inctsk:tsklist) {
            if(Inctsk.BMCServiceDesk__FKIncident__c != null){ 
            setIncidentIds.add(Inctsk.BMCServiceDesk__FKIncident__c);   
            }
          }
   
         AggregateResult[] groupedResults = [SELECT COUNT(Id), BMCServiceDesk__FKIncident__c FROM BMCServiceDesk__Task__c  where ((BMCServiceDesk__FKIncident__c IN :setIncidentIds) AND (BMCServiceDesk__FKStatus__r.name != 'CLOSED'AND BMCServiceDesk__FKStatus__r.name != 'RESOLVED')) GROUP BY BMCServiceDesk__FKIncident__c ];
         
         AggregateResult[] groupedResults1 = [SELECT COUNT(Id), SUM(BMCServiceDesk__Total_Duration__c), BMCServiceDesk__FKIncident__c FROM BMCServiceDesk__Task__c  where ((BMCServiceDesk__FKIncident__c IN :setIncidentIds))  GROUP BY BMCServiceDesk__FKIncident__c ];
         
         
         map<id,BMCServiceDesk__Incident__c > incmap= new map<id,BMCServiceDesk__Incident__c >();
         
         if(groupedResults.size() >0){
         for(AggregateResult ar:groupedResults) {
     
         Id custid = (ID)ar.get('BMCServiceDesk__FKIncident__c');
         System.debug('$$$$$$$$$$$$$$$$$$$$$ custid :' + custid);
         Integer count = (INTEGER)ar.get('expr0');
         tskIncidentIds.add(custid);
         System.debug('$$$$$ :'+ count);
       
         BMCServiceDesk__Incident__c incident = new BMCServiceDesk__Incident__c(Id=custid);
         incident.Open_task__c = count;
         incmap.put(custid,incident);
           }
         }
                  
             
        for(id incId:setIncidentIds){
        if(!tskIncidentIds.contains(incId)){
        BMCServiceDesk__Incident__c incident = new BMCServiceDesk__Incident__c(Id=incId);
        incident.Open_task__c = 0;
        incmap.put(incid ,incident);
       
         }
        }
        
        
         if(groupedResults1.size() >0){
         for(AggregateResult ar:groupedResults1) {
     
         Id custid = (ID)ar.get('BMCServiceDesk__FKIncident__c');
         System.debug('$$$$$$$$$$$$$$$$$$$$$ custid :' + custid);
         Integer count = (INTEGER)ar.get('expr0');
         Decimal sumofmin= (Decimal )ar.get('expr1');
         tskIncidentIds1.add(custid);
         if(incmap.containskey(custid)){
         BMCServiceDesk__Incident__c incident = incmap.get(custId);
         incident.Linked_Tasks__c=count;
         incident.Tasks_Duration_Minutes__c = sumofmin;
         incmap.put(custid,incident);
         }else{
         
         BMCServiceDesk__Incident__c incident = new BMCServiceDesk__Incident__c(Id=custid);
         incident.Tasks_Duration_Minutes__c = sumofmin;
         incident.Linked_Tasks__c=count;
         incmap.put(custid,incident);
         }
         
      
           }
         }
        
         for(id incId:setIncidentIds){
        if(!tskIncidentIds1.contains(incId)){
        if(incmap.containskey(incId)){
        BMCServiceDesk__Incident__c incident = incmap.get(incId);
         incident.Linked_Tasks__c=0;
         incident.Tasks_Duration_Minutes__c=0;
         incmap.put(incid ,incident);
         }
         else{
        BMCServiceDesk__Incident__c incident = new BMCServiceDesk__Incident__c(Id=incId);
        incident.Linked_Tasks__c= 0;
        incident.Tasks_Duration_Minutes__c=0;
        incmap.put(incid ,incident);
        }
         }
        }
        
        
        
        
        isexecutedInc =true;
       
       update incmap.values();
       }

Test Class
static testmethod void Taskcounttest(){
    Test.startTest();
        Profile prof = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        User usr = new User(Alias = 'testuser1', Email='testuser1@test.com', 
                   EmailEncodingKey='UTF-8', LastName='TestName1', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = prof.Id,TimeZoneSidKey='America/Los_Angeles', UserName='testuser1@testuser.com');
                
                   DisableCustomTriggers__c cust = new DisableCustomTriggers__c();
                   cust.name ='CountTasksForIncident';
                   cust.DisableTrigger__c = TRUE;
                   insert cust;
 
 
                  BMCServiceDesk__Category__c catg= new BMCServiceDesk__Category__c(Name = 'Test Emails'+ system.now(),BMCServiceDesk__AvailableForIncidents__c =true,BMCServiceDesk__Inactive__c=false,BMCServiceDesk__UnAvailableForTasks__c= false,BMCServiceDesk__AvailableForServiceCatalog__c=true,BMCServiceDesk__Display_In_SelfService__c=true);
                  insert catg;
                  system.debug('catg' + catg);

                  BMCServiceDesk__BMC_BaseElement__c serv = new BMCServiceDesk__BMC_BaseElement__c();
                  serv.Name ='Fraedom';
                  serv.BMCServiceDesk__Name__c='Fraedom';
                  insert serv;
                  system.debug('serv' + serv);
 

                  BMCServiceDesk__Impact__c impct = new BMCServiceDesk__Impact__c();
                  impct.Name='low';
                  insert impct;
                  system.debug('impct' + impct);
                  
                  BMCServiceDesk__Urgency__c urgc= new BMCServiceDesk__Urgency__c();
                  urgc.Name='low';
                  insert urgc;
                  system.debug('urgc' + urgc);

                  BMCServiceDesk__Status__c stat= new BMCServiceDesk__Status__c(Name='OPENED'+System.now().getTime(),BMCServiceDesk__state__c= true,BMCServiceDesk__defaultStatus__c = true,BMCServiceDesk__appliesToIncident__c = TRUE,BMCServiceDesk__appliesToTask__c = true);
                  insert stat;
                  system.debug('stat' + stat);
 
                  BMCServiceDesk__Status__c stat1= new BMCServiceDesk__Status__c(Name='CLOSED'+System.now().getTime(),BMCServiceDesk__state__c= false,BMCServiceDesk__defaultStatus__c = false,BMCServiceDesk__appliesToIncident__c = TRUE,BMCServiceDesk__appliesToTask__c = true);
                  insert stat1;
                  system.debug('stat1' + stat1);    
 
 
                Account acct = new Account();
                acct.Name='Test Account';
                insert acct;
                system.debug('acct' + acct);
 
                BMCServiceDesk__Incident__c inc = new BMCServiceDesk__Incident__c();
                inc.BMCServiceDesk__FKAccount__c =acct.id;
 
 
               inc.BMCServiceDesk__FKBusinessService__c=serv.id;
               system.debug('categoryId ' +'spmBMCTestforCatId ' + catg.id);
               inc.BMCServiceDesk__FKCategory__c= catg.id;
               inc.BMCServiceDesk__FKImpact__c=impct.id;
               inc.BMCServiceDesk__FKUrgency__c=urgc.id;
               system.debug('STATUS ' +'spmBMCTestforSTATUS ' + stat.id);
               inc.BMCServiceDesk__FKStatus__c=stat.id;
              
               insert inc;
                
               inc.Tasks_Duration_Minutes__c =20;
               inc.Open_task__c =1;
               inc.Linked_Tasks__c=2;
               update inc;
       Test.stopTest();
           }
 
 
 
 
 
 
    
 static testmethod void Taskcounttest2(){
    Test.startTest();
        Profile prof = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        User usr = new User(Alias = 'testuser1', Email='testuser1@test.com', 
                   EmailEncodingKey='UTF-8', LastName='TestName1', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = prof.Id,TimeZoneSidKey='America/Los_Angeles', UserName='testuser1@testuser.com');
   
          DisableCustomTriggers__c cust = new DisableCustomTriggers__c();
          cust.name ='CountTasksForIncident';
          cust.DisableTrigger__c = TRUE;
          insert cust;
         
                  BMCServiceDesk__Category__c catg= new BMCServiceDesk__Category__c(Name = 'Test Emails'+ system.now(),BMCServiceDesk__AvailableForIncidents__c =true,BMCServiceDesk__Inactive__c=false,BMCServiceDesk__UnAvailableForTasks__c= false,BMCServiceDesk__AvailableForServiceCatalog__c=true,BMCServiceDesk__Display_In_SelfService__c=true);
                  insert catg;
                  system.debug('catg' + catg);
                  
                  
 
                  BMCServiceDesk__BMC_BaseElement__c serv = new BMCServiceDesk__BMC_BaseElement__c();
                  serv.Name ='Fraedom';
                  serv.BMCServiceDesk__Name__c='Fraedom';
                  insert serv;
                  system.debug('serv' + serv);
 

                  BMCServiceDesk__Impact__c impct = new BMCServiceDesk__Impact__c();
                  impct.Name='low';
                  insert impct;
                  system.debug('impct' + impct);
                  
                  BMCServiceDesk__Urgency__c urgc= new BMCServiceDesk__Urgency__c();
                  urgc.Name='low';
                  insert urgc;
                  system.debug('urgc' + urgc);
 
                  BMCServiceDesk__Status__c stat= new BMCServiceDesk__Status__c(Name='OPENED'+System.now().getTime(),BMCServiceDesk__state__c= true,BMCServiceDesk__defaultStatus__c = true,BMCServiceDesk__appliesToIncident__c = TRUE,BMCServiceDesk__appliesToTask__c = true);
                  insert stat;
                  system.debug('stat' + stat);
 
                  BMCServiceDesk__Status__c stat1= new BMCServiceDesk__Status__c(Name='CLOSED'+System.now().getTime(),BMCServiceDesk__state__c= false,BMCServiceDesk__defaultStatus__c = false,BMCServiceDesk__appliesToIncident__c = TRUE,BMCServiceDesk__appliesToTask__c = true);
                  insert stat1;
                  system.debug('stat1' + stat1);    
 
 
                Account acct = new Account();
                acct.Name='Test Account';
                insert acct;
                system.debug('acct' + acct);
 
                BMCServiceDesk__Incident__c inc = new BMCServiceDesk__Incident__c();
                inc.BMCServiceDesk__FKAccount__c =acct.id;
 
 
               inc.BMCServiceDesk__FKBusinessService__c=serv.id;
               system.debug('categoryId ' +'spmBMCTestforCatId ' + catg.id);
                inc.BMCServiceDesk__FKCategory__c= catg.id;
               inc.BMCServiceDesk__FKImpact__c=impct.id;
               system.debug('STATUS ' +'spmBMCTestforSTATUS ' + stat.id);
               inc.BMCServiceDesk__FKStatus__c=stat.id;
               inc.BMCServiceDesk__FKUrgency__c=urgc.id;
              // inc.Tasks_Duration_Minutes__c =20;
              // inc.Open_task__c =1;
              // inc.Linked_Tasks__c=2;
               insert inc;
              
               
               
                 List<BMCServiceDesk__Task__c > lstTsk = new List<BMCServiceDesk__Task__c>(); 
                 BMCServiceDesk__Task__c tsk2 = new BMCServiceDesk__Task__c();
                 tsk2.BMCServiceDesk__FKClient__c =usr.id;
                 tsk2.BMCServiceDesk__FKCategory__c=catg.id;
                 tsk2.BMCServiceDesk__FKIncident__c =inc.id;
                 tsk2.BMCServiceDesk__FKStatus__c = stat.id;
                 tsk2.BMCServiceDesk__FKUrgency__c= urgc.id;
                 tsk2.BMCServiceDesk__FKImpact__c= impct.id;
                 inc.Linked_Tasks__c=tsk2.BMCServiceDesk__Total_Duration__c;
                 lstTsk.add(tsk2);
 
                 insert lstTsk;
                 tsk2.BMCServiceDesk__FKStatus__c = stat1.id;
                 update tsk2;
                 delete tsk2;
  Test.stopTest();
      }

User-added image

Hi Champs,

I have an issue while integrating with jira from salesforce.

I am getting System.HttpResponse[Status=null, StatusCode=401] error
from following code
public void jiraIssues(){
String username;
String password;
username='XXXXX';
password='XXXXXXX';
HttpRequest req = new HttpRequest();
Http h = new Http();
String jiraURL='https://test.com';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC '+
EncodingUtil.base64Encode(headerValue);
//String url='https://test.com/rest/api/2/issue/RPT-59';
String endpoint = jiraURL+'/rest/api/2/issue/'+'RPT-56';
req.setHeader('Authorization', 'Bearer ' +authorizationHeader);
// req.setHeader('Content-Type', 'application/xml; charset=utf-8');

// req.setHeader('Accept-Encoding', 'gzip');
req.setHeader('Content-type','application/json');
req.setEndpoint(endpoint);
req.setMethod('GET');
req.setTimeout(120000);
/* req.setHeader('content-type','application/json');
req.setHeader('content-type','application/x-www-form-urlencoded');
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type', 'application/xml');
req.setHeader('Content-Disposition', 'form-data');
req.setHeader('Cache-Control', 'no-cache'); */


HttpResponse res= h.send(req);
}
when I paste the URL(HttpRequest[Endpoint=https://test.com/rest/api/2/issue/RPT-56, Method=GET]) from debug log into the browser it gave me the response

someone help to figure out the issue from the code.

Thanks,
Hi All, 

when try to integrate Jira with Salesforce, I am getting  System.HttpResponse[Status=null, StatusCode=401] error, any suggestion.

Thanks 
 
Hi,

I have integrated salesforce with sendgrid, when I send bulk email from Salesforce via sendgrid user receiving list of toaddress emails.
how can every user receive only their toaddress.

Thanks 
Hi ,
I am trying to integrate Salesforce with Jira with REST service, 
getting following error 

User-added image

Any suggestion why I am getting this error.

Thanks,
Hi,
One of  Salesforce user having difficulty while logging as they keep getting the verification code.
when they login
Connecting VPN versus to desktop requiring re-verification
Also, every time user will have new Citrix session which also requiring re-verification

any workaround to stop verification code for this user 

Thanks in advance 


 

HI, 

I have a requirement where we need to send the survey to a user on every 10th ticket raised by the user.  
Custome object has lookup to Account and User object.

How can I achieve this?
Thanks 



 
Hi, 
 
I want to calculate case age in diffrent status and stop calculating if the status is "123" or"456"

thanks 
Hi,

I have requirment, where i need to have diffrent loging pafes for my diffrent clients. 
Any idea how to have multiple login pages.

Thanks 
Can someone help me in integrating sendgrid into my own org? I need to send bulk email(for campaigns) to a specified list of recepients. 

I took some help from here. https://github.com/sendgrid/sendgrid-apex

But when I tried implementing it in my or, I always had a compiling error
Error Error: Compile Error: Illegal assignment from SendGrid.SendGridResponse to String

Please suggest. Thanks for your time.