+ Start a Discussion
Harsha s 56Harsha s 56 
HI all
   Im new to salesforce . i want to write  a trigger  when ever Email/ phone of the account  is updated ,all the contact email should be same. any one help me to solve 

Thank you
Harsha
Best Answer chosen by Harsha s 56
sunny522sunny522
trigger SameEmailOnAllContacts on Account (after update) {
    Set<Id> setAccountId = new Set<Id>();
    for(Account acc:trigger.new) {
        if(Trigger.oldMap.get(acc.ID).Email__c != acc.Email__c || Trigger.oldMap.get(acc.ID).phone != acc.phone) {
            setAccountId.add(acc.id);
        }
    }
    List<Contact> lstContact = new List<Contact>();
    for(Account acc:[Select id,Email__c,(select id,Email from Contacts) from Account where Id in:setAccountId]) {
        for(Contact con:acc.contacts) {
            if(con.Email != acc.Email__c) {
                con.Email = acc.Email__c;
                lstContact.add(con);
            }
        }
    }
    if(lstContact.size() >0) {
        update lstContact;
    }
}

Please use this trigger code Harsha .
Best Answer chosen by SAGAR LOKEGAONKAR
Amit Jadhav 13Amit Jadhav 13
Select id (Select id, Name From Contact ) From Account

Example of SubQuery Parent To Child

Select Id , Name, AccountId From Contact

Example of SubQuery child to Parent


thanks!

Regards,

Amit Jadhav 
Best Answer chosen by sai prakash 14
sai prakash 14sai prakash 14
Thanks khan. that second link is working .

To work on this we need to use two js files. i am providing the two js link files to download and store them as static resource in your org

https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js

https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js

In the second link u have to add window.xlsx=xlsx then only it will work otherwise it will show error.
where to add that is explained in this link- https://sfdcbro.com/2018/11/18/using-sheetjs-with-lightning-components/

 
Kayla SchneiderKayla Schneider 
Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Fulfillment Creation” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: FIELD_INTEGRITY_EXCEPTION: Assigned To ID: id value of incorrect type: 0063i000003ZVyyAAG. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 990470032-165661 (-1137041356): []
Best Answer chosen by Kayla Schneider
Khan AnasKhan Anas (Salesforce Developers) 
Hi Kayla,

Greetings to you!

Please make sure you are using correct Assigned To Id. 
Assigned To ID -> [OpportunityLineItem].Opportunity.OwnerId

Please refer to the below link which might help you further.

https://trailheadbaby.blogspot.com/2018/01/lightning-experience-specialist.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
khaviya G Senthilkumarkhaviya G Senthilkumar 
I have created a custom object and a tab. However its not visible on the page layout and as a tab as well. 
Checked evrything below
Profiles
 Permission sets
App manager
Page layout

Nothing seems to work. Please help out
Best Answer chosen by khaviya G Senthilkumar
Sunil RathoreSunil Rathore
Hi,
For Custom tab in Lightning environment please refer the following link:
https://developer.salesforce.com/forums/?id=906F0000000DEHGIA4

And to add the custom button on the page layout of the Lightning environment follow the following steps:
1. Edit the page layout in classic environment.
2. Add the button/tab in the Quick Actions in the Salesforce Classic Publisher section of the page layout.
3. Save the page layout and check-in Lightning environment.

Let me know if it solves your problem.

Many Thanks,
Sunil Rathore
Vinay RamuVinay Ramu 
Dear Gurus,

I have created a custom object Voter__c with standard field "Name" and custom Master-Detail field "Precinct__c"(relationship with custom object Precinct__c).
Requirement is to upload few Voter records for precinct and queued job failing with this error. Does not clearly point out what's wrong with the file.
My file to upload:
<?xml version="1.0" encoding="UTF-8"?>
<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<sObject>
<Name>[Bulk API] Voter 1</Name>
<Precinct__c>a0J7F00000Hw7PuUAJ</Precinct__c>
</sObject>
<sObject>
<Name>[Bulk API] Voter 2</Name>
<Precinct__c>a0J7F00000Hw7PuUAJ</Precinct__c>
</sObject>
</sObjects>

Thanks,
Vinay
Best Answer chosen by Vinay Ramu
Vinay RamuVinay Ramu
Job operation was "query" upon changing operation to "insert", the Bulk API job was successful.
Alana SantosAlana Santos 
Hello guys! :)

Could someone help me with this?

I'm trying to deploy classes and triggers using the change set settings, but the error bellow persists. Can anyone help? Because in my researches, I found out that I'm not the only one to face that, even though , is so difficult to find a solution...

Error:

' line -1, column -1: Dependent class is invalid and needs recompilation: Class <class name> : Variable does not exist: run
Stack Trace: null '

I've tried:

> Opened a ticket on SF to the "Compile all triggers" to appears in my work org;
> Compile all triggers and classes;
> Update the API versions of my classes and triggers;
> Validat my classes with the other components that it has dependencies.

I don't know what more I can do...
Best Answer chosen by Alana Santos
Khan AnasKhan Anas (Salesforce Developers) 
Hi Alana,

Greetings to you!

I tried to research your problem and found that this is a known issue. They have provided a workaround to "Compile all classes"  which you have already tried. Keep watching this issue until get fixed.

https://success.salesforce.com/issues_view?id=a1p3A000000mCXpQAM

You can select the 'This Issue Affects Me' button to report your account and receive updates.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Nevin O'Regan 3Nevin O'Regan 3 
Hi guys,

I have created 12 custom number fields in the OppLineItem, each labeled a month of the year. I have also created a custom formula text field in the OppLineItemSchedule object called Month which defines the month based on the scheduled date.
I am trying to create a trigger to map the Quantity value from the related OppLineItemSchedule record to the relevant OppLineItem Month field. I have created the below trigger but the issue is that it is populating every Month field on the OppLineItem with a value even if there is not a related OppLineItemSch Quantity. 

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> MapMonths = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         MapMonths.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c, 
                                            February__c, 
                                            March__c, 
                                            April__c, 
                                            May__c, 
                                            June__c, 
                                            July__c, 
                                            August__c, 
                                            September__c, 
                                            October__c, 
                                            November__c,
                                            December__c From OpportunityLineItem Where Id IN :MapMonths.Keyset()])
    {
        if(MapMonths.containsKey(oli.id))
        {
            OppLineItemList.add(new OpportunityLineItem(Id = oli.id, January__c=MapMonths.get(oli.id), 
                                                                     February__c=MapMonths.get(oli.id),
                                                                        March__c=MapMonths.get(oli.id), 
                                                                     April__c=MapMonths.get(oli.id),
                                                                     May__c=MapMonths.get(oli.id),
                                                                     June__c=MapMonths.get(oli.id),
                                                                     July__c=MapMonths.get(oli.id),
                                                                     August__c=MapMonths.get(oli.id),
                                                                     September__c=MapMonths.get(oli.id),
                                                                     October__c=MapMonths.get(oli.id),
                                                                     November__c=MapMonths.get(oli.id),
                                                                     December__c=MapMonths.get(oli.id)));
                                                                                    
        }
    }
    update OppLineItemList;
}
Best Answer chosen by Nevin O'Regan 3
Boss CoffeeBoss Coffee
Try the following.
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    
    // UPDATED: Must handle multiple children for a single parent
    // Instead of a single OpportunityLineItem, hold a list of them
    Map<Id,List<OpportunityLineItemSchedule>> MapMonths = new Map<Id, List<OpportunityLineItemSchedule>>();
    
    // Have a temp list ready for looping
    List<OpportunityLineItemSchedule> tempOlisList;
    
    // Now populate the months map
    for(OpportunityLineItemSchedule sch : trigger.new) {
        // Check if the map already has an entry for the parent Id (key)
        if(MapMonths.containsKey(sch.OpportunityLineItemId)) {
            // If it does, then update the list with the new value (so it will not override the previous value)
            tempOlisList = MapMonths.get(sch.OpportunityLineItemId);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        } else {
            // Otherwise, we will create a new entry in the map with a list value of just the current iteration's OLIS
            tempOlisList = new List<OpportunityLineItemSchedule);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        }
    }

    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            
            // UPDATE: Because we have a list of children now, we will need to loop through all of them to assign values to each month before moving on to the next Opportunity Line Item
            // Create a for loop to go through the list of children
            for(OpportunityItemListSchedule olis : MapMonths.get(oli.id)) {
                
                // Create a switch statement to check what value is the Month
                switch on olis.Month__c {
                    // If the opportunity line item schedule's Month field was January
                    when 'January' {
                        // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                        oli.January__c = olis.Quantity;
                    }
                    when 'February' {
                        oli.February__c = olis.Quantity;
                    }
                    when 'March' {
                        oli.March__c = olis.Quantity;
                    }
                    when 'April' {
                        oli.April__c = olis.Quantity;
                    }
                    when 'May' {
                        oli.May__c = olis.Quantity;
                    }
                    when 'June' {
                        oli.June__c = olis.Quantity;
                    }
                    when 'July' {
                        oli.July__c = olis.Quantity;
                    }
                    when 'August' {
                        oli.August__c = olis.Quantity;
                    }
                    when 'September' {
                        oli.September__c = olis.Quantity;
                    }
                    when 'October' {
                        oli.October__c = olis.Quantity;
                    }
                    when 'November' {
                        oli.November__c = olis.Quantity;
                    }
                    when 'December' {
                        oli.December__c = olis.Quantity;
                    }
                    // If it did not find any matches
                    when else {
                        // EDIT: do not put anything here for now
                        // You can leave this empty or put something in here to handle cases where the Month field is NOT the name of the month
                        // e.g. Month field was for some reason populated with 'Apple'
                    }
                }
            }
            OppLineItemList.add(oli);
        }
    }
    update OppLineItemList;
}
Nevin O'Regan 3Nevin O'Regan 3 
Hi guys,

I am relatively new to writing triggers and I am running into an issue with one that I am currently working on. 

I would like to update custom fields in the OpportunityLineItem object with the value from the OpportunityLineItemSchedule.Quantity field. I have 12 custom fields in the OpportunityLineItem for each month of the year, Jan to Dec.

Here is the code that I have so far but I am running into an error "Method does not exist or incorrect signature: void put(Id, Decimal) from the type Map<Id,Integer>" on Line 6.

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
Map<Id,Integer> OpportunityLineItemIdwithOpportunityLineItemScheduleField = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new)
    {
        OpportunityLineItemIdwithOpportunityLineItemScheduleField.put(sch.OpportunityLineItemId, sch.Quantity);
    }
 
    List<OpportunityLineItem> listUpdatedOpportunityLineItem = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c From OpportunityLineItem Where Id IN :OpportunityLineItemIdwithOpportunityLineItemScheduleField.Keyset()])
    {
        if(OpportunityLineItemIdwithOpportunityLineItemScheduleField.containsKey(oli.id))
        {
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, January__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
        }
    }
    update listUpdatedOpportunityLineItem;
}

 
Best Answer chosen by Nevin O'Regan 3
MKRMKR
Hi,

Try to use the following with type conversion (Integer.valueOf):
 
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> OpportunityLineItemIdwithOpportunityLineItemScheduleField = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         OpportunityLineItemIdwithOpportunityLineItemScheduleField.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> listUpdatedOpportunityLineItem = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c From OpportunityLineItem Where Id IN :OpportunityLineItemIdwithOpportunityLineItemScheduleField.Keyset()])
    {
        if(OpportunityLineItemIdwithOpportunityLineItemScheduleField.containsKey(oli.id))
        {
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, January__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
        }
    }
    update listUpdatedOpportunityLineItem;
}

Regards,
MKR​​​​​​​