• ilu sharma
  • 0 Points
  • Member since 2022

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
Class Controller:
public with sharing class controllerquoteVisual {
    public String title {get;set;}
    public Quote quote {get;set;}
    public List<quoteLineItem> qliList {get;set;}
    //public List<Product2> products {get; set;}
    //Capturar Nombre de familia y lista de productos
    public Map<String,List<ObjectWrapper>> mapFamily {get;set;}
    //public Map<String,List<QuoteLineItem>> mapFamilyqli {get;set;}
    //Captutar Nombre de familia y recuento de Productos que se mostrarán
    public Map<String, Integer> FamilyCountMap{get;set;}
	//Capturar Lista de nombres de familia de productos 
    public List<String> FamilyList {get;set;}
    //ProductList o products ya con los productos que se requieren mostrar
    public controllerquoteVisual(){
        Id id = ApexPages.currentPage().getParameters().get('id');
        //Obtener quote mediante el Id que arroja la visualforce desde quote
        quote = [SELECT Id, Name, TotalPrice, GrandTotal, ExpirationDate, AccountId, Total_Hours__c, OpportunityId, QuoteNumber   
                FROM quote WHERE Id=:id LIMIT 1];
        Opportunity opportunity = [SELECT Name FROM Opportunity WHERE Id=:quote.OpportunityId LIMIT 1];
        title = opportunity.Name.split('\\|')[0] + opportunity.Name.split('\\|')[1];
        Apexpages.currentPage().getHeaders().put('content-disposition', 'inline; filename='+title+ ' - ' +quote.QuoteNumber );
        //Obtener lista de quoteLineItems de la actual quote
        qliList = [SELECT Id, Product2Id, Quantity  
                    FROM quoteLineItem WHERE quoteId=:Id];
        //Separar productos por tipo de familia 
        mapFamily = new Map<String, List<ObjectWrapper>>(); 
        FamilyCountMap = new Map<String, Integer>();
        FamilyList = new List<String>();
        List<quoteLineItem> finalqliList = new List<QuoteLineItem>();
        finalqliList = qliList;
        //Agrupar por nombre de familia y preparar los map
        for(QuoteLineItem qq: finalqliList){
            Product2 famObj = [SELECT Id, Name, Family, Description
                   FROM Product2 WHERE Id=:qq.Product2Id];
            if(famObj.Family == null){
                famObj.Family= 'Sin clasificación';
            //List<QuoteLineItem> qq = qliList;
            List<ObjectWrapper> proList = new List<ObjectWrapper>();
            //Verificar si el map ya contiene el mismo nombre por familia
            	//Recuperar lista de productos existentes
            	proList = mapFamily.get(famObj.Family);
            	//Meter el nuevo producto a la lista
                proList.add(new ObjectWrapper(qq, famObj));
                mapFamily.put(famObj.Family, proList);
                //Almacenar filas por nombre de familia
                FamilyCountMap.put(famObj.Family, proList.size());
            	//crear nuevo map del nombre de familia //.fammily,name,etc
                proList.add(new ObjectWrapper(qq, famObj));
                mapFamily.put(famObj.Family, proList); 
                //Almacenar filas por nombre de familia
                FamilyCountMap.put(famObj.Family, proList.size());
        	FamilyList = new List<String>(mapFamily.keySet());
    public class ObjectWrapper{
        //Campos QuoteLineItems
        //Public Id QliId{get;set;}
        Public Decimal Quantity{get;set;}
        //Campos Producto
        Public String Name{get;set;}
        Public String Family{get;set;}
        Public String Description{get;set;}
        public ObjectWrapper(QuoteLineItem ql, Product2 pr){
            //this.QliId = ql.Id;
            this.Quantity = ql.Quantity;
            this.Name = pr.Name;
            this.Family = pr.Family;
            this.Description = pr.Description;

Test Class (68%, wrapper class is missing)
public class TestControllerquoteVisual{
    static void testControllerVFP(){
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book', 
                                       Description = 'Price Book Products', IsActive = true );
        insert pb;
        Product2 prod = new Product2(Name = 'Test Product', Description = 'Descripción Test', 
                                     Family = 'Salesforce Service Cloud', IsActive = true);
        insert prod;
        List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 
                                           where IsStandard = true ];
    	List<PricebookEntry> listPriceBook = new List<PricebookEntry>();
     	for(Pricebook2 p : standardPbList ){
      		PricebookEntry pbe = New PricebookEntry ();
      		pbe = new PricebookEntry(Pricebook2Id = p.Id, Product2Id = prod.Id, 
                                     UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
        insert listPriceBook;
        Opportunity opp = new Opportunity(Name = 'Test Opportunity', 
                                          StageName = 'Discovery', Product_Families__c='Salesforce Service Cloud' ,CloseDate = system.today());
        insert opp;
        Quote quttest = new Quote (Name = 'Quote Test' , OpportunityId = opp.id , Pricebook2Id = pb.id );
        insert quttest;
        List<QuoteLineItem> listval = new List<QuoteLineItem>();
        for(PricebookEntry pricebook : listPriceBook){
            QuoteLineItem qutlineitemtest = new QuoteLineItem ();
            qutlineitemtest = new QuoteLineItem(QuoteId = quttest.id, Quantity = 3.00,UnitPrice = 12, PricebookEntryId = pricebook.id);
        insert listval;    
        QuoteLineItem qlitem = new QuoteLineItem(Quantity = 3.00, UnitPrice = 12 );
            ApexPages.currentPage().getParameters().put('id', String.valueOf(quttest.Id));
            controllerquoteVisual controllerVfp= new controllerquoteVisual();
            //controllerVfp = new controllerquoteVisual();
            controllerquoteVisual.ObjectWrapper wrapper = new controllerquoteVisual.ObjectWrapper(qlitem, prod);
            wrapper.Quantity = 3.00;
            wrapper.Name = prod.Name;
            wrapper.Description = prod.Description;
            wrapper.Family = prod.Family;


Hi there!

I've been asked to restrict the valid Close Dates for Opporunities to the last day of the month when the Stage is not Closed Won/Lost.

I've found a fromula that does a great job restricting the dates in general, but I can't figure out how to add the additional condition that it should only apply the date limitation when the Opportunity is in certain stages.

    MONTH( CloseDate ) = 12,
    DATE( YEAR( CloseDate ) + 1, 1, 1 ),
    DATE( YEAR( CloseDate ), MONTH( CloseDate ) + 1, 1 )
  ) - 1 

Any help/insight would be greatly appreciated!
Ans:  Text, Text Area, Text Area Long, Rich Text Area, URL. Is this is the right answer or is there something else????

13. Can we change the data type from Text to Auto Number for the Name when we already have?

Ans: I feel the answer is yes. If yes, please do let me know the explanation . If no, let me know the reason as well. Thanks guys.