• Umadevi S
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies

Hi Team,

I am create the apex class for tracking the Quote.....
My Apex Class is
global with sharing class InvoicePdfWsSample {
    webService static String generateInvoicePdf(List<Id> oppsIdList) {
        try {
            final Set<Id> oppsId = new Set<Id>(oppsIdList);
            final String quoteTemplateDataViewerUrl = '/quote/quoteTemplateDataViewer.apexp?id={!QuoteId}&headerHeight=100&footerHeight=100&summlid=0EH0K0000034xt6';
            if (String.isBlank(quoteTemplateDataViewerUrl)) {
                String errorMsg = 'Invoice Template Id or Quote Template Data Viewer URL are blank, please review their values in Application Properties custom setting.'; 
                return errorMsg;
            }
            
            final List<QuoteDocument> attList = new List<QuoteDocument>();
            
            for (Opportunity opp : 
                [
                SELECT Id, 
                    (
                        SELECT Id, QuoteNumber, IsSyncing,Quote_Track__c,CreatedDate 
                        FROM Quotes 
                        ORDER BY CreatedDate 
                        DESC
                    ) 
                FROM Opportunity 
                WHERE Id IN :oppsId
                ]) 
            {
                if (opp.Quotes.isEmpty()) continue;
                Quote theQuote = null;
                for (Quote quoteAux : opp.Quotes) {
                    if (quoteAux.IsSyncing) {
                        theQuote = quoteAux;
                        break;
                    }
                }
                if (theQuote == null) theQuote = opp.Quotes.get(0);
                PageReference pageRef = new PageReference(
                    quoteTemplateDataViewerUrl.replace('{!QuoteId}', theQuote.Id)
                );
 
                attList.add(
                    new QuoteDocument(
                        Document = pageRef.getContent(),
                        QuoteId = theQuote.Id
                    )
                );
                 theQuote.Quote_Track__c= theQuote.Quote_Track__c+ 1;
                 update theQuote;
            }
 
            system.debug(attList);
            if (!attList.isEmpty()){
                 insert attList;
            }             
            return '';
        } catch (Exception e) { System.debug(LoggingLevel.ERROR, e.getMessage());  final String errorMsg = 'An error has occured while generating the invoice. Details:\n\n' + e.getMessage() + '\n\n' + e.getStackTraceString(); return errorMsg; }
    }
}


My Test Class
@isTest (SeeAllData=true)                    
public class InvoicePdfWsSampleTest
{
    static testMethod void TestMe()
    {
        List<Id> oidl = new List<Id>();
        List<Opportunity> ol = new List<Opportunity>([SELECT Id FROM Opportunity ORDER BY CreatedDate DESC LIMIT 10]);
        for (Opportunity o : ol){
            oidl.add(o.Id);
        }
        InvoicePdfWsSample.generateInvoicePdf(oidl);
        
    }

    }

I getting 69% Code coverage of the test class. How can i increase the code coverage?
 
Hi Team,

This is the Class and when i run the class it through the error....
 
@isTest              
public class LeadOpportunityTest 
{
    static testMethod void LeadTestmethod()
    {
        RecordType LeadRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Lead' AND Name = 'IPL'
                                         LIMIT 1];
        Lead leadVar=new Lead(LastName='Singla',FirstName='Dinesh',Company='Infosys',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='RR',Email='dinesh.singla24@gmail.com',
                              RR_vs_CSK__c=true,RR_vs_RCB__c=true,RR_vs_KXIP__c=true,RR_vs_MI__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar;
         Lead leadVar1=new Lead(LastName='kumar',FirstName='Raj',Company='invoice',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='MI',Email='dinesh.singla24@gmail.com',MI_vs_RR__c=true
                               ,MI_vs_DD__c=true,MI_vs_KXIP__c=true,MI_vs_KKR__c=true,MI_vs_RCB__c=true,MI_vs_CSK__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar1;
         Lead leadVar2=new Lead(LastName='Farhan',FirstName='akhtar',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='CSK',Email='dinesh.singla24@gmail.com',CSK_vs_RR__c=true,CSK_vs_DD__c=true
                               ,CSK_vs_KXIP__c=true,CSK_vs_KKR__c=true,CSK_vs_RCB__c=true,CSK_vs_SRH__c=true,CSK_vs_MI__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar2;
         Lead leadVar3=new Lead(LastName='Prasad',FirstName='Madhvan',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='KXIP',Email='dinesh.singla24@gmail.com',KXIP_vs_DD__c=true
                               ,KXIP_vs_KKR__c=true,KXIP_vs_RR__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar3;
         Lead leadVar4=new Lead(LastName='Rohirt',FirstName='sharma',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='DD',Email='dinesh.singla24@gmail.com',DD_vs_RR__c=true,DD_vs_RCB__c=true
                               ,DD_vs_KXIP__c=true,DD_vs_MI__c=true,DD_vs_KKR__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar4;
        
    }
    static testMethod void OpportunityTestmethod()
    {
        
        Account accVar=new Account(name='Infosys',Destination_State__c='Tamil Nadu');
        insert accVar;
        Contact conVar=new Contact(LastName='Singla',FirstName='Dinesh',Email='dinesh.singla24@gmail.com',AccountId=accVar.id);
        insert conVar; 
        RecordType oppDiabetesRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Opportunity' AND Name = 'IPL'
                                         LIMIT 1];
        Opportunity oppVar=new Opportunity(name='Infosys',Accountid=accVar.id,Home_Team__c='DD',CloseDate=Date.Today(),StageName='Qualified',LeadSource='Web',recordtypeid=oppDiabetesRecordType.id);
        insert oppVar;
        Product2 proVar=new Product2(Name='test',IsActive=true,Family='Sports',Boxes_Type__c='Corporate Box/Hospitality/Gene',Event_Date__c=Date.Today()+1,Home_Team__c='RR',Match_Between__c='RR vs KKR');
        insert proVar;
        PriceBook2 priceBook = [Select Id from PriceBook2 where IsStandard=true];
        //insert priceBook;               
        OpportunityContactRole oppContactRole=new OpportunityContactRole(OpportunityId=oppVar.id,ContactId=conVar.id,IsPrimary=true);
            //OpportunityId,ContactId From OpportunityContactRole where IsPrimary=true
        insert oppContactRole;     
        
        PriceBookEntry pbe = new PriceBookEntry(Pricebook2Id=priceBook.Id, Product2Id=proVar.Id, UnitPrice=5, IsActive=true);
        insert pbe;
        OpportunityLineItem oppLineItemVar=new OpportunityLineItem(OpportunityId = oppVar.Id, PricebookEntryId=pbe.Id, Quantity=1, UnitPrice=5);
        insert oppLineItemVar;
        oppVar.StageName='Payment Received';
        oppVar.Payment_Received__c=true;
        oppVar.Transaction_Reference_No__c='transaction';
        oppVar.Customer_Payment_Date__c=Date.Today();
        oppVar.Booking_Ids__c='bookingid';
        update oppVar;
        system.debug('....update opportunity.........'+oppVar);
    
    }
    static testMethod void OpportunityTestmethodPaymentConfirm()
    {
        Account accVar=new Account(Name='Infosys',Destination_State__c='Tamil Nadu');
        insert accVar;
        Contact conVar=new Contact(LastName='Singla',FirstName='Dinesh',Email='dinesh.singla24@gmail.com',AccountId=accVar.id);
        insert conVar;
        RecordType oppRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Opportunity' AND Name = 'IPL'
                                         LIMIT 1];
        Opportunity oppVar=new Opportunity(Name='Infosys',Accountid=accVar.id,  Home_Team__c='DD',CloseDate=Date.Today(),StageName='Qualified',LeadSource='Web',recordtypeid=oppRecordType.id);
        insert oppVar;
        
        Product2 proVar=new Product2(Name='test',IsActive=true,Family='Sports',Boxes_Type__c='Corporate Box/Hospitality/Gene',Event_Date__c=Date.Today()+1,Home_Team__c='RR',Match_Between__c='RR vs KKR');
        insert proVar;
        PriceBook2 priceBook = [Select Id from PriceBook2 where IsStandard=true];
        //insert priceBook;               
        OpportunityContactRole oppContactRole=new OpportunityContactRole(OpportunityId=oppVar.id,ContactId=conVar.id,IsPrimary=true);
            //OpportunityId,ContactId From OpportunityContactRole where IsPrimary=true
        insert oppContactRole;     
        
        PriceBookEntry pbe = new PriceBookEntry(Pricebook2Id=priceBook.Id, Product2Id=proVar.Id, UnitPrice=5, IsActive=true);
        insert pbe;
        OpportunityLineItem oppLineItemVar=new OpportunityLineItem(OpportunityId = oppVar.Id, PricebookEntryId=pbe.Id, Quantity=1, UnitPrice=5);
        insert oppLineItemVar;
        
         oppVar.StageName='Payment Confirmation';
         oppVar.Customer_Payment_Confirmed__c=true;
         oppVar.Checked_By__c=UserInfo.getUserId();
         oppVar.Payment_Received_on__c=Date.Today();
         oppVar.Amount_Received__c=55555;
         oppVar.Booking_Ids__c='bookingid';
          update oppVar;
    }
}

 
Hi Team,

I need to make mandatory attachment Probability is 100 %, also Check box field(Invoiced__c) is true then attchment is mandatory.

I write the below trigger and it working fine. I don't how can i write the test class for that trigger.
 
trigger ClosedOpportunityTrigger on Opportunity (before update) {
    
    
    for(Opportunity o:Trigger.New) {
    if(o.Probability==100 && o.Invoiced__c == true)
    {
        
            
            Attachment a = new Attachment();
            try {
               a = [Select Id, Name from Attachment where ParentId =:o.Id];
            }
            catch(Exception e) {
               a = null;
            }
            
            if (a == null)
               o.addError('Add an attachment before you close the Opportunity');
        }
    }
   }
This my Test Class

@isTest
private class ClosedOpportuntyTriggerTest{
    
    static testmethod void methodOne(){
        
        /*contact objc = new contact();
        objc.Lastname = 'test';
        objc.Email ='umadevi.s@bookmyshow.com';
        insert objc;*/
        Opportunity objOpp = new Opportunity();
       objOpp.Name = 'test opp';
        objOpp.StageName = 'Payment Receiveed';
        objOpp.Probability = 80;
       // objOpp.Contact__c = objc.id;
        objOpp.CloseDate = system.today();
        objOpp.Booking_Ids__c ='12345';
        insert objOpp;
        
        blob attBlob;   
        
        attBlob = EncodingUtil.base64Decode('AA=='); // zero-length, null-terminated string
        
        Attachment objAttach = new Attachment();
        objAttach.OwnerId = UserInfo.getUserId();
        objAttach.Name = 'test.pdf';
        objAttach.ParentId = objOpp.Id; // the record the file is attached to
        objAttach.IsPrivate = true;
        objAttach.Body = attBlob;
        objAttach.ContentType = 'application/pdf';
        insert objAttach;
        
        objOpp.StageName = 'Payment Confirmation';
        objOpp.Probability = 100;
        objOpp.Invoiced__c = true;
        
        objOpp.Probability = 100;
        
        update objOpp;
        
    }
}
And i got Error Add one Product 
 
Hi Team,

I need to generate the report for particular Quote template used in pdf. 
How can generate the report,we have the more than 6 Quote template. I need to track the Particular Quote Template used in Quote.
Hi Team,

I want to show Quote No(Formula field) and No of Ticket in Email Template i create the Visula force template and i got the following error.
"Error: Invalid field QuoteLineItem for SObject Opportunity". I am create the below code for youe reference.

<messaging:emailTemplate subject="Payment information is confirmed By Finance Team" recipientType="User" relatedToType="Opportunity">
<messaging:htmlEmailBody >



<html>

<head>
<style>
table, th, tr {
    border: 3px solid red;
    border-collapse: collapse;
}
</style>
</head>
<body  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" yahoo="fix" style="font-family:Arial, sans-serif; background:#efefef;">
<table height="100px" width="600px"  cellpadding="0" cellspacing="0"  border="0" align="center" style="background-color:#efefef;">
<tr height="100px" >
<td>
<img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb2R&oid=00DO00000051Sb5&lastMod=1427087493000" alt="" width="175" height="50" style="padding:15px; display:block; background-color:#efefef; color:#ffffff;" border="0"/>
</td>
</tr>
<tr height="60px" >
<td style="width:560px; padding:15px 10px; font-size:13px; font-family:arial,sans-serif; line-height:18px; text-align:justify; vertical-align:top; background-color:#ffffff; color:#010101;">
  Hi {!recipient.name},<br/><br/>
  <apex:repeat var="qx" value="{!relatedTo.QuoteLineItem}">  
  We have received the payment of {!relatedTo.Amount_Received__c}    of {!qx.No_Of_Tickets__c}tickets of{!relatedTo.Name} for {!qx.Quote_No__c}. <br/><br/> 
  Please follow the link to view https://ap2.salesforce.com/{!relatedTo.Id}<br/><br/>

</apex:repeat>


  Thank You,<br/>
  BookMyShow Finance Team
</td>

</tr>
<tr height="40px" >
<td>
<table width="600px">
<tr>
 <td style="vertical-align:top; text-align:left;"><a href="http://www.facebook.com/pages/BookMyShow/82235273865" target="_blank"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb2W&oid=00DO00000051Sb5&lastMod=1427087527000" alt="Facebook Share" width="30" height="30" border="0" /></a></td>
                                       <td style="vertical-align:top; text-align:left;"><a href="http://www.twitter.com/BookMyShow"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb30&oid=00DO00000051Sb5&lastMod=1427087711000" alt="Twitter" width="30" height="30" border="0" /></a></td>
                                       <td style="vertical-align:top; text-align:left;"><a href="http://www.youtube.com/user/bookmyshow" target="_blank"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb35&oid=00DO00000051Sb5&lastMod=1427087742000" alt="Youtube" width="30" height="30" border="0" /></a></td>
                                       <td style="vertical-align:top; text-align:left;"><a href="https://plus.google.com/110517543803442814698/posts" target="_blank"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb2g&oid=00DO00000051Sb5&lastMod=1427087583000" alt="Google" width="30" height="30" border="0" /></a></td>
                                       <td style="vertical-align:top; text-align:left;"><a href="http://www.linkedin.com/company/bookmyshow/" target="_blank"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb2v&oid=00DO00000051Sb5&lastMod=1427087685000" alt="Linkedin" width="30" height="30" border="0" /></a></td>
                                       <td style="vertical-align:top; text-align:left;"><a href="http://line.naver.jp/ti/p/%40bookmyshow" target="_blank"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb2q&oid=00DO00000051Sb5&lastMod=1427087656000" alt="Linkedin" width="30" height="30" border="0" /></a></td>
                                       <td style="vertical-align:top; text-align:center;"><a href="http://instagram.com/bmsbookmyshow" target="_blank"><img src="https://c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000Mb2l&oid=00DO00000051Sb5&lastMod=1427087617000" alt="Instagram" width="30" height="30" border="0" /></a></td>
    <td style="width:25px;"><img src="http://cnt.in.bookmyshow.com/mailers/images/footer110814/call.png" alt="Call BookMyShow Contact Center" width="30" height="30" border="0" style="vertical-align:middle;" /></td>
                                                   <td style="width:125px; padding:0 0 0 10px;  font-family:Arial,Helvetica,sans-serif; font-size:16px; font-weight:bold; color:#010101; vertical-align:middle;">+912239895050</td>
                                                                               
</tr>
</table>
</td>
</tr>
</table>

</body>
</html>

</messaging:htmlEmailBody>
</messaging:emailTemplate>

I dont know how to show the both formula field in template.

Regards,
Uma

Hi Team,

I am create the apex class for tracking the Quote.....
My Apex Class is
global with sharing class InvoicePdfWsSample {
    webService static String generateInvoicePdf(List<Id> oppsIdList) {
        try {
            final Set<Id> oppsId = new Set<Id>(oppsIdList);
            final String quoteTemplateDataViewerUrl = '/quote/quoteTemplateDataViewer.apexp?id={!QuoteId}&headerHeight=100&footerHeight=100&summlid=0EH0K0000034xt6';
            if (String.isBlank(quoteTemplateDataViewerUrl)) {
                String errorMsg = 'Invoice Template Id or Quote Template Data Viewer URL are blank, please review their values in Application Properties custom setting.'; 
                return errorMsg;
            }
            
            final List<QuoteDocument> attList = new List<QuoteDocument>();
            
            for (Opportunity opp : 
                [
                SELECT Id, 
                    (
                        SELECT Id, QuoteNumber, IsSyncing,Quote_Track__c,CreatedDate 
                        FROM Quotes 
                        ORDER BY CreatedDate 
                        DESC
                    ) 
                FROM Opportunity 
                WHERE Id IN :oppsId
                ]) 
            {
                if (opp.Quotes.isEmpty()) continue;
                Quote theQuote = null;
                for (Quote quoteAux : opp.Quotes) {
                    if (quoteAux.IsSyncing) {
                        theQuote = quoteAux;
                        break;
                    }
                }
                if (theQuote == null) theQuote = opp.Quotes.get(0);
                PageReference pageRef = new PageReference(
                    quoteTemplateDataViewerUrl.replace('{!QuoteId}', theQuote.Id)
                );
 
                attList.add(
                    new QuoteDocument(
                        Document = pageRef.getContent(),
                        QuoteId = theQuote.Id
                    )
                );
                 theQuote.Quote_Track__c= theQuote.Quote_Track__c+ 1;
                 update theQuote;
            }
 
            system.debug(attList);
            if (!attList.isEmpty()){
                 insert attList;
            }             
            return '';
        } catch (Exception e) { System.debug(LoggingLevel.ERROR, e.getMessage());  final String errorMsg = 'An error has occured while generating the invoice. Details:\n\n' + e.getMessage() + '\n\n' + e.getStackTraceString(); return errorMsg; }
    }
}


My Test Class
@isTest (SeeAllData=true)                    
public class InvoicePdfWsSampleTest
{
    static testMethod void TestMe()
    {
        List<Id> oidl = new List<Id>();
        List<Opportunity> ol = new List<Opportunity>([SELECT Id FROM Opportunity ORDER BY CreatedDate DESC LIMIT 10]);
        for (Opportunity o : ol){
            oidl.add(o.Id);
        }
        InvoicePdfWsSample.generateInvoicePdf(oidl);
        
    }

    }

I getting 69% Code coverage of the test class. How can i increase the code coverage?
 
Hi Team,

This is the Class and when i run the class it through the error....
 
@isTest              
public class LeadOpportunityTest 
{
    static testMethod void LeadTestmethod()
    {
        RecordType LeadRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Lead' AND Name = 'IPL'
                                         LIMIT 1];
        Lead leadVar=new Lead(LastName='Singla',FirstName='Dinesh',Company='Infosys',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='RR',Email='dinesh.singla24@gmail.com',
                              RR_vs_CSK__c=true,RR_vs_RCB__c=true,RR_vs_KXIP__c=true,RR_vs_MI__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar;
         Lead leadVar1=new Lead(LastName='kumar',FirstName='Raj',Company='invoice',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='MI',Email='dinesh.singla24@gmail.com',MI_vs_RR__c=true
                               ,MI_vs_DD__c=true,MI_vs_KXIP__c=true,MI_vs_KKR__c=true,MI_vs_RCB__c=true,MI_vs_CSK__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar1;
         Lead leadVar2=new Lead(LastName='Farhan',FirstName='akhtar',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='CSK',Email='dinesh.singla24@gmail.com',CSK_vs_RR__c=true,CSK_vs_DD__c=true
                               ,CSK_vs_KXIP__c=true,CSK_vs_KKR__c=true,CSK_vs_RCB__c=true,CSK_vs_SRH__c=true,CSK_vs_MI__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar2;
         Lead leadVar3=new Lead(LastName='Prasad',FirstName='Madhvan',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='KXIP',Email='dinesh.singla24@gmail.com',KXIP_vs_DD__c=true
                               ,KXIP_vs_KKR__c=true,KXIP_vs_RR__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar3;
         Lead leadVar4=new Lead(LastName='Rohirt',FirstName='sharma',Company='wipro',State__c='New Delhi',Origin_State_1__c='Tamil Nadu',LeadSource='Web',Status='Open',Home_Team__c='DD',Email='dinesh.singla24@gmail.com',DD_vs_RR__c=true,DD_vs_RCB__c=true
                               ,DD_vs_KXIP__c=true,DD_vs_MI__c=true,DD_vs_KKR__c=true,Recordtypeid=LeadRecordType.id);
        insert leadVar4;
        
    }
    static testMethod void OpportunityTestmethod()
    {
        
        Account accVar=new Account(name='Infosys',Destination_State__c='Tamil Nadu');
        insert accVar;
        Contact conVar=new Contact(LastName='Singla',FirstName='Dinesh',Email='dinesh.singla24@gmail.com',AccountId=accVar.id);
        insert conVar; 
        RecordType oppDiabetesRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Opportunity' AND Name = 'IPL'
                                         LIMIT 1];
        Opportunity oppVar=new Opportunity(name='Infosys',Accountid=accVar.id,Home_Team__c='DD',CloseDate=Date.Today(),StageName='Qualified',LeadSource='Web',recordtypeid=oppDiabetesRecordType.id);
        insert oppVar;
        Product2 proVar=new Product2(Name='test',IsActive=true,Family='Sports',Boxes_Type__c='Corporate Box/Hospitality/Gene',Event_Date__c=Date.Today()+1,Home_Team__c='RR',Match_Between__c='RR vs KKR');
        insert proVar;
        PriceBook2 priceBook = [Select Id from PriceBook2 where IsStandard=true];
        //insert priceBook;               
        OpportunityContactRole oppContactRole=new OpportunityContactRole(OpportunityId=oppVar.id,ContactId=conVar.id,IsPrimary=true);
            //OpportunityId,ContactId From OpportunityContactRole where IsPrimary=true
        insert oppContactRole;     
        
        PriceBookEntry pbe = new PriceBookEntry(Pricebook2Id=priceBook.Id, Product2Id=proVar.Id, UnitPrice=5, IsActive=true);
        insert pbe;
        OpportunityLineItem oppLineItemVar=new OpportunityLineItem(OpportunityId = oppVar.Id, PricebookEntryId=pbe.Id, Quantity=1, UnitPrice=5);
        insert oppLineItemVar;
        oppVar.StageName='Payment Received';
        oppVar.Payment_Received__c=true;
        oppVar.Transaction_Reference_No__c='transaction';
        oppVar.Customer_Payment_Date__c=Date.Today();
        oppVar.Booking_Ids__c='bookingid';
        update oppVar;
        system.debug('....update opportunity.........'+oppVar);
    
    }
    static testMethod void OpportunityTestmethodPaymentConfirm()
    {
        Account accVar=new Account(Name='Infosys',Destination_State__c='Tamil Nadu');
        insert accVar;
        Contact conVar=new Contact(LastName='Singla',FirstName='Dinesh',Email='dinesh.singla24@gmail.com',AccountId=accVar.id);
        insert conVar;
        RecordType oppRecordType = [SELECT Id
                                         FROM RecordType
                                         WHERE SobjectType = 'Opportunity' AND Name = 'IPL'
                                         LIMIT 1];
        Opportunity oppVar=new Opportunity(Name='Infosys',Accountid=accVar.id,  Home_Team__c='DD',CloseDate=Date.Today(),StageName='Qualified',LeadSource='Web',recordtypeid=oppRecordType.id);
        insert oppVar;
        
        Product2 proVar=new Product2(Name='test',IsActive=true,Family='Sports',Boxes_Type__c='Corporate Box/Hospitality/Gene',Event_Date__c=Date.Today()+1,Home_Team__c='RR',Match_Between__c='RR vs KKR');
        insert proVar;
        PriceBook2 priceBook = [Select Id from PriceBook2 where IsStandard=true];
        //insert priceBook;               
        OpportunityContactRole oppContactRole=new OpportunityContactRole(OpportunityId=oppVar.id,ContactId=conVar.id,IsPrimary=true);
            //OpportunityId,ContactId From OpportunityContactRole where IsPrimary=true
        insert oppContactRole;     
        
        PriceBookEntry pbe = new PriceBookEntry(Pricebook2Id=priceBook.Id, Product2Id=proVar.Id, UnitPrice=5, IsActive=true);
        insert pbe;
        OpportunityLineItem oppLineItemVar=new OpportunityLineItem(OpportunityId = oppVar.Id, PricebookEntryId=pbe.Id, Quantity=1, UnitPrice=5);
        insert oppLineItemVar;
        
         oppVar.StageName='Payment Confirmation';
         oppVar.Customer_Payment_Confirmed__c=true;
         oppVar.Checked_By__c=UserInfo.getUserId();
         oppVar.Payment_Received_on__c=Date.Today();
         oppVar.Amount_Received__c=55555;
         oppVar.Booking_Ids__c='bookingid';
          update oppVar;
    }
}

 
Hi Team,

I need to make mandatory attachment Probability is 100 %, also Check box field(Invoiced__c) is true then attchment is mandatory.

I write the below trigger and it working fine. I don't how can i write the test class for that trigger.
 
trigger ClosedOpportunityTrigger on Opportunity (before update) {
    
    
    for(Opportunity o:Trigger.New) {
    if(o.Probability==100 && o.Invoiced__c == true)
    {
        
            
            Attachment a = new Attachment();
            try {
               a = [Select Id, Name from Attachment where ParentId =:o.Id];
            }
            catch(Exception e) {
               a = null;
            }
            
            if (a == null)
               o.addError('Add an attachment before you close the Opportunity');
        }
    }
   }
This my Test Class

@isTest
private class ClosedOpportuntyTriggerTest{
    
    static testmethod void methodOne(){
        
        /*contact objc = new contact();
        objc.Lastname = 'test';
        objc.Email ='umadevi.s@bookmyshow.com';
        insert objc;*/
        Opportunity objOpp = new Opportunity();
       objOpp.Name = 'test opp';
        objOpp.StageName = 'Payment Receiveed';
        objOpp.Probability = 80;
       // objOpp.Contact__c = objc.id;
        objOpp.CloseDate = system.today();
        objOpp.Booking_Ids__c ='12345';
        insert objOpp;
        
        blob attBlob;   
        
        attBlob = EncodingUtil.base64Decode('AA=='); // zero-length, null-terminated string
        
        Attachment objAttach = new Attachment();
        objAttach.OwnerId = UserInfo.getUserId();
        objAttach.Name = 'test.pdf';
        objAttach.ParentId = objOpp.Id; // the record the file is attached to
        objAttach.IsPrivate = true;
        objAttach.Body = attBlob;
        objAttach.ContentType = 'application/pdf';
        insert objAttach;
        
        objOpp.StageName = 'Payment Confirmation';
        objOpp.Probability = 100;
        objOpp.Invoiced__c = true;
        
        objOpp.Probability = 100;
        
        update objOpp;
        
    }
}
And i got Error Add one Product 
 
Cannot pass this challenge although I have passed it on another account.

I've completely recreated every step. The Home page is Process_Automation_Home for developer name. This challenge keeps telling me it cannot find the new lead flow even though I can use the flow on the page to generate a new lead. It has full functionality but apparently theres a magical parameter I can't seem to pass to complete this challenge.
Hi, 

I need to create a trigger or validation rule that requires a user to attach a document/insertion order to an opportunity when it is changed to 100% or closed won.

Please advise.