• Smurfet15
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 12
    Replies
Hi Guro,

I have trigger that is working but my testclass is only  coverage code 36%:
Can you please help to make my code coverage 100% or close to it?
Here is test class and below is my trigger.
--------------------------------------------------------------
@isTest
private class TESTCLASS_AutoCreateWork {
    static testMethod void testCreateWork(){
    controlTriggerRun.autoCreateWork_run = true;
        Case c = new Case();
        c.recordtypeID = '0123B0000004Hzg';
        c.status = 'new';
        c.origin = 'email';
        c.subject = 'Test work item';
        c.description = 'Test to see if a work item is created';
        c.type = 'change';
        insert c;
    
        agf__ADM_Work__c w = new agf__ADM_Work__c();
          w.agf__Subject__c = c.Subject;
          w.agf__Description__c = c.Description;
          w.agf__Status__c = 'New';
          w.Case__c = c.id;
          w.agf__Assignee__c = c.OwnerId;
          w.agf__Product_Owner__c = c.Requestor_Name__c;
          w.agf__Priority_Rank__c = 1;
          w.agf__Use_Prioritizer__c = true;
         
     Test.startTest();
       insert w;  
       list<agf__ADM_Work__c>  ws = [Select Id,  agf__Subject__c , agf__Description__c , case__c  From agf__ADM_Work__c where Case__c =: c.Id];
       system.assertEquals(1,ws.size());
    agf__ADM_Work__c ws1 = ws[0];
   Test.stopTest();
    }
}

Here is trigger:
--------------------------------------------------------------------------------------------------------
trigger autoCreateWork on Case (after update, after insert) {
list<agf__ADM_Work__c> workitems = new list<agf__ADM_Work__c>();
    if(controlTriggerRun.autoCreateWork_run ){
        if(trigger.isinsert){
           for(case c : trigger.new){
               RecordType caseRecType = [Select Name from RecordType where id = : c.recordtypeID];
                if(caseRecType.Name == 'change'){
                    agf__ADM_Work__c w = new agf__ADM_Work__c();
                    w.agf__Subject__c = c.Subject;
                    w.agf__Description__c = c.Description;
                    w.agf__Status__c = 'New';
                    w.Case__c = c.id;
                    w.agf__Assignee__c = c.OwnerId;
                    w.agf__Product_Owner__c = c.Requestor_Name__c;
                    w.agf__Priority_Rank__c = 1;
                    w.agf__Use_Prioritizer__c = true;
                    workitems.add(w);
                    system.debug('Maryx' + c.ownerid);
                    system.debug('Maryx1' + c.Requestor_Name__c);
                }
            }
        }
 
     if(workitems.size()>0){
           controlTriggerRun.autoCreateWork_run = false;
            upsert workitems;
     }
   }
}
Hi Guro,

Here is my exact requirement, we have a flow but we need to fire this 30 days before the contract end date.
Is this possible only in Apex classe if yes can you please send a sample classe on this.

And also i need this Apex Class to run every day, so do we need to Apex Scheduler on this?


Thanks in Advace
Sumerfet

 
Hi guro,

I have a requirement display: Contract Date - 25/01/2015 to 24/01/2016

my code : contact_date = 'Contract Date'  + '  - ' + string.valueOfGmt(s_date) + ' to ' + string.valueOfGmt(e_date);
Resulted to : Contract Date - 25/01/2015 00:00:00 to 24/01/2016 00:00:00

Tried this : contact_date = 'Contract Date'  + '  - ' + s_date.format('dd/MM/yyyy')  + ' to ' + s_date.format('dd/MM/yyyy')
but resulted to different date.

first code is fine but need to remove the time 00:00:00.

Thank,
Smurfet
Hi guro,

I have a requirement display: Contract Date - 25/01/2015 to 24/01/2016

my code : contact_date = 'Contract Date'  + '  - ' + string.valueOfGmt(s_date) + ' to ' + string.valueOfGmt(e_date);
Resulted to : Contract Date - 25/01/2015 00:00:00 to 24/01/2016 00:00:00

Tried this : contact_date = 'Contract Date'  + '  - ' + s_date.format('dd/MM/yyyy')  + ' to ' + s_date.format('dd/MM/yyyy')
but resulted to different date.

first code is fine but need to remove the time 00:00:00.

Thank,
Smurfet
 
Hi Guro,

We have an email to case setup, and we want populate field on case based on the related email fromaddress, since email address will be the lookup to user object then populated the rest of the field then save the case. I have tried to create the trigger with below logic and i am getting an error(invalid type: email) on the "set<email> = new set<email>()" tag.

Can you please help mo on this code?

----------------------------------
trigger  Fieldpopulation on Case (before insert) {
    List<Case> C =  trigger.new;      
    List<EmailMessage> EMessage = [Select id, FromAddress, parentid
                                   From EmailMessage
                                   where parentid in :C];
 
    //assigning the email address
       Set<email> fromadd = new Set<email>(); //getting error here
       for( EmailMessage EM: EMessage )
       {
          fromadd.add( EMessage.FromAddress );
       }
    
    
    //Select in the user object to populate Requestor data
       List <User> ulist = [Select id, name, email, Department, Sales_Office__c, Phone  
                           from user
                          where email = :fromAdd ];
         
    // Update the Case
       c.loc_name__c   = ulist.name;
       c.loc_email__c   = ulist.email;
       c.loc_Dept__c    = ulist.Department;
    update c;
    }

Thanks in advance.

 
Hi,

We have an existing Case Management for External user and we are in the process if developing Internal Case Management.
I have setup the routing email from outlook to Salesforce, we have 2 record types. As of now the Requestor name is coming from Automated Case User(Support Setting). We want it to be auto populated from the sender of the email which is in the user object. How will i do this?

Thanks in Advance,
Smurfet15

 
Hi Guru,

I have a requirement report planning to use standard report "Opportunity and Products",  the problem is custom products fields information are not showing in the fields list of the product. How can I add this? I have tried to create a custom report types but no lucks. I even try to use the joined report (Opportunity with products and Products with Opportunidy) dont know exactly how it work? 
When i try to use the "Opportunity and Product" , product information is missing.
When i try to use the "Product and Opportunities:, Account information is missing.

Thanks in advance,
Smurfet

 
Hi Guru,

I have a requrement to update the checkbox field in the opportunity everytime product is added/update in the opportunitylineitem.
Checkbox should be check if ANYONE of those materials has an 'FRAME' category. Below is working only when material is added with FRAME category. I need to list all product and loop to all lineitem.  I need a list code or SOQL for my lineitem...

Thanks in Advance!

----- here is logic and let me know if this correct-----
loop in list line item
{  if  (itemcategory == 'FRAME')
  { var vframe = true }
}
if (vframe)
{
  oppy.Includes_Frame__c = true ;
  update opportunity;
}
--------------------------------------------------------------
Here is my current code:
----------------------------------------------------------------
trigger OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert, after update) {
//Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>();
    String OppID;
    String Olipc;    

    List<OpportunityLineItem> oppLineItems =
    [Select Id, OpportunityID, PricebookEntry.Product2.product_Category__c
     from OpportunityLineItem where Id IN: trigger.new ];
    
        List<Opportunity> opprt = new List<Opportunity>(); //Get the Opportunity
    for(OpportunityLineItem Oli: oppLineItems){ //loop to the line items
      
     OppID = Oli.OpportunityID;
     Olipc = Oli.PricebookEntry.Product2.product_Category__c  ;
     
    if(Oli.PricebookEntry.Product2.product_Category__c == 'Frame' )
     {
       Opportunity oppy = new Opportunity(Id = OppID);
       oppy.Includes_Frame__c = true ;
       update oppy;  
     }
   }
Hi there,

My requirement is to update(check) opportunity checkbox everytime there is a product added that has product category = "Frame".
Can you please help me?
Nothing is displaying on this : system.debug('Display'+ Olipc);

Below is my code:
--------------------------------------
trigger OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert, after update) {
Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>();
String OppID;
String Olipc;    
   List<Opportunity> opprt = new List<Opportunity>();
   for(OpportunityLineItem Oli: trigger.new){
      
     OppID = Oli.OpportunityID;
     Olipc = Oli.PricebookEntry.Product2.product_Category__c  ;
     system.debug('Display'+ Olipc);
    if(Oli.PricebookEntry.Product2.product_Category__c == 'Frame' )
     {
       Opportunity oppy = new Opportunity(Id = OppID);
       oppy.Frame__c = true ;
       opprt.add(oppy);
         
     }
   }

}
 
Hi,

I have query that need to pull the Username from Users table but I am currently on Case object and the user ID is in opportunity.
This is working, but I want to show Approval name instead of user id (Opportunity__r.PR_Approval_level__c).  This should be the setup Master is Case Object.

Can you please help me?
------------------------------------------------------------------
SELECT Account_Owner__c, CaseNumber, 
Opportunity__r.PR_Approval_level__c, 
Opportunity__r.Bill_To_Contact__r.FirstName, 
Opportunity__r.Bill_To_Contact__r.LastName 
FROM Case WHERE Id = '500M0000006Acvv'

Thanks in advance,
Mary 
 
Hi Guro,

Here is my exact requirement, we have a flow but we need to fire this 30 days before the contract end date.
Is this possible only in Apex classe if yes can you please send a sample classe on this.

And also i need this Apex Class to run every day, so do we need to Apex Scheduler on this?


Thanks in Advace
Sumerfet

 
Hi guro,

I have a requirement display: Contract Date - 25/01/2015 to 24/01/2016

my code : contact_date = 'Contract Date'  + '  - ' + string.valueOfGmt(s_date) + ' to ' + string.valueOfGmt(e_date);
Resulted to : Contract Date - 25/01/2015 00:00:00 to 24/01/2016 00:00:00

Tried this : contact_date = 'Contract Date'  + '  - ' + s_date.format('dd/MM/yyyy')  + ' to ' + s_date.format('dd/MM/yyyy')
but resulted to different date.

first code is fine but need to remove the time 00:00:00.

Thank,
Smurfet
Hi Guro,

We have an email to case setup, and we want populate field on case based on the related email fromaddress, since email address will be the lookup to user object then populated the rest of the field then save the case. I have tried to create the trigger with below logic and i am getting an error(invalid type: email) on the "set<email> = new set<email>()" tag.

Can you please help mo on this code?

----------------------------------
trigger  Fieldpopulation on Case (before insert) {
    List<Case> C =  trigger.new;      
    List<EmailMessage> EMessage = [Select id, FromAddress, parentid
                                   From EmailMessage
                                   where parentid in :C];
 
    //assigning the email address
       Set<email> fromadd = new Set<email>(); //getting error here
       for( EmailMessage EM: EMessage )
       {
          fromadd.add( EMessage.FromAddress );
       }
    
    
    //Select in the user object to populate Requestor data
       List <User> ulist = [Select id, name, email, Department, Sales_Office__c, Phone  
                           from user
                          where email = :fromAdd ];
         
    // Update the Case
       c.loc_name__c   = ulist.name;
       c.loc_email__c   = ulist.email;
       c.loc_Dept__c    = ulist.Department;
    update c;
    }

Thanks in advance.

 
Hi,

We have an existing Case Management for External user and we are in the process if developing Internal Case Management.
I have setup the routing email from outlook to Salesforce, we have 2 record types. As of now the Requestor name is coming from Automated Case User(Support Setting). We want it to be auto populated from the sender of the email which is in the user object. How will i do this?

Thanks in Advance,
Smurfet15

 
Hi Guru,

I have a requrement to update the checkbox field in the opportunity everytime product is added/update in the opportunitylineitem.
Checkbox should be check if ANYONE of those materials has an 'FRAME' category. Below is working only when material is added with FRAME category. I need to list all product and loop to all lineitem.  I need a list code or SOQL for my lineitem...

Thanks in Advance!

----- here is logic and let me know if this correct-----
loop in list line item
{  if  (itemcategory == 'FRAME')
  { var vframe = true }
}
if (vframe)
{
  oppy.Includes_Frame__c = true ;
  update opportunity;
}
--------------------------------------------------------------
Here is my current code:
----------------------------------------------------------------
trigger OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert, after update) {
//Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>();
    String OppID;
    String Olipc;    

    List<OpportunityLineItem> oppLineItems =
    [Select Id, OpportunityID, PricebookEntry.Product2.product_Category__c
     from OpportunityLineItem where Id IN: trigger.new ];
    
        List<Opportunity> opprt = new List<Opportunity>(); //Get the Opportunity
    for(OpportunityLineItem Oli: oppLineItems){ //loop to the line items
      
     OppID = Oli.OpportunityID;
     Olipc = Oli.PricebookEntry.Product2.product_Category__c  ;
     
    if(Oli.PricebookEntry.Product2.product_Category__c == 'Frame' )
     {
       Opportunity oppy = new Opportunity(Id = OppID);
       oppy.Includes_Frame__c = true ;
       update oppy;  
     }
   }
Hi there,

My requirement is to update(check) opportunity checkbox everytime there is a product added that has product category = "Frame".
Can you please help me?
Nothing is displaying on this : system.debug('Display'+ Olipc);

Below is my code:
--------------------------------------
trigger OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert, after update) {
Map<Id,Opportunity> oppIds = new Map<Id,Opportunity>();
String OppID;
String Olipc;    
   List<Opportunity> opprt = new List<Opportunity>();
   for(OpportunityLineItem Oli: trigger.new){
      
     OppID = Oli.OpportunityID;
     Olipc = Oli.PricebookEntry.Product2.product_Category__c  ;
     system.debug('Display'+ Olipc);
    if(Oli.PricebookEntry.Product2.product_Category__c == 'Frame' )
     {
       Opportunity oppy = new Opportunity(Id = OppID);
       oppy.Frame__c = true ;
       opprt.add(oppy);
         
     }
   }

}