• Nabeel Munir 9
  • NEWBIE
  • 35 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 4
    Replies
Hello all,

I want to know if it is possible to launch a process builder after a finish button is clicked in visual flow.

I have a flow that takes input from user and stores the values into variables in flow.
In account object, I have all fields read-only but, I want to be able to ignore those read-only restrictions. I know that process builder runs on system mode so, i thought it might be possible. But, I can not seem to find a solution. I want to update the address field in account object and I am trying to do it using flow. Since flow runs on user mode. It can not update the fields. So, How can I launch the process builder after the finish button is clicked in the flow and then assign the values user entered in the flow, to the address field in account object?

Thanks,
Kind regards.
Hello everyone,
I am trying to update the field in account object. The field is called, open_activities__c. The count of all open activities for the corresponding account should appear on the field. 
I am getting the right count of activities(Tasks,Events) But the corresponding account Id is not being stored in my map datastructure. I have variable from aggregate query called cnt, that stores the count of open tasks/events. and accId that gets the WhatId of those tasks and events and I am putting both variables into my map<Id,Double> 
Here is the log result.

Log result for cnt:
14:42:44:055 VARIABLE_ASSIGNMENT [6]|agg|{"cnt":9}|0x6729bfa8
Log result for accId:
14:42:44:055 VARIABLE_SCOPE_BEGIN [7]|accId|Id|false|false
14:42:44:055 VARIABLE_ASSIGNMENT [7]|accId|null
I can not figure out the reason for the accId to be null.
Here is the code and trigger:
public class ActivityCounter {

   public static void activityCount(Set<Id> accountIds) { 
  
   List<Account> acctToUpdate = new List<Account>();
    Integer taskcounts=0;
    System.debug('coming here atleast');
   Map<Id,Double> tasksByAccount = new Map<Id, Double>();
   for (AggregateResult agg : [Select WhatId , count(Id) cnt From Task Where WhatId IN :accountIds and IsClosed = false GROUP BY WhatId]) {
     Id accId = (Id) agg.get('WhatId');
     Double cnt = (Double) agg.get('cnt');
     taskcounts=cnt.intValue();
     System.debug('Tasks got: '+taskcounts);  
     tasksByAccount.put(accId, cnt);
   }
    System.debug('size of tasks by account: '+tasksByAccount.size());
   Map<Id, Double> eventsByAccount = new Map<Id, Double>();
   for(AggregateResult agg : [Select  WhatId , count(Id) cnt From Event Where WhatId IN :accountIds and  EndDateTime <= TODAY GROUP BY WhatId]) {
     Id accId = (Id) agg.get('WhatId');
     Double cnt = (Double) agg.get('cnt');
         
     eventsByAccount.put(accId, cnt);
   }
    System.debug('Reaches events'); 
   for(Id accountId : accountIds) {
     Double taskCount = tasksByAccount.containsKey(accountId) ? tasksByAccount.get(accountId) : 0;
     Double eventCount = eventsByAccount.containsKey(accountId) ? eventsByAccount.get(accountId) : 0;
     Account acc = new Account(Id = accountId, Open_Activities__c=(taskCount + eventCount) );
     System.debug('coming here');
     acctToUpdate.add(acc);    
   }    

   update acctToUpdate;

  }
}
Trigger:
trigger OpenActivityCountTrigger on Task (before insert,after update) {
Set<Id> acctIds = new Set<Id>();
String accPrefix = Account.SObjectType.getDescribe().getKeyPrefix();
  for (Task t : trigger.New) {
    //I Have to check this is an account and not something else
    if (string.valueof(t.WhatId).startsWith(Account.SObjectType.getDescribe().getKeyPrefix())) {
      acctIds.add(t.WhatId);
        System.debug('What is going on??');
    }
  }
    
  openActivityCounter.activityCount(acctIds);
    System.debug('Are you even executing after this?');
}
 
Hello,
I have 3 objects, team, plater, game. Loopk-up relationship between team and player and team and game. In both relationships, team is parent. What i want now is, I want to display all players names that are related to that team into the game object. I do not have any relation ship between game and player. Basically what i want is, for example, i have chosen real madrid as a team in game object using lookup relationship, and there are players that are related to real madrid, I want all those players to be displayed in game object. How is this possible using only UI without apex of VF. Since i am practicing UI only, It would be better if i have been told a way to do this only UI if possible.
Thanks
How does apex makes callouts to external system? how do i know that the enpoint that is specified in apex class is accessible?
Hello,
I am trying to prevent trigger from creating duplicate requests.
For example, if the case status is changed from something else to close, then create a new request. but, if the case status is not changed from something else to closed but it was already closed and edit button was clicked and without doing any changes, it was saved, in this case it should not create a new request.

I have trigger and handler class all set up for this but, i don't know why old values are being passed in both of my maps in handler class even though inside the trigger, it is fetching new and old values. still in my map inside handler class, it is passing old values where status is New.
I checked the log.

Below is what i have tried
public class MaintenanceRequestHelper {
 
    public static Boolean isFirstTime = true;

public static void updateWorkOrders(Map<Id,Case> newVal, Map<Id,Case> oldVal) {
    Map<Id,Case> maintenance_Req_List =new Map<Id,Case>([SELECT id,Origin,Status,Date_Due__c,priority, Case.vehicle__c,Equipment__c,Equipment__r.Maintenance_Cycle__c,
                                         Type,Subject,Date_Reported__c FROM Case Where Status in:newVal.KeySet()]);
  Map<Id,Case> maintenance_Req_Listt =new Map<Id,Case>([SELECT id,Origin,Status,Date_Due__c,priority, Case.vehicle__c,Equipment__c,Equipment__r.Maintenance_Cycle__c,
                                         Type,Subject,Date_Reported__c FROM Case Where id in:oldVal.KeySet()]);
        closedMaintenanceRequestList(maintenance_Req_List,maintenance_Req_Listt);
 }
        public static void closedMaintenanceRequestList(Map<Id, Case> newMap,  Map<Id, Case> oldMap)
         {
            List<Case> new_Maintenance_Req_Lst = new List<Case>();
            for (Case c: newMap.Values()) {
                if(c.Type=='Repair'||c.Type=='Routine Maintenance'){
                     System.debug('routine if is true');
                 if (c.Status == 'Closed' && oldMap.get(c.Id).Status != 'Closed' ) {
                System.debug('if executed after being true');
                  
                  Case new_req = new Case();
                  new_req.Subject='Maintenance request';
                  new_req.Type='Routine Maintenance';
                  new_req.Vehicle__c=c.Vehicle__c;
                  new_req.Equipment__c=c.Equipment__c;
                  new_req.Date_Reported__c=Date.today();
                  new_req.Date_Due__c=Date.today().addDays(Integer.valueOf(c.Equipment__r.Maintenance_Cycle__c));
                  new_req.Status='New';
                  new_req.Origin='Phone';
                  new_Maintenance_Req_Lst.add(new_req);
                
            }
        }
            }
        if(new_Maintenance_Req_Lst.size()>0)
        {
         insert new_Maintenance_Req_Lst;
        }
      }
    
    }
and trigger

trigger MaintenanceRequest on Case (before update,after update) {
    
    
        if(MaintenanceRequestHelper.isFirstTime)
        {
            MaintenanceRequestHelper.isFirstTime=false;
            System.debug('Trigegr fired');
            MaintenanceRequestHelper.updateWorkOrders(Trigger.newMap, Trigger.oldMap);          
        }
    
}
Here are the values from log.
For new values:
SSIGNMENT [5]|newVal|{"5002o00002Br9G9AAJ":{"Origin":"Phone","Status":"Closed","LastModifiedDate":"2019-08-05T12:29:24.000Z","IsDeleted":false,"Date_Due__c":"2019-08-09T00:00:00.000Z","Priority":"Medium","Equipment__c":"01t2o000007zDQfAAM","IsClosed":false,"SystemModstamp":"2019-08-05T12:29:24.000Z","BusinessHoursId":"01m2o000000U4OdAA

For old values:
IGNMENT [5]|oldVal|{"5002o00002Br9G9AAJ":{"Origin":"Phone","Status":"New","LastModifiedDate":"2019-08-05T12:29:24.000Z","IsDeleted":false,"Date_Due__c":"2019-08-09T00:00:00.000Z","Priority":"Medium","Equipment__c":"01t2o000007zDQfAAM","IsClosed":false,"SystemModstamp":"2019-08-05T12:29:24.000Z","BusinessHoursId":"01m2o000000U4OdAAK&q

But in my map inside handler class. both values are where status is New. 

Please help. I am totally lost here.
Hello, I have a situation where I need to check if a field is already updated or not before firing a trigger.
Meaning,
I have just finished apex specialist super badge where everytime a case is updated to closed, a new maintenance request is made automatically. But, what if the status is already updated to closed and i go ahead edit it and save it without doing anything, in this case another maintenance request will be made which should not be made.
So, I should case.status field is already updated to closed or not. How can i achieve this in trigger. I want that trigger does not fire if the field is already updated.

Below is the trigger that i have tried but i m really not sure about it.

trigger MaintenanceRequest on Case (before update,after update) {
    // call MaintenanceRequestHelper.updateWorkOrders
    if(trigger.isBefore && trigger.isUpdate)
    {
        for(Case c: trigger.old)
        {
            if(c.Status!='Closed')
            {
              MaintenanceRequestHelper.updateWorkOrders();          
            }
        }
    }
      
}
Hello,
I am a newbie in salesforce and practicing apex triggers using the following scenerio.
Pre-Reqs:
Create a field on Account called “Only_Default_Contact”, checkbox, default off
Assignment:
When a new Account is created, create a new Contact that has the following data points:
First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.

So far I have only been able to create contacts related to account after insert. But, since I know that after insert, Account becomes read only. I needed a way to update the Only_Default_Contact__c field. 
Below is what I have tried but it does not seem to work. 

trigger createAccount on Account (after insert,before update)
{
   List<Contact> lst = new List<Contact>();
    Contact con = new Contact();
    if(trigger.isAfter && trigger.isInsert)
  {
   for(Account acc:trigger.new)
   {
     con.AccountId = acc.Id;
     con.FirstName = 'Info';
     con.LastName = 'Default';
     con.Email = 'info@websitedomain.tld';
     
     lst.add(con);    
   }
  }
   if(!lst.isEmpty())
   {
      insert lst;
   
   }
   
   
   if(trigger.isBefore && trigger.isUpdate)
   {
   List<Account> ls = [Select Only_Default_Contact__c from Account];
   for(Account a: trigger.new)
     {
      if(lst.size()==1)
        {
        a.Only_Default_Contact__c = TRUE;
        update a;
        }
        else
        {
          a.Only_Default_Contact__c = FALSE;
          update a;
        }
   }
   }
}
Hello,
I am trying to prevent trigger from creating duplicate requests.
For example, if the case status is changed from something else to close, then create a new request. but, if the case status is not changed from something else to closed but it was already closed and edit button was clicked and without doing any changes, it was saved, in this case it should not create a new request.

I have trigger and handler class all set up for this but, i don't know why old values are being passed in both of my maps in handler class even though inside the trigger, it is fetching new and old values. still in my map inside handler class, it is passing old values where status is New.
I checked the log.

Below is what i have tried
public class MaintenanceRequestHelper {
 
    public static Boolean isFirstTime = true;

public static void updateWorkOrders(Map<Id,Case> newVal, Map<Id,Case> oldVal) {
    Map<Id,Case> maintenance_Req_List =new Map<Id,Case>([SELECT id,Origin,Status,Date_Due__c,priority, Case.vehicle__c,Equipment__c,Equipment__r.Maintenance_Cycle__c,
                                         Type,Subject,Date_Reported__c FROM Case Where Status in:newVal.KeySet()]);
  Map<Id,Case> maintenance_Req_Listt =new Map<Id,Case>([SELECT id,Origin,Status,Date_Due__c,priority, Case.vehicle__c,Equipment__c,Equipment__r.Maintenance_Cycle__c,
                                         Type,Subject,Date_Reported__c FROM Case Where id in:oldVal.KeySet()]);
        closedMaintenanceRequestList(maintenance_Req_List,maintenance_Req_Listt);
 }
        public static void closedMaintenanceRequestList(Map<Id, Case> newMap,  Map<Id, Case> oldMap)
         {
            List<Case> new_Maintenance_Req_Lst = new List<Case>();
            for (Case c: newMap.Values()) {
                if(c.Type=='Repair'||c.Type=='Routine Maintenance'){
                     System.debug('routine if is true');
                 if (c.Status == 'Closed' && oldMap.get(c.Id).Status != 'Closed' ) {
                System.debug('if executed after being true');
                  
                  Case new_req = new Case();
                  new_req.Subject='Maintenance request';
                  new_req.Type='Routine Maintenance';
                  new_req.Vehicle__c=c.Vehicle__c;
                  new_req.Equipment__c=c.Equipment__c;
                  new_req.Date_Reported__c=Date.today();
                  new_req.Date_Due__c=Date.today().addDays(Integer.valueOf(c.Equipment__r.Maintenance_Cycle__c));
                  new_req.Status='New';
                  new_req.Origin='Phone';
                  new_Maintenance_Req_Lst.add(new_req);
                
            }
        }
            }
        if(new_Maintenance_Req_Lst.size()>0)
        {
         insert new_Maintenance_Req_Lst;
        }
      }
    
    }
and trigger

trigger MaintenanceRequest on Case (before update,after update) {
    
    
        if(MaintenanceRequestHelper.isFirstTime)
        {
            MaintenanceRequestHelper.isFirstTime=false;
            System.debug('Trigegr fired');
            MaintenanceRequestHelper.updateWorkOrders(Trigger.newMap, Trigger.oldMap);          
        }
    
}
Here are the values from log.
For new values:
SSIGNMENT [5]|newVal|{"5002o00002Br9G9AAJ":{"Origin":"Phone","Status":"Closed","LastModifiedDate":"2019-08-05T12:29:24.000Z","IsDeleted":false,"Date_Due__c":"2019-08-09T00:00:00.000Z","Priority":"Medium","Equipment__c":"01t2o000007zDQfAAM","IsClosed":false,"SystemModstamp":"2019-08-05T12:29:24.000Z","BusinessHoursId":"01m2o000000U4OdAA

For old values:
IGNMENT [5]|oldVal|{"5002o00002Br9G9AAJ":{"Origin":"Phone","Status":"New","LastModifiedDate":"2019-08-05T12:29:24.000Z","IsDeleted":false,"Date_Due__c":"2019-08-09T00:00:00.000Z","Priority":"Medium","Equipment__c":"01t2o000007zDQfAAM","IsClosed":false,"SystemModstamp":"2019-08-05T12:29:24.000Z","BusinessHoursId":"01m2o000000U4OdAAK&q

But in my map inside handler class. both values are where status is New. 

Please help. I am totally lost here.
Hello, I have a situation where I need to check if a field is already updated or not before firing a trigger.
Meaning,
I have just finished apex specialist super badge where everytime a case is updated to closed, a new maintenance request is made automatically. But, what if the status is already updated to closed and i go ahead edit it and save it without doing anything, in this case another maintenance request will be made which should not be made.
So, I should case.status field is already updated to closed or not. How can i achieve this in trigger. I want that trigger does not fire if the field is already updated.

Below is the trigger that i have tried but i m really not sure about it.

trigger MaintenanceRequest on Case (before update,after update) {
    // call MaintenanceRequestHelper.updateWorkOrders
    if(trigger.isBefore && trigger.isUpdate)
    {
        for(Case c: trigger.old)
        {
            if(c.Status!='Closed')
            {
              MaintenanceRequestHelper.updateWorkOrders();          
            }
        }
    }
      
}
Hello,
I am a newbie in salesforce and practicing apex triggers using the following scenerio.
Pre-Reqs:
Create a field on Account called “Only_Default_Contact”, checkbox, default off
Assignment:
When a new Account is created, create a new Contact that has the following data points:
First Name = “Info”
Last Name = “Default”
Email = “info@websitedomain.tld”
Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.

So far I have only been able to create contacts related to account after insert. But, since I know that after insert, Account becomes read only. I needed a way to update the Only_Default_Contact__c field. 
Below is what I have tried but it does not seem to work. 

trigger createAccount on Account (after insert,before update)
{
   List<Contact> lst = new List<Contact>();
    Contact con = new Contact();
    if(trigger.isAfter && trigger.isInsert)
  {
   for(Account acc:trigger.new)
   {
     con.AccountId = acc.Id;
     con.FirstName = 'Info';
     con.LastName = 'Default';
     con.Email = 'info@websitedomain.tld';
     
     lst.add(con);    
   }
  }
   if(!lst.isEmpty())
   {
      insert lst;
   
   }
   
   
   if(trigger.isBefore && trigger.isUpdate)
   {
   List<Account> ls = [Select Only_Default_Contact__c from Account];
   for(Account a: trigger.new)
     {
      if(lst.size()==1)
        {
        a.Only_Default_Contact__c = TRUE;
        update a;
        }
        else
        {
          a.Only_Default_Contact__c = FALSE;
          update a;
        }
   }
   }
}