• Mariusz
  • NEWBIE
  • 45 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
Hi guyz,

I want  to restrict the users login to the salesforce for one particular time slot. eg. user should not be able login between 5.30  pm to 6.30 pm every day.
in all other timings he should be able to login to the salesforce instance.
How can i achieve this, it would be great if anyone help me to achieve this

Thanks
Hi guyz,

I want  to restrict the users login to the salesforce for one particular time slot. eg. user should not be able login between 5.30  pm to 6.30 pm every day.
in all other timings he should be able to login to the salesforce instance.
How can i achieve this, it would be great if anyone help me to achieve this

Thanks
Hi, I'm having some issues with getting the Contact IDs from their emails. I have a list of emails (around 1000 users) that I want to get their Contact IDs for. Using a VLookup table isn't the most efficient because there are over 3 million Contact records to sort through. If there's an easier way, let me know! 

I tested the code below and it returns only the first value of the list of emails. When I do the query for [SELECT id, name, email FROM Contact WHERE email IN :emails], it only returns one object. What am I doing wrong? 

String users = 'johnny@abc.com, jimmy@abc.com, jonas@abc.com'
List<String> emails = users.split(',');

public static Map<String, id> contactIDFromEmail(List<String> emails){
        Map<String, id> cm = new Map<String, id>();
        Contact[] c = [SELECT id, name, email FROM Contact WHERE email IN :emails];
        for(Contact cont : c){
            cm.put(cont.email, cont.id);
        }
        return cm;
    }
  • September 28, 2018
  • Like
  • 0
Hi, 

  I have a class below which has no code I want to get coverage for below class
public class PP_HandleException extends Exception {
  
}
Wrote test class as mentioned blelow. Still showing 0% as code coverage 
@isTest(seealldata=false)
public class PP_HandleExceptionTest{
    static testMethod void PP_HandleException(){
        Test.startTest();
       PP_HandleException PP = new PP_HandleException('test');
    
        Test.stopTest();
    }  
}

  Please suggest me how to get code coverage.

Thanks
Sudhir
 
I keep getting this error, and don't know why - help! :
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ARGUMENT_TYPE, The argument is null or invalid.: []

when I run this test:
@istest 
public class UpdateCheckboxAgreementContentDocTest {
    @isTest static void testcheckboxaddPDFcd() {
        // Insert Company
        Account acc=new Account(name='testing');
        insert acc;
        // Insert Contact
        Contact con=new contact(lastname='testinggvs',accountid=acc.id,leadsource='Walk In');
        insert con;
        // Insert Pricebook
        Pricebook2 pb = new Pricebook2(name='test',IsActive = true);
        insert pb;
        // Get Standard Pricebook
        Pricebook2 standardPB = new Pricebook2(
            Id = Test.getStandardPricebookId(),
            IsActive = true
        );
        // Insert Product Agreement Terms
        Product_Agreement_Terms__c pat = new Product_Agreement_Terms__c(name = 'MAP');
        insert pat;
        // Insert Product
        Product2 p = new Product2(Name='MAP Build',Productcode='MACP',Product_Agreement_Terms__c=pat.Id,IsActive = true);
        insert p;
        // Insert Standard Pricebook Entry
        PricebookEntry standardPBE = new PricebookEntry(Product2Id = p.Id,Pricebook2Id = standardPB.Id,UnitPrice = 0,IsActive = true);
        insert standardPBE;
        // Insert Pricebook Entry
        PricebookEntry pbe = new PricebookEntry(Product2Id = p.Id,Pricebook2Id = pb.Id,UnitPrice = 0,IsActive = true);
        insert pbe;
        // Insert Opportunity
        Opportunity opp = new Opportunity(Name='AAA Test',StageName='Agreement Sent', CloseDate=date.parse('02/02/2018'),MAP_Start_Date__c=date.parse('02/02/2018'),MAP_End_Date__c=date.parse('02/02/2018'),Pricebook2Id = pb.Id,Payment_Method__c='Interac',Signing_Contact__c=con.id,accountid=acc.id);
        insert opp; 
        // Insert Opportunity Line Item
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId = opp.Id,UnitPrice = 1,Quantity = 1,Product2Id = p.Id);
        insert oli;
        // Insert CD to opportunity
        ContentVersion contentVersion1 = new ContentVersion(Title = 'ContentAgreement0',PathOnClient = 'ContentAgreement0.pdf',VersionData = Blob.valueOf('Test Content'),IsMajorVersion = true,ContentLocation='S ');
        system.debug('contentVersion Value equals: '+ contentVersion1);
        insert contentVersion1;
    }
    @isTest static void testcheckboxremovePDFcd() {
        // Insert Company
        Account acc=new Account(name='testing');
        insert acc;
        // Insert Contact
        Contact con=new contact(lastname='testinggvs',accountid=acc.id,leadsource='Walk In');
        insert con;
        // Insert Pricebook
        Pricebook2 pb = new Pricebook2(name='test',IsActive = true);
        insert pb;
        // Get Standard Pricebook
        Pricebook2 standardPB = new Pricebook2(
            Id = Test.getStandardPricebookId(),
            IsActive = true
        );
        // Insert Product Agreement Terms
        Product_Agreement_Terms__c pat = new Product_Agreement_Terms__c(name = 'MAP');
        insert pat;
        // Insert Product
        Product2 p = new Product2(Name='MAP Build',Productcode='MACP',Product_Agreement_Terms__c=pat.Id,IsActive = true);
        insert p;
        // Insert Standard Pricebook Entry
        PricebookEntry standardPBE = new PricebookEntry(Product2Id = p.Id,Pricebook2Id = standardPB.Id,UnitPrice = 0,IsActive = true);
        insert standardPBE;
        // Insert Pricebook Entry
        PricebookEntry pbe = new PricebookEntry(Product2Id = p.Id,Pricebook2Id = pb.Id,UnitPrice = 0,IsActive = true);
        insert pbe;
        // Insert Opportunity
        Opportunity opp = new Opportunity(Name='AAA Test',StageName='Agreement Sent', CloseDate=date.parse('02/02/2018'),MAP_Start_Date__c=date.parse('02/02/2018'),MAP_End_Date__c=date.parse('02/02/2018'),Pricebook2Id = pb.Id,Payment_Method__c='Interac',Signing_Contact__c=con.id,accountid=acc.id);
        insert opp; 
        // Insert Opportunity Line Item
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId = opp.Id,UnitPrice = 1,Quantity = 1,Product2Id = p.Id);
        insert oli;
        // Insert ContentVersion to opportunity       
 	    ContentVersion contentVersion = new ContentVersion(
            Title = 'ContentAgreement1',
            PathOnClient = 'ContentAgreement1.pdf',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true
        );
        insert contentVersion;
        contentVersion = [Select ContentDocumentId from contentVersion where Title= 'ContentAgreement1'];
        ContentDocument cd = new ContentDocument(id=contentVersion.ContentDocumentId);
        // Insert ContentVersion2 to opportunity       
        ContentVersion contentVersion2 = new ContentVersion(
            Title = 'ContentAgreement2',
            PathOnClient = 'ContentAgreement2.jpg',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true
        );
        insert contentVersion2;
        contentVersion2 = [Select ContentDocumentId from contentVersion where Title= 'ContentAgreement2'];
        ContentDocument cd2 = new ContentDocument(id=contentVersion2.ContentDocumentId);
        //Create and populate review opportunity record
        Opportunity oppReview =  new Opportunity();
        oppReview = [Select Id,Agreement_Attached_as_Content_Document__c from Opportunity where ID=:opp.Id];
        system.debug('Content Added, oppReview.Agreement_Attached_as_Content_Document__c Value equals: '+ oppReview.Agreement_Attached_as_Content_Document__c);
        System.Assert(oppReview.Agreement_Attached_as_Content_Document__c==True);
        // Delete ContentDocument
        delete cd;
        //Populate review opportunity record
        oppReview = [Select Id,Agreement_Attached_as_Content_Document__c from Opportunity where ID=:opp.Id];
        system.debug('cd deleted, oppReview.Agreement_Attached_as_Content_Document__c Value equals: '+ oppReview.Agreement_Attached_as_Content_Document__c);
        System.Assert(oppReview.Agreement_Attached_as_Content_Document__c==False);
        // Delete ContentDocument2
        delete cd2;
        //Populate review opportunity record
        oppReview = [Select Id,Agreement_Attached_as_Content_Document__c from Opportunity where ID=:opp.Id];
        system.debug('cd2 deleted, oppReview.Agreement_Attached_as_Content_Document__c Value equals: '+ oppReview.Agreement_Attached_as_Content_Document__c);
        System.Assert(oppReview.Agreement_Attached_as_Content_Document__c==False);
    }
}


for this trigger:
trigger UpdateCheckboxAgreementContentDocument on ContentDocument (after insert, after delete) {
    Set<Id> setOpportunityId = new Set<Id>();
    List<Opportunity> lstOpp = new List<Opportunity>();
    if (Trigger.isInsert) {
        for(ContentDocument cd: trigger.new){
            // this 006 check was in the sample code I found
            if(String.valueOf(cd.ParentId).startsWith('006')) {
                setOpportunityId.add(cd.ParentId); 
            }
            // Check ContentDocument to see if PDF
            if(cd.FileExtension.endsWithIgnoreCase('pdf')) {
                for(Opportunity opp: [Select Id, Agreement_Attached_as_Content_Document__c from opportunity where Id IN:setOpportunityId]){
                    // check the box on the opportunity
                    opp.Agreement_Attached_as_Content_Document__c = True;
                    // add the opportunity to the list variable to update
                    lstOpp.add(opp);
                }
            }
        }
    }
    else if (Trigger.isDelete) {
        //new id variable for checking in delete scenario
        id oppId = null;
        boolean PDFStillAttached = null;
        for(ContentDocument cd: trigger.old){
            // this 006 check was in the sample code I found
            if(String.valueOf(cd.ParentId).startsWith('006')) {
                oppId = cd.ParentId; 
            }
            // Check other ContentDocuments to see if there are any other PDFs attached
            List<ContentDocument> lstCds = ([SELECT ID, FileExtension From ContentDocument where ParentId=:oppId]);
            if (lstCds.size()>0) {
                for (ContentDocument lstCd: lstCds) {
                    if(lstCd.FileExtension.endsWithIgnoreCase('pdf')) {
                        PDFStillAttached = True;
                    }
                }
                for(Opportunity opp: [Select Id, Agreement_Attached_as_Content_Document__c from opportunity where Id IN:setOpportunityId]){
                    // check the box on the opportunity
                    If(PDFStillAttached=True){
                        opp.Agreement_Attached_as_Content_Document__c = True;
                    }
                    else {
                        opp.Agreement_Attached_as_Content_Document__c = False;
                    }
                    // add the opportunity to the list variable to update
                    lstOpp.add(opp);
                }
            }
            else {
                Opportunity opp= [Select Id, Agreement_Attached_as_Content_Document__c from opportunity where Id=:oppId];
                    opp.Agreement_Attached_as_Content_Document__c = False;
                // add the opportunity to the list variable to update
                lstOpp.add(opp);
                system.debug('lstOpp equals: '+ lstOpp);
            }
        }
    }
    // Update opportunity if opportunity list size greater than 0
    if(lstOpp.size()>0) {
        update lstOpp;
                system.debug('lstOpp updated: '+ lstOpp);
    }
}

 
I'm trying to mass update a specific field using developer's console, but I only end up deleting the record itself. Here is my code: 

Contact[] contactDel = [SELECT Email__c FROM Contact
   WHERE Join_Date__c <= '2000'
   AND Email__c LIKE '%it.work.com’];

delete contactDel;

I'm currently trying to mass delete an email field that ends with "it.work.com," but only from people who joined on or before the year 2000. I don't want to necessarily remove the field from the record, but just delete the entry so that it's blank. However, this ends up deleting the whole record. Is there another way to do this? Maybe such as retrieving the ID's of these record?