• saurabh_kumar_S
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
I have an standard object called case, I need to update a  custom field with case object attachment name
I have a custom object where the record has a button to create an opportunity.  There is a lookup on the custom object that fills in the opportunity name when the opportunity is created through the button.  I have 2 lines of code I can't get covered and I'm not sure how to accomplish, please help!  TIA!

These are the 2 lines I can't get covered
acc.Related_to_Opportunity__c = MapAccCom.get(acc.id);
        oppList.add(acc);

trigger IDM_GSVT_UpdateRelatedOpportunity on EOMPDiscountRequest__c (before insert) {
    //Name - field to be added to Related_to_Opportunity
    //Related_to_Opportunity__c //look up on GSVT record to be updated
    Map<Id, Id> MapAccCom = new Map<Id, Id>();
    for(EOMPDiscountRequest__c comm:trigger.new)
    {
        MapAccCom.put(comm.Name,comm.id);
    }
    List<EOMPDiscountRequest__c> disc = [Select id from EOMPDiscountRequest__c where id IN :MapAccCom.keyset()];
    List<EOMPDiscountRequest__c> oppList = new List<EOMPDiscountRequest__c>();
    for(EOMPDiscountRequest__c acc : disc)
    {
        acc.Related_to_Opportunity__c = MapAccCom.get(acc.id);
        oppList.add(acc);
    }
    update oppList;

}

@isTest
private class IDM_GSVT_UpdateRelatedOpportunityTest {
 private static EOMPDiscountRequest__c createDiscountRequest(string dealerCode, string marketSegment, string segmentType, string discountType, string majorClass) {
        Id OTOretro = Schema.SObjectType.EOMPDiscountRequest__c.getRecordTypeInfosByName().get('OTO Retroactive').getRecordTypeId();
        EOMPDiscountRequest__c discountRequestObj = new EOMPDiscountRequest__c(Dealer_Code__c = dealerCode,
                                                                                Market_Segment_Picklist__c = marketSegment,
                                                                                Major_Class__c = majorClass,
                                                                                Industry_GASD__c = segmentType,
                                                                                Valid_From__c = system.today(),
                                                                                Valid_To__c = system.today(),
                                                                                Discount_Type__c = discountType,
                                                                                recordTypeId = OTOretro,
                                                                                M_Rate__c = 25);
        insert discountRequestObj;
        return discountRequestObj;
    }
private static testMethod void testController(){    
    Map<String,schema.recordtypeinfo> rtMapByName=schema.sobjecttype.account.getRecordtypeInfosByName();
        Id ryById=rtMapByName.get('Customer/Partner').getRecordTypeId();
        Account acc = new Account(Name = 'Account1',RecordtypeId = ryById,Account_Usage__c='GCI');
        insert acc;
        
        Map<String,schema.recordtypeinfo> rtdelMapByName=schema.sobjecttype.account.getRecordtypeInfosByName();
        Id rydelById=rtdelMapByName.get('Dealer').getRecordTypeId();
        Account delacc = new Account(Name = 'delAccount1',RecordtypeId = rydelById,Account_Usage__c='GCI');
        insert delacc;
    
       Id oppRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts & Service Opportunity').getRecordTypeId();
        Opportunity oppty = new Opportunity();
        oppty.Name = 'test1';
        oppty.RecordTypeId = oppRecordTypeId;
        oppty.AccountId = acc.id;
        oppty.Major_Class__c = 'CSA';
        oppty.Dealer__c = delacc.id;
        oppty.Marketing_Campaign__c = 'GD UC';
        oppty.Amount = 50000.00;
        oppty.LeadSource = 'other';
        oppty.CurrencyIsoCode = 'INR';
        oppty.StageName = 'Closed Won';
        oppty.CloseDate = system.today();
        oppty.Description = 'test';
        oppty.Primary_Lost_Sale_Reason__c = 'Product';
        oppty.Primary_Lost_Sale_Reason_Detail__c = 'Worktool';
        oppty.Winning_Competitor_legacy__c = 'BYG';
        oppty.GASD_Industry__c = 'Construction Industries';
        insert oppty;
        }
        
}

 
  • October 02, 2017
  • Like
  • 0

I have a validation rule that prevents a community user from creating a case if he has yet to qualify 2 or more previous cases (this is a way to measure the quality of the service). However, the validation rule marks the error until the user tries to save, and that is not the operation I want .... I would like that whenever a user has 2 or more cases without qualifying, it prevents the creation of cases , that is to say, that it does not have the possibility to fill any field until it responds the cases that it has pending to qualify.

P.S. sorry if my English is not very good, it is not my native language and I use an automatic translator to ask this question.

Thank you!

There is a critical update - View Setup permission now required to run tests synchronously using the POST method for runTestsSynchronous. How to enable this Permission. Please explain in steps