• SecondID Patel
  • NEWBIE
  • 100 Points
  • Member since 2018

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

I wanted to find out if there is a way to rollup the number of records based on the "type" picklist and then add those totals to the parent record related through a look up field. 


I have the code below which works fine to update the field "Opens" on the parent. (just included the "isInsert" part to keep the example simple)

Is there a way to do this so I wouldn't need a  seperate query for eachrecord type? These records usually come in batches from a 3rd party app.

I'm not sure how connect a query such as [select count(Id) count, activiyType__c from childObject__c group by activiyType__c] with the parent id in a map that can be used in the dml. 

any help is greatly appreciated.
 

trigger pickListCount on wbsendit__Campaign_Activity__c (after insert, after update,after delete) {

    if(trigger.isInsert){

            // list to collect query for all history records
            
            List<CMRules__Email_Tracking_Summary__c> summaryList = new List<CMRules__Email_Tracking_Summary__c>();

            for(AggregateResult agr : [SELECT count(id) ct,CMRules__Email_Tracking_Summary__c c FROM  wbsendit__Campaign_Activity__c where wbsendit__Activity__c = 'Opened' GROUP BY CMRules__Email_Tracking_Summary__c LIMIT 50000]){
                if((ID)agr.get('c')!=null){
                    CMRules__Email_Tracking_Summary__c sum = new CMRules__Email_Tracking_Summary__c(id = (ID)agr.get('c'),CMRules__Opened__c = (Integer)agr.get('ct') );
                    summaryList.add(sum);
                    }
                }
                update summaryList;
            }
}
 



 

Below are trigger and error.


Error: Compile Error: Variable does not exist: whatId at line 13 column 14

trigger LinkdTaskToIncident on BMCServiceDesk__Incident__c (before insert) 
{

    List<BMCServiceDesk__Task__c>  task=new  List<BMCServiceDesk__Task__c>();
        
        for(BMCServiceDesk__Incident__c c:Trigger.new)
        {
           if(c.BMCServiceDesk__Is_New_Record__c==true)
           {    
            
             BMCServiceDesk__Task__c t = new BMCServiceDesk__Task__c();
             t.BMCServiceDesk__taskDescription__c=c.BMCServiceDesk__incidentDescription__c;
             whatId=c.id;

             task.add(t);
           }
        }
          
             insert task;    
}
  • March 31, 2019
  • Like
  • 0
Hi all,

I’m a middle of make some trigger classes and found that trigger.new return list of sobject
What kind of situation would return size 2?
it would be much appreciated if someone give any examples of that

Thanks!

I wanted to find out if there is a way to rollup the number of records based on the "type" picklist and then add those totals to the parent record related through a look up field. 


I have the code below which works fine to update the field "Opens" on the parent. (just included the "isInsert" part to keep the example simple)

Is there a way to do this so I wouldn't need a  seperate query for eachrecord type? These records usually come in batches from a 3rd party app.

I'm not sure how connect a query such as [select count(Id) count, activiyType__c from childObject__c group by activiyType__c] with the parent id in a map that can be used in the dml. 

any help is greatly appreciated.
 

trigger pickListCount on wbsendit__Campaign_Activity__c (after insert, after update,after delete) {

    if(trigger.isInsert){

            // list to collect query for all history records
            
            List<CMRules__Email_Tracking_Summary__c> summaryList = new List<CMRules__Email_Tracking_Summary__c>();

            for(AggregateResult agr : [SELECT count(id) ct,CMRules__Email_Tracking_Summary__c c FROM  wbsendit__Campaign_Activity__c where wbsendit__Activity__c = 'Opened' GROUP BY CMRules__Email_Tracking_Summary__c LIMIT 50000]){
                if((ID)agr.get('c')!=null){
                    CMRules__Email_Tracking_Summary__c sum = new CMRules__Email_Tracking_Summary__c(id = (ID)agr.get('c'),CMRules__Opened__c = (Integer)agr.get('ct') );
                    summaryList.add(sum);
                    }
                }
                update summaryList;
            }
}
 



 

I wanted to lock Create PDF Button in Quotes until the Quote is Approved (Approved field is true).

Is there a way to do this? Right now anyone can create a qoute at any time. 

Thank you!
Below are trigger and error.


Error: Compile Error: Variable does not exist: whatId at line 13 column 14

trigger LinkdTaskToIncident on BMCServiceDesk__Incident__c (before insert) 
{

    List<BMCServiceDesk__Task__c>  task=new  List<BMCServiceDesk__Task__c>();
        
        for(BMCServiceDesk__Incident__c c:Trigger.new)
        {
           if(c.BMCServiceDesk__Is_New_Record__c==true)
           {    
            
             BMCServiceDesk__Task__c t = new BMCServiceDesk__Task__c();
             t.BMCServiceDesk__taskDescription__c=c.BMCServiceDesk__incidentDescription__c;
             whatId=c.id;

             task.add(t);
           }
        }
          
             insert task;    
}
  • March 31, 2019
  • Like
  • 0
Dear All,

I am new to SFDC. I have been gudied that it is a best practicse to write an apex class and then call that class in a trigger. I want to udersatnd how we can use trigger.oldmap or trigger.newmap in an Apex class. Can anyone help me with an example or provide me a link 
Hello Developers,

First Code 
 
   BMCServiceDesk__Incident__c inc=new          BMCServiceDesk__Incident__c();
       inc.BMCServiceDesk__FKClient__c='0050o00000X3wMPAAZ';    
       inc.BMCServiceDesk__FKOpenBy__c='0050o00000X3wMPAAZ'; 
       inc.BMCServiceDesk__FKStatus__c='a3w0w0000000AskAAE'; 
       inc.BMCServiceDesk__FKImpact__c='a2M0w0000000dcYEAQ';
       inc.BMCServiceDesk__FKUrgency__c='a470w00000001G0AAI';
       inc.BMCServiceDesk__Is_New_Record__c=true;
       inc.BMCServiceDesk__FKCategory__c='a210w00000009pbAAA';
       insert inc; 
---------------------------------------------------------------------------------------------

Second Code 
       
       BMCServiceDesk__Status__c[] sta=[select id from BMCServiceDesk__Status__c where name='Opened'];
       User[] user=[Select id from User];
       BMCServiceDesk__Category__c[] cat=[select id from BMCServiceDesk__Category__c where name='Hardware'];
       BMCServiceDesk__Impact__c[] imp=[select id from BMCServiceDesk__Impact__c where name='Low']; 
       BMCServiceDesk__Urgency__c[] urgency=[select id from BMCServiceDesk__Urgency__c where name='Low'];    
       BMCServiceDesk__SYSTemplate__c[] temp=[select id from BMCServiceDesk__SYSTemplate__c where name like '%Test%'];
        
        if(sta.size()> 0 && user.size()>0 &&  cat.size()>0 && imp.size()>0  && urgency.size()> 0 && temp.size()>0 )
        {
               List<BMCServiceDesk__Incident__c> a =new List<BMCServiceDesk__Incident__c>();
             BMCServiceDesk__Incident__c inc=new BMCServiceDesk__Incident__c();
               inc.BMCServiceDesk__FKStatus__c=sta[0].id;     
               inc.BMCServiceDesk__FKClient__c=user[0].id;
               inc.BMCServiceDesk__FKOpenBy__c=user[0].id;
                inc.BMCServiceDesk__FKCategory__c=cat[0].id; 
               inc.BMCServiceDesk__FKImpact__c=imp[0].id;
               inc.BMCServiceDesk__FKTemplate__c=temp[0].id;
               inc.BMCServiceDesk__FKUrgency__c=urgency[0].id;
               insert inc;        
        }

First code is working fine but secod code is not working

I tried  Execute Anonymous.
  • March 30, 2019
  • Like
  • 0
How can we update stock inventory on delete line items using salesforce trigger

Hi all, 

I try to upload my first trigger to my production sytem. Its an addition of an already existing trigger. 

My overall code coverage is 67. My test class is fine. When I checked the Errors I realized that a lot of the System Tests fail due to validation rules and mandatory fields. When I switched of my Account validation Rules my code coverage is 81.

So it should work If I switch of validation rules in the production and upload - and switch them on again after the upload. Is this the way or is there a other option to solve this? 

And when I upload the new version in the change set (+ new Testclass) with the same name it should be replace the old one. Correct? 

Thanks a lot

Hi all,

I’m a middle of make some trigger classes and found that trigger.new return list of sobject
What kind of situation would return size 2?
it would be much appreciated if someone give any examples of that

Thanks!