• Sumanta Satpathy
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
/*Create “Sales Rep”(Sales_Rep__c) field with data type (Text) on the Account Object. 
When we create the Account record, the Account Owner will be automatically added to Sales Rep field.
When we update the Account owner of the record, then also the Sales Rep will be automatically updated.
*/
trigger Update_SalesRep on Account (before insert,before update) {
    Set<id> accountOwnerId= new Set<ID>();
    for(Account a: trigger.new){
        accountOwnerId.add(a.OwnerId);
    }
    Map<Id,User> userMap= new Map<Id,User>();
    
    List<User>userList=[Select id,name from User where id IN:accountOwnerId];
    for(User u:userList){
        userMap.put(u.Id,u);
    }
    for(Account ac: trigger.new){
        user u=userMap.get(ac.Id);
        ac.Sales_Rep__c=u.Name;
    }
    

}

 
A requirement for trigger:
I just want to write one after update trigger.
The scenario is as follows:
Employee_c and Employer_c two custom objects are there.
Employee__c is the child object and Employer_c is the parent object.
Lookup relationship is present in between the objects.
The lookup field is employer name.
When salary is getting updated in the salary_c field of the Employee_c object at that time
Total cost_c field present in the Employer_c object needs to be updated.
Object details:
Child Object:
Object name: Employee__c
Fields: Name
Salary__c
Employeer_Name(lookup to Employer__c)
Parent Object: when Salary__c getting updated
Object Name:Employer__c
Fields: Name
Total_Cost__c
Total_cost__c should be updated
Any suggestion is appretiated.

Thanks in advance
Hi there,

I'm getting the following message: We can’t display component 'flowruntime:lookup', because it isn't supported in Classic runtime. Ask your Salesforce admin to distribute this flow in Lightning runtime instead. but I have already enable the setting in process automation settings so I'm not sure what else I'm missing. Any help would be greatly appreciated.
A requirement for trigger:
I just want to write one after update trigger.
The scenario is as follows:
Employee_c and Employer_c two custom objects are there.
Employee__c is the child object and Employer_c is the parent object.
Lookup relationship is present in between the objects.
The lookup field is employer name.
When salary is getting updated in the salary_c field of the Employee_c object at that time
Total cost_c field present in the Employer_c object needs to be updated.
Object details:
Child Object:
Object name: Employee__c
Fields: Name
Salary__c
Employeer_Name(lookup to Employer__c)
Parent Object: when Salary__c getting updated
Object Name:Employer__c
Fields: Name
Total_Cost__c
Total_cost__c should be updated
Any suggestion is appretiated.

Thanks in advance
So the structure I have is this:

Record of Custom Object Type A has a related list of multiple records of Custom Object Type B.


And this is what I'm looking to do:

Object Type B has a Currency field, and Object Type A has a field that is inteded to be the Sum of that Currency field for all records in the related list. Whenever any record of Object Type B is updated, I need the Sum field on Object Type A to calculate the new sum. (Essentially it is a rollup sum, but I cannot use a rollup field because these do not have a Master-Detail relationship.)


Example:

Initial State:
  • Object Type A Record SumField = 100
    • Related ObjectB Record 1 CurrencyField = 50
    • Related ObjectB Record 2 CurrencyField = 30
    • Related ObjectB Record 3 CurrencyField = 20
User Action:
  • Related ObjectB Record 2 CurrencyField is changed from 30 to 80
Desired End State:
  • Object Type A Record SumField = 150
    • Related ObjectB Record 1 CurrencyField = 50
    • Related ObjectB Record 2 CurrencyField = 80
    • Related ObjectB Record 3 CurrencyField = 20
Is it possible to run Apex code under a different user than the logged in one?

So someone has logged in and they kick off some Apex code, but I need that specific method to run under an admin user? Is that possible?

Thanks.
I'm trying to create a trigger that will update a custom Account field called "In Touch Date" based on the Activity History of the account. I want the "In Touch Date" to always be the most recent date any contact in that account has been in touch. I was able to sucessfully create this trigger on a Contact level so that a Contact field also called "In Touch Date" will update based on the most recent Activity Date (code seen below). I am trying to figure out the easiest way to replicate this trigger on an Account level.

The working trigger on the Contact level is here: 
trigger UpdateInTouchDate on Task (after insert, after update) {
	Set<String> whoIds = new Set<String>();
	
    for (Task t : Trigger.new) {
  		whoIds.add(t.WhoId);
	}
	
   	List<Contact> cons = [SELECT Id, In_Touch_Date__c FROM Contact WHERE Id =: whoIds];
    
   	Map<String, Task> taskMap = new Map<String, Task>();
	
    for (Task t : Trigger.new){
    	if (!(t.Type.equals('Eloqua Activity'))) {
    		if (t.Status.equals('Completed')) {
    			taskMap.put(t.WhoId, t);
    		}
    	}
  		
	}
         
    for (Contact c : cons) {
  		if (taskMap.containsKey(c.Id)) {
    		c.In_Touch_Date__c = taskMap.get(c.Id).ActivityDate;
    		c.POC_Communications__c = 'Muted';
  		}
	}
	update cons;

}

Any suggestions on how to replicate this on an Account level would be much appreciated.
  • July 22, 2014
  • Like
  • 0