• Robin Shira
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I want to assign my case to article automatically is there any way to assign.

 please help
Thanks in advanced
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please enter a valid email'));
return null;

how to add in test class.
Thanks!!!
trigger QuoteLineItemTrigger on QuoteLineItem (after insert, after update){

    List<QuoteLineItem> newQlis = Trigger.new;
    Map<Id, QuoteLineItem> oldQlis = Trigger.oldMap;

    // Collecting reference Ids.
    Set<Id> quoteIds = new Set<Id>();
    Set<Id> oppIds = new Set<Id>();
    Map<Id, Quote> parentQuotes;

    if (Trigger.isInsert || Trigger.isUpdate) {

        for (QuoteLineItem qli : newQlis) {
            quoteIds.add(qli.QuoteId);
        }
        parentQuotes = new Map<Id, Quote>([SELECT Id FROM Quote WHERE Id IN: quoteIds]);

        for (Quote quote : [SELECT Id, Name, OpportunityId, IsSyncing FROM Quote WHERE Id IN: quoteIds]) {
            oppIds.add(quote.OpportunityId);
        }
    }


    List<QuoteLineItem> updateQuoteLineItem;
    if (Trigger.isInsert) {
        String JSONContent = Json.Serialize(newQlis);
        JSONParser parser = JSON.createParser(JSONContent);
        System.debug('parser-------->'+parser );

        List<String> OpptyLineId = new List<String>();
        List<String> QuoteLineId = new List<String>();

        while (parser.nextToken() != null) {
            if (parser.getCurrentToken() == JSONToken.VALUE_STRING && parser.getCurrentName() == 'OpportunityLineItemId') {
                OpptyLineId.add(parser.getText());
            }

            if(parser.getCurrentToken() == JSONToken.VALUE_STRING && parser.getCurrentName() == 'Id') {
                QuoteLineId.add(parser.getText());
            }

            parser.nextToken();

            if(parser.getCurrentToken() == JSONToken.VALUE_STRING && parser.getCurrentName() == 'OpportunityLineItemId') {
                OpptyLineId.add(parser.getText());
            }

            if(parser.getCurrentToken() == JSONToken.VALUE_STRING && parser.getCurrentName() == 'Id') {
                QuoteLineId.add(parser.getText());
            }
        }
        System.debug('OpptyLineId-------->'+OpptyLineId);
        System.debug('QuoteLineId-------->'+QuoteLineId);


        Map<String, String> mapQuoteOppty = new Map<String, String>();
        Integer iCount = 0;
        for (String strOppLineId : OpptyLineId) {
            String iQuoteLineId = QuoteLineId[iCount];
            mapQuoteOppty.put(iQuoteLineId, strOppLineId);
            iCount++;
        }

        Map<Id, OpportunityLineItem> MapOLI = new Map<Id, OpportunityLineItem>([
            SELECT Id, Name, ServiceDate, Tax__c, Tax_Rate__c, Promo_Code__c, Onsite_Additional_Price__c, OpportunityId, Event__c
            FROM OpportunityLineItem WHERE OpportunityId IN: oppIds
        ]);

        Map<Id, QuoteLineItem> MapQLI = new Map<Id, QuoteLineItem>([
            SELECT Id, ServiceDate, Event__c, Opp_Line_Item_Id__c, Opportunity_Line_Item_Name__c, Tax__c, Tax_Rate__c, Promo_Code__c, Onsite_Additional_Price__c
            FROM QuoteLineItem WHERE QuoteId IN: quoteIds
        ]);
        
        
        updateQuoteLineItem = new List<QuoteLineItem>();
        for (QuoteLineItem qli : MapQLI.values()) {
            if(mapQuoteOppty.get(qli.Id) != null) {
                String OppID = mapQuoteOppty.get(qli.Id);
                OpportunityLineItem OLI = MapOLI.get(OppID);

                qli.Event__c = OLI.Event__c;
                qli.Opp_Line_Item_Id__c = OLI.Id;
                qli.Opportunity_Line_Item_Name__c = OLI.Name;
                qli.ServiceDate = OLI.ServiceDate;
                qli.Onsite_Additional_Price__c = OLI.Onsite_Additional_Price__c;
                qli.Tax__c = OLI.Tax__c;
                qli.Tax_Rate__c = OLI.Tax_Rate__c;
                qli.Promo_Code__c = OLI.Promo_Code__c;
                updateQuoteLineItem.add(qli);
            }
        }

        try {
            if (updateQuoteLineItem != null && !updateQuoteLineItem.isEmpty()) {
                update updateQuoteLineItem;
            }
        } catch (Exception e) {
            System.debug(e.getMessage());
        }
    }


    // Updating parent quote indicators based on QLI values.
    Map<Id, Quote> quotes2Update = new Map<Id, Quote>();
    if (Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {

        for (QuoteLineItem qli : newQlis) {
            Quote parentQuote = parentQuotes.get(qli.QuoteId);

            if (qli.IsCourse__c || qli.Delivery_Format__c == 'Self Paced' || qli.IsPrepay__c) {
                if (qli.IsCourse__c) {
                    parentQuote.QLI_Course__c = true;
                }
                if (qli.Delivery_Format__c == 'Self Paced') {
                    parentQuote.QLi_Product__c = true;
                }
                if (qli.IsPrepay__c) {
                    parentQuote.QLi_Savings__c = true;
                }
                quotes2Update.put(parentQuote.Id, parentQuote);
            }
        }

        try {
            update quotes2Update.values();
        }
        catch (Exception e) {
            System.debug(e.getMessage());
        }
    }
}

please help..
I want to assign my case to article automatically is there any way to assign.

 please help
Thanks in advanced
This is the original code for trigger
---------------------------------------------
updateQuoteLineItem = new List<QuoteLineItem>();
        for (QuoteLineItem qli : MapQLI.values()) {
            if(mapQuoteOppty.get(qli.Id) != null) {
                String OppID = mapQuoteOppty.get(qli.Id);
                OpportunityLineItem OLI = MapOLI.get(OppID);

                qli.Event__c = OLI.Event__c;
                qli.Opp_Line_Item_Id__c = OLI.Id;
                qli.Opportunity_Line_Item_Name__c = OLI.Name;
                qli.ServiceDate = OLI.ServiceDate;
                qli.Onsite_Additional_Price__c = OLI.Onsite_Additional_Price__c;
                qli.Tax__c = OLI.Tax__c;
                qli.Tax_Rate__c = OLI.Tax_Rate__c;
                qli.Promo_Code__c = OLI.Promo_Code__c;
                updateQuoteLineItem.add(qli);
            }

Need test class for the above code.
It is very urgent...Please do the needful....Thanks in advance