• Ankit Kalsara 6
  • NEWBIE
  • 35 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 24
    Replies
Hi team,

I have created a test class for code coverage of my apex class which gets called 30days after the criteria are met. During the test run, I am getting 0% code coverage. 

My process builder criteria is: when the case moves to Open, I am calling scheduled action 30days from now and calling the apex class inside.
The apex class simply sends an email to case contact.

Below is my test class.
@isTest
private class EmailCaseDLTest {    
    
    Static testMethod void Test_EmailCaseDL(){                
               
        TestData.insertTemplateEntitlements();
        Account acct = TestData.createAccountWithAddress('Test Account Email Case DL', 'Boston', 'MA', '02115', 'US');
        INSERT acct;    
        
        // create the Contact under the Account
        Contact ct = new Contact(AccountId = acct.Id,
                                 lastName  = 'lastname',
                                 firstName = 'firstname',
                                 email     = 'testingContact@test.com');        
        INSERT ct;
       
        // Create the asset
        Asset ast = new Asset(Name = 'test Asset1', AccountId = acct.Id);
        INSERT ast;        
        
        // Test insert
        Case c = new Case(AccountId   = acct.Id, 
                          AssetId     = ast.Id,
                          ContactId   = ct.Id, 
                          Subject     = 'Test case Subject', 
                          Description = 'test case description');
        c.DL_Of_Customer_Case_Team__c = 'ankit.kalsara@test1.com;ankit.kalsara2@test2.com';
        INSERT c;        
        
        Test.startTest();
        
        // update Internal status and sub-status
        c.Internal_Status__c = 'Open';
        c.Sub_Status__c      = 'Awaiting Information';                
        UPDATE c;
        Test.stopTest();        
    }

}

 
Hi team,

I am trying to send email using Messaging.sendEmail() method using Apex trigger on Case object.

The Owner of the Case object could be single owner or a Queue. How can I send the email address to all the members of the queue when Case owner is a Queue?
Hi team,

I have workflow rule which sends email notification once the criteria is met and sends another notification 30days after the rule trigger date.

I am replacing the entire workflow rule using apex trigger. How do I send email notification 30days after the initial rule trigger date? How can I perform time trigger actions of workflow rule using basic apex trigger?
Hi team,

I have workflow rule which sends email notification once the criteria is met and sends another notification 30days after the rule trigger date.

I am replacing the entire workflow rule using apex trigger. How do I send email notification 30days after the initial rule trigger date?
Hi all,

I have certain Contacts which are part of Predefined case team.

When the Case is created by a particular Contact(say ABC), I want to send notificaiton to ALL the contacts(say ABC,JKL,XYZ) which are part of SAME predefined case team(team 1) as the contact who created the case.

I cannot write SOQL on PredefinedCaseTeamMember. However I can see that all the 3 contacts are linked to same team when view the records via Power BI.

User-added image
Hi team,

I am trying to send email using Messaging.sendEmail() method using Apex trigger on Case object.

The Owner of the Case object could be single owner or a Queue. How can I send the email address to all the members of the queue when Case owner is a Queue?
Greetings,

I'm trying to help trouble-shoot an issue with a flow which is invoked by a process.  The whole thing is supposed to result in an automatic synchronization between the product and opportunity.

Right now, if I add a quote to an opportunity which has a product, the quote will save but the product will disappear from the opportunity.

User-added imageUser-added imageUser-added imageUser-added imageUser-added image
trigger OppUpBsdOnStage on Opportunity (before update) {
    map<id,Opportunity> oppold= trigger.oldMap;
    map<id,Opportunity> oppnew= trigger.newMap;
    set<id> soi=oppold.keySet();
    for(id i:soi)
    {
        Opportunity oldop=oppold.get(i);
        Opportunity nwop=oppnew.get(i);
        if(oldop.StageName=='Closed Won'  &&  nwOp.StageName=='Closed Won')
        {
            nwop.closeDate=System.today();
            nwop.type='New Customer';
            oppnew.put(i, nwop);
        }

    }
    update oppnew.values();
}Trigger Error
I have tried below code for send email with attachment and I am unable to receive the attachment file along with email. Even email also not getting received.Below is my code:

1. I debug the code and I got the attached file id,content-type,Name and all thing which is required but not receiving mail. If anyone can help, i will aprriciate their help. Thanks!
Apex class:
public class sendEmailAttachmentPR {
    public Pricing_Reconfirmation__c prId{get;set;}
    public String primaryContactId {get;set;}
    public String AccountId{get;set;}
    public String email{get;set;}
    
    public pagereference sendEmailAttchament(){
        
        prId = [Select Id,Name,Account__r.Id,Primary_Contact__r.id from Pricing_Reconfirmation__c where id =: ApexPages.currentPage().getParameters().get('id')];
        primaryContactId = prId.Primary_Contact__r.id;
        AccountId = prId.Account__r.Id;
        system.debug('Primary Contact Id ====>'+primaryContactId);
        system.debug('Account Id ===> '+AccountId);
        
        Contact con = [SELECT ID,Name,Email,Phone from Contact where Id =:primaryContactId];
        email = con.email;
        system.debug('Email Id  =======>'+email);
        User currentUser = [SELECT Id FROM User Where Id = :UserInfo.getUserId()];
        
        Attachment attachFile = [SELECT Id,Name,parentId,LastmodifiedDate,ContentType,body FROM Attachment where parentId=:prId.Id ORDER BY LastmodifiedDate Desc LIMIT 1];
        system.debug('Attachment File Id '+attachFile.id);
      
            Messaging.EmailFileAttachment emailAttach = new Messaging.EmailFileAttachment();
            emailAttach.setContentType(attachFile.ContentType);
            system.debug('ContentType ====> '+attachFile.ContentType);
            emailAttach.setFileName(attachFile.Name);
            system.debug('FIle Name ===>'+attachFile.Name);
            emailAttach.setInline(false);
            emailAttach.Body = attachFile.Body;
            system.debug('Body ====> '+emailAttach.Body);
            
            
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            semail.setEntityAttachments(new Id[]{attachFile.Id});
            semail.setSubject('Sending Document as attachemnt');
            String[] sendTo = new String[]{'shashikant@xxxxx.com'};
                semail.setToAddresses(sendTo);
            semail.setPlainTextBody('Please find the attached document details');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
            
            system.debug('Email Sent Successfully');
        
            //system.debug('Email Id available for Contact');
     
        return null;
    }

}
VF Page:
<apex:page controller="sendEmailAttachmentPR">
    
    <apex:form >
        <apex:pageMessages />
        <apex:commandButton value="Send Email" action="{!sendEmailAttchament}"/>
    </apex:form>  
</apex:page>

could anyone help me here?
trigger OpportunityOpen on Account(before delete)
{
    Map<Id, Account> mapacc = new Map<Id, Account>( [Select Id, Name, AnnualRevenue,
                            (Select AccountId, StageName From Opportunities)
                            From Account Where Id In : trigger.old]);
    for(Account a : trigger.old)
    {
        for(Opportunity opp : mapacc.get(a.Id).Opportunities)
        {
            if(opp.stageName=='closed won')
            {
                a.addError('associated open opportunities with account');
            }
        }
    }
}
Hi all,

I'm new to apex triggers and had posted in the community to get a trigger to create a field that summarizes Opportunities Product Families.  I was so excited when a wondeful community member was able to help. The code works create in my sandbox.  I attempted to do a change set to move into production but have been unable.  I submitted a case to Salesforce support and they recommded to post this forum since we are not on a Premier Sucess plan.

Code:
trigger populateProductFamily  on OpportunityLineItem (after Insert,before delete) {


if((trigger.IsAfter  && trigger.IsInsert)  || (trigger.IsBefore  && trigger.IsDelete)  )      // run after insert and before delete


{
//map to hold product family for a gven oppty
Map<id,Set<String>> oppprodFamilyMap = new Map<id,Set<String>>();
//get all oppty id
List<id> oppId =  new List<Id>();
List<opportunitylineitem> triggerList = new List<opportunitylineitem>();
if(trigger.IsDelete)
{  system.debug('in delete');
triggerList = trigger.old;
}

else
{
triggerList = trigger.new;
}


for (opportunitylineitem ol : triggerList )  {

   oppId.add(ol.opportunityid);

}

// query all opportunity for opportunitylineitem inserted



List<opportunity> oppList = [select id ,Opportunity_Product_Family__c from opportunity where id in :oppId];




// query all opportunitylineitem linked with opportunity of current opportunitylineitem
//we need this so that we can get all product family for a a given oppty

List<opportunitylineitem> olList  =  new List<opportunitylineitem>();

if(trigger.IsDelete) {
olList = [select id,opportunityid,product2.family  from opportunitylineitem where opportunityid in :oppList  and id not in  :triggerList  ];

}

else

{
olList = [select id,opportunityid,product2.family  from opportunitylineitem where opportunityid in :oppList  ];

}

system.debug('---ollist' + olList  );


//now we need to separate productfamily by opportunity


for (opportunitylineitem ol : olList )  {

IF(ol.product2.family  != null)  {
if(oppprodFamilyMap.get(ol.opportunityid) != null)  {

Set<String>  pFamilySet   = oppprodFamilyMap.get(ol.opportunityid);
pFamilySet.add(ol.product2.family);
oppprodFamilyMap.put(ol.opportunityid,pFamilySet);

}

else {
 Set<String> pFamilySet = new Set<String> ();
 pFamilySet.add(ol.product2.family);
oppprodFamilyMap.put(ol.opportunityid,pFamilySet);


}

}



}



// now we have got all productfamily for a given oppty.
//we need to concat  and update field


  //opplist to update
  
  List<opportunity> oppListToUpdate = new List<opportunity>();


for(opportunity  o : oppList)  



List<String>  pFamilyList = new List<String>(oppprodFamilyMap.get(o.Id));
String pFamily  = string.join(pFamilyList ,',');

o.Opportunity_Product_Family__c  = pFamily;
oppListToUpdate.add(o);

 


}


if(oppListToUpdate.size()>0)

update  oppListToUpdate;







}      

}

Error - Code Coverage Failure
Your code coverage is 0%. You need at least 75% coverage to complete this deployment.
populateProductFamily

I'm sure I have to change the sandbox, then the change set and try to deploy again into but everything I've tried fails.  Any help would be greatly appreciated.  
Hi team,

I have workflow rule which sends email notification once the criteria is met and sends another notification 30days after the rule trigger date.

I am replacing the entire workflow rule using apex trigger. How do I send email notification 30days after the initial rule trigger date?
Hi there, I am relatively new to apex coding and need to write a trigger handler for the following Trigger.  I understand the general logic and reason for why I need to do it, but unsure on how exacty it needs to be done. i.e. do I leave my definition of the ID sets in the trigger and move everything else to the class? Do I need to pass anything from the trigger to the class when I call it (specially if the id sets are defined/declared in the trigger)? Your help is greatly appreciated!

trigger AgreementHasAttachment on ContentDocumentLink (after insert) {
    Set<Id> setParentId = new Set<Id>();
    Set<Id> setGrandParentId = new Set<Id>();
      
    for (ContentDocumentLink cdl : trigger.new)  {
        setParentId.add(cdl.LinkedEntityId);      
    }
    
    List<Agreement__c> Agreementlst = new List<Agreement__c>();
    Agreementlst = [select Id, HasAttachment__c, MDU_Referral_Contact__c from Agreement__c where Id IN :setParentId];    
    For (Agreement__c a : Agreementlst) 
    {
        a.HasAttachment__c = True;
        setGrandParentId.add(a.MDU_Referral_Contact__c);
    }
    
    List<Contact> Contlst = new List<Contact>();
    Contlst = [Select Id, Contract_Uploaded__c from Contact where Id IN :setGrandParentId];
    For (Contact c : Contlst){
        c.Contract_Uploaded__c = true;
    }
    
    if(Agreementlst.size() > 0) update Agreementlst;
    if(Contlst.size() > 0) update Contlst;
}
Hi all,

I have certain Contacts which are part of Predefined case team.

When the Case is created by a particular Contact(say ABC), I want to send notificaiton to ALL the contacts(say ABC,JKL,XYZ) which are part of SAME predefined case team(team 1) as the contact who created the case.

I cannot write SOQL on PredefinedCaseTeamMember. However I can see that all the 3 contacts are linked to same team when view the records via Power BI.

User-added image
I tried using the following code as a base and modifying the profile to userID, I am not getting emails, Please advice
 
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage> ();

List<Profile> userProfile = [select id from profile where Name='System Administrator'];

// getting email template id

List<Id> emailTemplateId = [select id from EmailTemplate where DeveloperName='My_Email_Template'].id; 

for(User sysAdminUser :[Select id from user where ProfileID IN:userProfile]) {
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 string body = 'Hi '+ sysAdminUser.LastName;
 mail.setSubject('Test Subject');
 
// assign user
 
mail.setTargetObjectId(sysAdminUser.Id); 
 mail.setSaveAsActivity(false);
 
//email template id
 
mail.setTemplateId(emailTemplateId); 
 
//this is used to merge field values in email template

 mail.setWhatId( [select id from Account limit 1].id ); 
 mails.add(mail);

}
Messaging.sendEmail(mails);

 

Was wondering if someone has successfully accomplished cloning a quote and the related quote line items?  I need it to create a new quote revision without creating a whole new quote with new quote number...just a new revision number.

 

I am struggling and thought that this task has probaly been done by someone "out there"...

 

I appreciate your help!!

  • September 14, 2011
  • Like
  • 0