• Rahul Chauhan 33
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
My requirement is to apply validation for lightning Input date filed that user can select only today or yesterday date ..??
How can i achieve this 

Thnks in advance..!!
<lightning:input aura:id="yesterday" class="slds-size_1-of-4"  name="Work Day" type="date" label="Workday" 
  max="{!v.today}"   messageWhenBadInput="You cannot fill old date time entry"  value="{!v.work}"  format="DD-MM-YYYY" required="true" />


Js controller:
 var pastday =component.find("v.yesterday");
       var fordate =pastday.get("v.value");
       if(pastday< $today.getDate()-1){
          pastday.set("v.errors", [{message:" You cannot fill time sheet of previous day  "}]);
        }

 
My apex code :-
public class Acctcontroller
{
 // Delaration   
 public Account accobj{get;set;}
 public Opportunity oppobj{get;set;}
 public List<Product2> Productlist{get;set;}
 public List<wrapperclass> wraplist{get;set;}
 Public List<Pricebook2>   pbookobj{get;set;}
 Public Set<Id>      productidset{get;set;}
 public string oppid;
 public List<Opportunity> pbookidlst{get;set;}
 Public List<Pricebookentry> pbe{get;set;}   
 Public Map<Id,Double> mapunitprice{get;set;}
 Public Map<Id,string> mapproduct{get;set;}
 
 
 // constructor
 public Acctcontroller() {
     wraplist = new List < wrapperclass > ();
     oppobj = new Opportunity();
     pbookobj = new List < Pricebook2 > ();
    
     String accId = ApexPages.currentPage().getParameters().get('Id');
     System.debug('Accountid' + accId);
     oppid = ApexPages.currentPage().getParameters().get('oppId');

     if (accId != null && accId.trim() != '') {
         accobj = [SELECT Id, 
                             Name 
                       FROM Account 
                          WHERE Id = : accId];
         System.debug('hey' + accobj);
         oppobj.AccountId = accId;
     }

     Productlist = [SELECT Id, 
                    Name, Productcode 
                    FROM Product2];
     System.debug('Plistvalue' + Productlist);

     for (product2 prodt: Productlist) {
         wrapperclass wrap = new wrapperclass();
         wrap.pro = prodt;
         wraplist.add(wrap);
     }

 }

 public Pagereference save() {
     list<pricebook2> istpbook = [SELECT Id,
                                           Name 
                                      FROM pricebook2
                                      LIMIT 1];
     if(!istpbook.isEmpty())
     oppobj.pricebook2id = istpbook[0].id;
     insert oppobj;
     Pagereference objPG = new Pagereference('/apex/opportunityproductline?oppid=' + oppobj.id);
     objPG.setRedirect(true);
     return objPG;

 }

 public Pagereference saveproduct() {
     productidset = new set <Id>();
     for (wrapperclass wss: wraplist) {
         if (wss.checkbx == true) {

             productidset.add(wss.pro.id);
         }
         }
        System.debug('productsetid'+productidset); 
     
     
    pbookidlst = [SELECT Id,
                           Name,
                           Pricebook2id 
                      FROM Opportunity 
                      WHERE Id = :oppId];
    System.debug('productset1'+pbookidlst);
   
     pbe =[SELECT id,
          UnitPrice,
          Product2Id 
          FROM pricebookentry 
          WHERE product2.id in :productidset];
     
     System.debug('pricebookunitprice'+pbe);
 
     mapunitprice = new Map<id,Double>();
     for(pricebookentry p : pbe)
     {
      
      mapunitprice.put(p.Product2Id,p.UnitPrice);
      
     } 
      System.debug('Mapid'+mapunitprice);
      
 
     list < OpportunityLineItem > lstOLI = new list < OpportunityLineItem > ();
     for (wrapperclass ws: wraplist) {
         if (ws.checkbx == true) {
             OpportunityLineItem objOLI = new OpportunityLineItem();
             objOLI.Product2Id = ws.pro.id;
             objOLI.OpportunityId = oppid;
             objOLI.UnitPrice=mapunitprice.get(ws.pro.id);
             
             System.debug('prod id'+ws.pro.id+'\n--map-'+mapunitprice.get(ws.pro.id));
             System.debug('id11'+ws.pro.id);
             
             objOLI.Quantity = ws.qty;
             System.debug('Quantity'+objOLI.Quantity);
             System.debug('Tp'+objOLI.totalprice);
             // objOLI.totalprice = 100; 
             //objOLI.UnitPrice=map.get(ws.pro.id);
             lstOLI.add(objOLI);
             
         }

     }
     insert lstOLI;
     System.debug('waplistvalue' + lstOLI);
     Pagereference objPGg = new Pagereference('https://ap.salesforce.com?id=accid');
     objPGg.setRedirect(true);
     return objPGg;
 }

 public class wrapperclass {
     public product2 pro {get;set;}
     public Boolean checkbx {get;set;}
     public integer qty {get;set;}
     
     // Wrapper Constructor
     public wrapperclass() {
         pro = new product2();
         checkbx = false;
        
     }
 }
 }

I am trying this :- 
@isTest
public class Acctcontroller_Test {
       
     static testMethod void Updatefield() {
    Account acc = new Account();
        acc.Name = 'Test';
        acc.Rating = 'Hot';
        acc.Status__c= 'Active';
        insert acc;
        
        Opportunity opp = new Opportunity();
        opp.name = 'Test';
        opp.AccountId = acc.Id;
        opp.Amount =1500 ; 
        opp.StageName = 'Closed Won';
        opp.CloseDate = Date.today();
        opp.Type = 'New Customers';
        insert opp;
        
        
        
        Test.StartTest(); 
        Acctcontroller refClass = new Acctcontroller ();
        Test.stopTest();
    }       
}


but its coverage only 20% 
Please help me.........
Thanx in adv.*
My class is:-
public class Contactvfpage
{
    public Map <string,List<Contact>> contactMap {get;set;}
    public Contactvfpage() {
        
      
        contactMap = new Map < string, List < Contact >> ();
        List<Contact> conlist = [Select name,Email,Account.Name from Contact Where Account.Name != null Limit 100];
        list<Contact> tempConList;
        for (Contact con : conlist) {
            if(contactMap.containskey(con.account.Name)) {
                tempConList = contactMap.get(con.account.Name);     
                tempConList.add(con);
            } else {
                tempConList = new list<contact>();
                tempConList.add(con);
            }
            contactMap.put(con.account.Name,tempConList);
        }
    } }

i am trying this code to write its test class :--
@isTest
public class Contactvfpage_Test {
        public static testmethod void testInsertAccount(){
          List<Contact> conlist = new List<Contact>([Select name,Email,Account.Name from Contact Where Account.Name != null Limit 100]);
        
          }
 }

Please help me how to write test class
thanks in advance
i am trying as below : (CLASS)
public class Displaycontactbyaccname {
   public Map <string,List<Contact>> contactMap {get;set;}
public Displaycontactbyaccname() {
      contactMap = new Map < string, List < Contact >> ();
        List<Contact> conlist = [Select LastName,Account.Name from Contact Where Account.Name != null ];
        System.debug('conn'+conlist[0].Account.Name);
         for (Contact con : conlist)
       {
          if(contactMap.containskey(con.account.Name))
          contactMap.get(con.account.Name).add(con);
      else
          contactMap.put(con.account.Name,new list<contact>{con});
               } }}


and below VF page is 
<apex:page controller="Displaycontactbyaccname">
 <apex:form >
 <apex:pageBlock >
  <apex:pageBlockTable value="{!contactMap}" var="item"  >
    <apex:column value="{!item}"/>  <!-- key --->
    <apex:column value="{!contactMap[item]}"/>  <!-- Value--->
</apex:pageBlockTable>
</apex:pageBlock>
 </apex:form>
</apex:page>


But output is not right : please help me 
thanks in advance :))
i am trying as below : (CLASS)
public class Displaycontactbyaccname {
   public Map <string,List<Contact>> contactMap {get;set;}
public Displaycontactbyaccname() {
      contactMap = new Map < string, List < Contact >> ();
        List<Contact> conlist = [Select LastName,Account.Name from Contact Where Account.Name != null ];
        System.debug('conn'+conlist[0].Account.Name);
         for (Contact con : conlist)
       {
          if(contactMap.containskey(con.account.Name))
          contactMap.get(con.account.Name).add(con);
      else
          contactMap.put(con.account.Name,new list<contact>{con});
               } }}


and below VF page is 
<apex:page controller="Displaycontactbyaccname">
 <apex:form >
 <apex:pageBlock >
  <apex:pageBlockTable value="{!contactMap}" var="item"  >
    <apex:column value="{!item}"/>  <!-- key --->
    <apex:column value="{!contactMap[item]}"/>  <!-- Value--->
</apex:pageBlockTable>
</apex:pageBlock>
 </apex:form>
</apex:page>


But output is not right : please help me 
thanks in advance :))
trigger ChatterGroupM on CollaborationGroup (after insert) {

       for(CollaborationGroup e:Trigger.New){

        List<User> users=[select id, Username from User where CompanyName='Bodhtree' AND IsActive=true];   
    
        e = [select id, OwnerId,Name from CollaborationGroup where Id=:Trigger.New];
    
        List<CollaborationGroupMember> ChatterM = new List<CollaborationGroupMember>();
    
        //List<CollaborationGroupMember> ChatterM = [SELECT MemberId FROM CollaborationGroupMember WHERE CollaborationGroupId='0F9m00000004K33'];
    
         for(User user:users){

          system.debug('The Group Name is ' + e.Name);

         if(e.OwnerId==user.Id){} 
  
         else{   
         CollaborationGroupMember CollMember= new CollaborationGroupMember(CollaborationGroupId=e.id,MemberId = user.Id);
         
         system.debug('The memberId is ' + CollMember.MemberId);
         
         ChatterM.add(CollMember);
         
         system.debug('The ownerId is ' + e.OwnerId);
       
         system.debug('The users are ' + ChatterM);
         
         }

        }
        
        
        insert ChatterM;
        


        }
}

How to write the test class for the CollaborationGroup. Its urgent