• madonaa max 9
  • -3 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 5
I'm new to salesforce and coding. please suggest me what to do here!!!

I have three objects opportunities, projects and tasks.
relationship between them is,
Opportunity to projects--> lookup 
projects to tasks-->master-detail.

i need the status field on projects to populate 'complete' when an opportunity is closed won/lost. 
but i can't do this because the projects status field is a managed package formula field which cannot be edited.

The project status field formula is, if all its task records status fields are marked as complete then it will also be completed.

i dont see any relation directly from opportunity and tasks.

So now i need to make a trigger/process builder/workflow/lightning flow so when an opportunity is closed it will mark these tasks as complete which in turn marks the project as complete and make that unavailable to edit. 

How can i achieve this. I'm new to coding, so if it is a trigger how should the code be. 

Your help is really appreciated!!!!!!!
Hi Friends,

I have a requirement where I need to create a Quote when a Opportunity Product is added.
When creating a Quote I need to copy contact details based on Opportunity Contact Role where Contact is Primary.
I am getting Contact Name but, got Stuck in getting a Contact Email, Contact MailingAddress and Contact Other Address. It is not getting populated in Quote.
/** Trigger on Opportunity Line Item to insert Quote and Quotelineitem **/
trigger quoteCreation on OpportunityLineItem (after insert) {
    if(Trigger.isAfter && Trigger.isInsert){
        List<Quote> quoteList = new List<Quote>();
        Set<ID> oppIds = new Set<ID>();
        Set<Id> processIds = new Set<ID>();
        for(OpportunityLineItem oppli : Trigger.New){
        List<OpportunityLineItem> opplList = new List<OpportunityLineItem>();
        if(oppIds != null && oppIds.size() >0){
            opplList = [SELECT Id, Opportunity.Name, Opportunity.AccountId, Opportunity.Account.PersonContactId, OpportunityId, Opportunity.Account.Name, Opportunity.Account.PersonEmail,
                        Opportunity.Account.Salutation, Opportunity.Account.BillingCity, Opportunity.Account.BillingCountry, Opportunity.Account.BillingPostalCode, Opportunity.Account.BillingState,
                        Opportunity.Account.ShippingCity, Opportunity.Account.ShippingCountry, Opportunity.Account.ShippingPostalCode, Opportunity.Account.ShippingState,
                        Opportunity.Account.BillingStreet, Opportunity.Account.ShippingStreet, Opportunity.ContactId, Opportunity.Account.isPersonAccount
                        FROM OpportunityLineItem 
                        WHERE Id IN:oppIds];
        if(opplList != null && opplList.size() >0 ){
            for(OpportunityLineItem oppli : opplList) {        
                Quote quo = new Quote();
                quo.Name = 'Quote - ' + oppli.Opportunity.Name;
                quo.Status = 'Draft';
                quo.OpportunityId = oppli.OpportunityId;
               // Getting Contact Details from Business Account.
                if(oppli.Opportunity.Account.isPersonAccount == False)
                    quo.ContactId = oppli.Opportunity.ContactId;
                    quo.Email = oppli.Opportunity.Contact.Email;
                          Need to get Contact Mailing Address and Other Address.

               // Getting Contact Details from Person Account.
                    quo.ContactId = oppli.Opportunity.Account.PersonContactId;
                    quo.Email = oppli.Opportunity.Account.PersonEmail;
                    quo.BillingName = oppli.Opportunity.Account.Name;
                    quo.ShippingName = oppli.Opportunity.Account.Name;
                    quo.BillingStreet = oppli.Opportunity.Account.BillingStreet; 
                    quo.BillingCity = oppli.Opportunity.Account.BillingCity;
                    quo.BillingCountry = oppli.Opportunity.Account.BillingCountry;
                    quo.BillingPostalCode = oppli.Opportunity.Account.BillingPostalCode;
                    quo.BillingState = oppli.Opportunity.Account.BillingState;
                    quo.ShippingStreet = oppli.Opportunity.Account.ShippingStreet;        
                    quo.ShippingCity = oppli.Opportunity.Account.ShippingCity;
                    quo.ShippingCountry = oppli.Opportunity.Account.ShippingCountry;
                    quo.ShippingPostalCode = oppli.Opportunity.Account.ShippingPostalCode;
                    quo.ShippingState = oppli.Opportunity.Account.ShippingState;
        try {        
            if(quoteList.size() > 0) {    
                insert quoteList;
        catch(Exception e) {
            System.debug('The Following Exception has occurred: '+ e.getLinenumber() + ' : ' + e.getMessage());
        // Insert Quote Line Item 
        set<Id> oppId = new Set<Id>();
        set<Id> pcrId = new set<Id>(); 
        List<QuoteLineItem> oliPist = new  List<QuoteLineItem>();
        if(quoteList != null && quoteList.size() >0){
            for(Quote quo : quoteList) {
                if(quo.opportunityId != null) {
        Map<Id, List<OpportunityLineItem>> olitoOpp = new  Map<Id, List<OpportunityLineItem>>();
        if(oppId != null && oppId.size() >0){
            for(OpportunityLineItem oli : [SELECT Id, Quantity, UnitPrice, PricebookEntryId, Product2Id, OpportunityId 
                                           FROM OpportunityLineItem WHERE opportunityId IN : oppId]) {
                                               if(olitoOpp.containsKey(oli.opportunityId)) {
                                               else {
                                                   olitoOpp.put(oli.opportunityId, new List<OpportunityLineItem> {oli});
        for(Quote quot : quoteList) {
            if(olitoOpp.containsKey(quot.opportunityId)) {
                for(OpportunityLineItem  oli : olitoOpp.get(quot.opportunityId)){
                    if(oli != null)
                        oliPist.add(new QuoteLineItem(QuoteId=quot.Id,Quantity = oli.Quantity,PricebookEntryId = oli.PricebookEntryId,UnitPrice = oli.UnitPrice,Product2Id = oli.Product2Id));
        if(!oliPist.isEmpty()) {
            insert oliPist;

Kindly review my code and let me know how can I get contact values.

Thanks in Advance.

I am trying to do the following.  Have a button on teh parenet record that will render the child records in a datatable(editable)
What ever is selected I need to be able to create a new record from the rows slected.
I have a LWC and controller.  The LWC is wrapped in a aura compone tbut when selected it just has the header columns.
Should I try to  grab the child records in the .js?

Then how do I add a button to the LWS to create a new record from the rows slected?

Thank you for your help,
Hello All,
Can you update a field in LWC?  I want to append a child record field info with info from a parent record? So for example Contact.info = Contact.info + Account.info.  Is this possibe or does this need to be handle in a Apex class?
Hi Guys. 
I have just begun the SuperBadge: Lightning Experience Specialist. I am unable to rename standard objects. Any thoughts?