• shwetha prabhakar
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Can someone help me out in generating reports as below?


Sales Stage on   Sales Stage on   Probability    Status         Close Date
18-03-2020      27-03-2020
-------------------------------------------------------------------------------------------------
PO Awaited    PO Awaited              50%            Warm             31/3/2020
Closed Won    Closed Won           100%           Closed Won    16/3/2020
Closed Won    Closed Won            100%          Closed Won     5/3/2020
trigger QuotaRoll on Opportunity (after delete,after update,after insert,after undelete) {
    
    set<ID>QtaIds = new set<ID>();   
    
    if(trigger.isinsert || trigger.isundelete){
        for(opportunity opp : trigger.new){
            QtaIds.add(opp.Quota__c);
        }
    }
    if(trigger.isdelete){
        for(opportunity opp : trigger.old){
            QtaIds.add(opp.Quota__c);           
        }        
    }
       
    if(trigger.isupdate){
        for(opportunity opp:trigger.new){
            QtaIds.add(opp.Quota__c);
            if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){
                QtaIds.add(trigger.oldmap.get(opp.id).Quota__c);
            }            
        }
    }    
    map<id,double> amtmap = new map<id,double>();
    for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and ClosedDate_Checkbox__c ='True' and StageName = 'Closed Won' group by Quota__c ]){
        amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM')));
    }
    list<Quota__c>Qtalist = new list<Quota__c>();
   
    for(id iid : QtaIds){
        Quota__c quot = new Quota__c(id=iid);
        if(amtmap.containskey(iid)){
            quot.Inside_Sales_Roll_up__c = amtmap.get(iid);
        }else{
            quot.Inside_Sales_Roll_up__c = 0;
        } 
        Qtalist.add(quot);       
    }
   
    if(Qtalist.size()>0){
        update Qtalist;
    }
   
}
Can anyone help me to write the test class for following apex class

public class QuoteApexClass {
    public Id testId {get;set;}
    private Quotes__c quoteObj;
    public String renderAs { get; set; }
     
    public QuoteApexClass(ApexPages.standardController con){
        if(con.getId()!=NULL){
            testId = con.getId();
            quoteObj =  [select id,Name,Email__c,ContactId__c from Quotes__c where id =:testId];
        }
    }
    public PageReference saveQuoteAsPDFandEmail()
    {    
        PageReference pr = Page.QuoteTemplate;
        Attachment attachmnt = new Attachment();
        Blob pdfBlob;
        try {
            pdfBlob = pr.getContentAsPDF();
        }
        catch (VisualforceException e) {
            pdfBlob = Blob.valueOf('Some Text');
        }
        
        attachmnt.parentId = testId;
        attachmnt.Name = 'V - '+ system.Now() + '.pdf';
        attachmnt.body = pdfBlob;
        insert attachmnt;
        
        
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        
        attach.setFileName(attachmnt.Name);
        attach.setBody(attachmnt.body);
        attach.setContentType('application/pdf');
        semail.setSubject('Quote template '+quoteObj.Name);
        List <String> listEmailMembers = new List<String>();
        listEmailMembers.add('chandra.s@proseraa.com');
        listEmailMembers.add(UserInfo.getUserEmail());
        semail.setToAddresses(listEmailMembers);
        semail.saveAsActivity = true;
        semail.setPlainTextBody('As Discussed over the phone.Please find the quotation attached.Also sign the document and send us back.');
        semail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
        Messaging.SendEmailResult [] r1 = Messaging.sendEmail(new messaging.SingleEmailMessage[] {semail});
        
         if (r1[0].success) 
        {
            System.debug('The email was sent successfully.');
        } else 
        {
            System.debug('The email failed to send: ' + r1[0].errors[0].message);
        }
        
        Task tk = new Task();
        tk.ActivityDate = system.today();
        tk.Subject = 'Email has been sent with subject name as '+'Quote template '+quoteObj.Name;
        tk.Description ='Email has been sent with subject name as '+'Quote template" '+quoteObj.Name + ' " along with an attachment "'+attachmnt.Name+ ' " at '+system.now();
        tk.Status = 'completed';
        tk.WhatId = testId;
        insert tk;
        
        attachment att = new attachment();
        att.Name = 'V - '+ system.Now() + '.pdf';
        att.body = pdfBlob;
        att.ParentId = tk.Id;
        insert att;
        
        PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+testId+'/view');
        pageRef.setRedirect(true);
        return pageRef;  
    }
    
    public void attachPDF() {
        PageReference pdfPage = Page.QuoteTemplate;
        Attachment attach = new Attachment();
        Blob pdfBlob;
        try {
            pdfBlob = pdfPage.getContent();
        }
        catch (VisualforceException e) {
            pdfBlob = Blob.valueOf('Some Text');
        }
        
        attach.parentId = ApexPages.currentPage().getParameters().get('id');
        attach.Name = 'Letter - '+ system.Now() + ' .pdf';
        attach.body = pdfBlob;
        insert attach;
    }
    
    public Boolean getShowPrintLink() {
        return ( (renderAs == null) || ( ! renderAs.startsWith('PDF')) );
    }
   
    public PageReference print() {
        renderAs = 'PDF';
        PageReference pdfPage = Page.QuoteTemplate;
        Attachment attach = new Attachment();
        Blob pdfBlob;
        try {
            pdfBlob = pdfPage.getContentAsPDF();
        }
        catch (VisualforceException e) {
            pdfBlob = Blob.valueOf('Some Text');
        } 
        
        attach.parentId = testId;
        attach.Name = 'V - '+ system.Now() + '.pdf';
        attach.body = pdfBlob;
        insert attach;
        
        PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+testId+'/view');
        pageRef.setRedirect(true);
        return pageRef;  
    }
}
Hi all,
Can anyone help me writing the test class for my trigger.

trigger orderproduct on Order__c (after insert,after update) {
    Set<Id> opportunityIds = new Set<Id>();
    Set<Id> orderIds = new Set<Id>();
    List<Order__c> orderList = new List<Order__c>();
    Map<Id,Id> mapof = new Map<Id,Id>();
    for(Order__c o : Trigger.new)
    {
        if(o.Opportunity__c  != NULL)
        {
            opportunityIds.add(o.Opportunity__c );
            orderIds.add(o.Id);
            mapof.put(o.Opportunity__c ,o.Id);
        }
        
    }
    
    if(opportunityIds.size() > 0)
    {
        list<OpportunityLineItem__c> oppprodList = new list<OpportunityLineItem__c>([Select id,name,Product2Id__r.name,ListPrice__c,OpportunityId__c,Sales_Price__c,Quantity__c from OpportunityLineItem__c WHERE OpportunityId__c=:opportunityIds]);
        // Loop through orders
        List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
        for(OpportunityLineItem__c pd : oppprodList)
        {
            OrderItem__c oi = new OrderItem__c();
            oi.OrderId__c = mapof.get(pd.OpportunityId__c);
            oi.Name = pd.Product2Id__r.name;
            oi.ListPrice__c = pd.ListPrice__c;
            oi.Unit_Price__c = pd.Sales_Price__c;
            oi.Quantity__c = pd.Quantity__c;
            orderItemsForInsert.add(oi);
            
        }
        system.debug('sucess');                              
        if(orderItemsForInsert.size() > 0)
        {
             system.debug('orderItemsForInsert +' +orderItemsForInsert);  
            insert orderItemsForInsert;
        }
        
    }
}
Here is the code, running successfully but not copying the products. can someone help on this?

trigger orderproduct on Order__c (before insert,after insert)  {
    Set<Id> opportunityIds = new Set<Id>();
    Set<Id> orderIds = new Set<Id>();
    List<Order__c> orderList = new List<Order__c>();
    for(Order__c o : Trigger.new)
    {
        if(o.Opportunity__c  != NULL)
        {
            opportunityIds.add(o.Opportunity__c );
            orderIds.add(o.Id);
        }
        
    }
    
    if(opportunityIds.size() > 0)
    {
        list<OpportunityLineItem__c> oppprodList = new list<OpportunityLineItem__c>([Select id,name from OpportunityLineItem__c WHERE Id IN :opportunityIds]);
        // Loop through orders
        List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
        for(OpportunityLineItem__c pd : oppprodList)
        {
            OrderItem__c oi = new OrderItem__c();
            oi.OrderId__c = oi.Id;
            oi.Unit_Price__c = 2323;
            oi.Quantity__c = 1;
            orderItemsForInsert.add(oi);
        }
        system.debug('sucess');                              
        if(orderItemsForInsert.size() > 0)
        {
            insert orderItemsForInsert;
        }
        
    }
}
Hi I am Sales Force student , working on week 3 assignment. I have started on Entitlement Management. I followed all the steps for housekeeping. 
Created the New Entitlement Template also. But when I try creating a new product , I am not able to see the Entitlement Template option in the Details. 
I did add the related list Entitlement Template Name in the Product Page Layout. When I previewed, the Entitlement option was visible. 
Please help