• Jsingh
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies

hi
 I have custom object for Quote,opportunitylineitem,product and so on....
my requirement is to -1.only one quote should be synced with opportunity.
                      2.first delete the opportunity product list than add the line item
                        of synced Quote.
                      3.The quote line item for that(synced) quote should be populated
                        into the related opportunity product(opplineitem)

Relation ship in my objects are
 Quote-----Opportunity--Masterdetail and lookup
 Quote----Quotelineitem--Master Detail
Quotelineitem----Opportunity-- lookup
OpportunityProduct-------Quotelineitem--look up
OpportunityProduct----Opportunity--Masterdetail
OpportunityProduct-----Product-- lookup

i had achieved first(1) and second(2) but not third(3).i had written code for third condition also
but it is not working.
my handler and trigger is here

                                  HANDLER
public class Mytestclassforupdatelineitem {
   
    public static void UpdateSyncedOpportunity(List<Quote__c> lstQuotes) {    
        system.debug('lstQuotes : ' +lstQuotes);
       
        List<Opportunity__c> lstOpportunitiesToUpdate = new List<Opportunity__c>();
       
        Set<string> setOpportunityIDs = new Set<string>();
        List<OpportunitylineItem__c> lstOppLineItems = new List<OpportunitylineItem__c>();
       
        for(Quote__c quote: lstQuotes) {    
            Opportunity__c opp = new Opportunity__c();
            opp.Id = quote.Opportunity__c;              
            opp.SyncedQuote__c = quote.id;
            lstOpportunitiesToUpdate.add(opp);            
           
            setOpportunityIDs.add(quote.Opportunity__c);
        }
       
        if(lstOpportunitiesToUpdate.size() > 0){
            update lstOpportunitiesToUpdate;
        }
       
        system.debug('setOpportunityIDs : ' +setOpportunityIDs);
       
        if(setOpportunityIDs.size() > 0){
            lstOppLineItems = [select id, name, Quantity__c from OpportunitylineItem__c where Opportunityproducts__c =: setOpportunityIDs ];            
        }
       
        if(lstOppLineItems != null && lstOppLineItems.size() > 0){
            delete lstOppLineItems;
        }
    }    
       
    public static void UpdateSyncedOpportunityLineItems(List<Quote__c> lstQuotes) {
        system.debug('lstQuotes in UpdateSyncedOpportunityLineItems : ' +lstQuotes);
       
        // set to store the opportunity id's for associated quotes on which sync is set as true
        Set<Id> setOpportunityIDs = new Set<Id>();  
        Set<Id> setSyncedQuoteIDs = new Set<Id>();  
        List <Quote__c> lstAllAssociatedQuotes = new List<Quote__c>();
        for(Quote__c quote: lstQuotes) {
            setOpportunityIDs.add(quote.Opportunity__c);
            setSyncedQuoteIDs.add(quote.id);
        }
        system.debug('setOpportunityIDs : ' +setOpportunityIDs);
       
        if(setOpportunityIDs.size() > 0){
            lstAllAssociatedQuotes = [select id, Name, Opportunity__c,IsSyncing__c from Quote__c where Opportunity__c =: setOpportunityIDs];
        }
       
        System.debug('lstAllAssociatedQuotes  :'+lstAllAssociatedQuotes);
        List<Quote__c> lstQuotesToUpdate = new List<Quote__c>();
        if(lstAllAssociatedQuotes.size() > 0){
            for(Quote__c qt : lstAllAssociatedQuotes){
                for(Quote__c syncedqt : lstQuotes){
                    if(syncedqt.Opportunity__c == qt.Opportunity__c &&
                       syncedqt.id != qt.id && qt.IsSyncing__c == true){
                           qt.IsSyncing__c = false;
                           lstQuotesToUpdate.add(qt);
                       }
                }                
            }
        }
       
        if(lstQuotesToUpdate.size() > 0){
            update lstQuotesToUpdate;
        }
       
                        //code to add opportunity line item from quoteline item        
       
       
        List<OpportunitylineItem__c> lstofoppitems = new List<OpportunitylineItem__c>(); //list for opportunitylineitem
       
        List<Quote_Line_Items__c> lstofQlineitem = New List<Quote_Line_Items__c>();//list for quotelineitem
       
        if(setSyncedQuoteIDs.size() > 0){
            lstofQlineitem=[Select ID,Name,Opportunity__c,Quote_Name__c,Product__c,Quantity__c,UnitPrice__c From Quote_Line_Items__c where Id =:setSyncedQuoteIDs];
        }
       
        //store the the lineitems which are associated with synced quote
        system.debug('listofquotelineitem:'+lstofQlineitem);
       
        //creating instance for quotelineitem and paas the list of associated quotelineitem with synced quote and
        // in for loop create the instance for opplineitem and assign value in opportunity line item
       
        if(lstofQlineitem != null && lstofQlineitem.size() > 0){
            for(Quote_Line_Items__c quotelineitems : lstofQlineitem){
                system.debug('quotelineitems'+ quotelineitems);
               
                OpportunitylineItem__c opplineitem = new OpportunitylineItem__c();
               
                opplineitem.UnitPrice__c = quotelineitems.UnitPrice__c;
                opplineitem.Name = quotelineitems.Name;
                opplineitem.Quantity__c =  quotelineitems.Quantity__c;
                opplineitem.ProductCode__c = quotelineitems.Product__c;
                opplineitem.Opportunityproducts__c= quotelineitems.Opportunity__c;
                opplineitem.QuoteLineItems__c = quotelineitems.id;
            }
           
            if( lstofoppitems == null && lstofoppitems.size() > 0){
                insert lstofoppitems;
                system.debug('listofopportunitylineitem:'+ lstofoppitems);
            }
        }
    }
}



                                 Trigger

trigger mytesttriggerforupdatelineitem on Quote__c (after update) {
   
    if (trigger.isAfter && trigger.isUpdate ){// check if trigger is isAfter and isUpdate
        List <Quote__c> lstToBeModifiedQuotes = new List<Quote__c>();
       
        for(Quote__c qt : trigger.new){ // check for value change of isSynced
           
            Quote__c oldquote = trigger.OldMap.get(qt.id);//get the quote with old values
           
            if(qt.IsSyncing__c != oldquote.IsSyncing__c && qt.IsSyncing__c == true){ //check with oldvalues and new values
                lstToBeModifiedQuotes.add(qt);                
            }
        }
       
        system.debug('lstToBeModifiedQuotes : ' +lstToBeModifiedQuotes);
        if(lstToBeModifiedQuotes.size() > 0){
            Mytestclassforupdatelineitem.UpdateSyncedOpportunity(lstToBeModifiedQuotes);
            Mytestclassforupdatelineitem.UpdateSyncedOpportunityLineItems(lstToBeModifiedQuotes);
        }
    }
}

Thanks
  • October 30, 2019
  • Like
  • 0
In Lightning App Builder module  I hade finished all challenge of this module in my trailhead playground.but when i came in last challenge '"work with custom lightning component" i am not able to install the unmanaged package "Contacts Today" in my playground.it is giving following error

"This page has an error. You might just need to refresh it. afterRender threw an error in 'lightning:accordionSection' [Cannot read property 'dispatchEvent' of null] Failing descriptor: {lightning:accordionSection}"
and
when i close it
it display

"This app can't be installed.
There are problems that prevent this package from being installed.
You cannot install an unlocked package without a namespace into an org with a namespace".
Done
Please help me solve this
Regards
Jyotsana
  • October 04, 2019
  • Like
  • 0
Hi

When i am trying to call Apex class in Process Build using @invocablemethod it's giving following error.(the same class
i was calling using trigger also)

unsupported parameter type string.valid invocable parameters must be
List type like list where T is a supported type
 apex code is here


1
//Helper class to update customfield with autonumber field in after insert
public class updatfield
4
{
5
@InvocableMethod(Label='abc')
6
!
public static void updateoutputfield(string accountid ) //Helper class method passing one parameter
7
{
8
if(string.isNotBlank(accountid)) //check the accountid is not blank
9
{
10

11
//retrieve the value of all required field from account
12

13
Account acc=[select id , Name,Division__c, Group__c, Subgroup__c, AutoNumber__c from account where id=:accountid];
14

15
acc.Account_Number__c= acc.Division__c.substring(0,2).Touppercase()+'-'+ acc.Group__c.substring(0,2).Touppercase() + '-' + acc.Subgroup__c.substring(0,2).Touppercase() + '-'+ acc.AutoNumber__c;
16
update acc;
17

18
system.debug('Record has updated.............' + acc);
19
}
20

21
}
22
}


Trigger Code

//Trigger to update custom field Account Number on Account abject with Auto number field
trigger autonumberpopulate on Account (after insert) {
    set<Account> listOfAccount =new set<Account> ();//we want unique value that's why we are using 'set' collection 
    
    for (Account accounts: [select id, Name, Division__c,Group__c,Subgroup__c,AutoNumber__c from Account])
    {
        
        ListOfAccount.add(accounts);  //get all account id
    }
    
    for(Account newaccounts : Trigger.new) // retrieve all new accounts using for loop (bulkify)
    
    {
        
        //calling handler method updateoutputfield using handler class updatfield.
        updatfield.updateoutputfield(string.valueOf(newaccounts.id));
        

    }
}
 
Please help me

Regards
jyotsana 

 
  • September 23, 2019
  • Like
  • 0
hi

when ever i am trying to launch my trailhead playgroun (old or new one)  following error comes
[This site can’t be reached
curious-raccoon-og38f6-dev-ed--c.documentforce.com’s server IP address could not be found.
Try running Windows Network Diagnostics.
DNS_PROBE_FINISHED_NXDOMAIN]
 please help me out i was trying from yesterday.
Thanks
jyotsana


 
  • September 18, 2019
  • Like
  • 0
In Lightning App Builder module  I hade finished all challenge of this module in my trailhead playground.but when i came in last challenge '"work with custom lightning component" i am not able to install the unmanaged package "Contacts Today" in my playground.it is giving following error

"This page has an error. You might just need to refresh it. afterRender threw an error in 'lightning:accordionSection' [Cannot read property 'dispatchEvent' of null] Failing descriptor: {lightning:accordionSection}"
and
when i close it
it display

"This app can't be installed.
There are problems that prevent this package from being installed.
You cannot install an unlocked package without a namespace into an org with a namespace".
Done
Please help me solve this
Regards
Jyotsana
  • October 04, 2019
  • Like
  • 0
hi

when ever i am trying to launch my trailhead playgroun (old or new one)  following error comes
[This site can’t be reached
curious-raccoon-og38f6-dev-ed--c.documentforce.com’s server IP address could not be found.
Try running Windows Network Diagnostics.
DNS_PROBE_FINISHED_NXDOMAIN]
 please help me out i was trying from yesterday.
Thanks
jyotsana


 
  • September 18, 2019
  • Like
  • 0
Hi, I am having trouble with the "Attributes and Expressions" module from trailhead.

Here is the challenge:
Create a Lightning Component to display a single item for your packing list.
  • Create a component called campingListItem that displays the name (ui:outputText) and the three custom fields using the appropriate output components.
  • Add an attribute named 'item' for type Camping_Item__c.
I created an component named campingListItem and this is the code:
<aura:component >
    <aura:attribute name="item" type="<my_domain>__Camping_Item__c"/>
    
    <ui:outputText value="{!v.item.Name}"/>
    <ui:outputCheckbox value="{!v.item.<my_domain>__Packed__c}"/>
    <ui:outputCurrency  value="{!v.item.<my_domain>__Price__c}"/>
    <ui:outputNumber value="{!v.item.<my_domain>__Quantity__c}"/>
</aura:component>

The error that I am getting is: "Challenge Not yet complete... here's what's wrong: 
The packingListItem Lightning Component's attribute tag doesn't exist or its attributes are not set correctly."

With this, I tried to create another component, with the name "packingListItem", but It didn't work.

Can anyone help me?

Thanks,