• SKT
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 9
    Replies
I have a date/time field Due_Date__c which I am using as a default value in an email quick action body. The return type of this formula is Text.

Here is the Due_Date__c field output: 2022-03-24 16:00:00Z

Now, is there anyway that I can convert this field into 12 hour format in this way 2022-03-24 4:00 PM. Please suggest
  • March 28, 2022
  • Like
  • 0

When we send an outbound email from Salesforce lightning record page, a task gets created and will be captured in activity history of that particular record.

Now, when we send this email from Lead record, neither the email is getting captured under lead record nor the task record is getting created.

This functionality is working fine for all the objects except for leads.
Can anyone let me know any solution here?
Thanks!
  • February 28, 2022
  • Like
  • 0
I have a requirement to create a new email_capture__c record whenever a new task gets created.

Here is the logic I have:
trigger EmailTrigger on Task (after insert) {
    Email_Capture__c ec = new Email_Capture__c();
        for(Task t:trigger.new){
           for(Email_Capture__c e : [SELECT id, email__c from Email_Capture__c where email__c != null]){
               if(e.email__c != t.description.substringBefore('CC:').substringAfter('To:')){
                   
                   ec.email__c = t.description.substringBefore('CC:').substringAfter('To:');
                   
               }
        }
    }
    insert ec;
}

Now, whenever I send an email from a record and new task is getting created, instead of 1 email capture record, I am seeing multiple records getting created.

Can anyone let me know how to overcome this error.

Thanks!
  • February 23, 2022
  • Like
  • 0
I have a requirement to cut certain characters from string which is a long text field
The String is as follows:
 
To: Test1@test.com; Test2@test.com
CC: 
BCC: test3@test.com
Attachment: --none--

Subject: Test-123
Body:
Test
Now, from above string, I just need what is there in To: (which is line 1) and omit rest of the characters.

Can anyone let me know how to achieve this
Thanks!
 
  • February 23, 2022
  • Like
  • 0
I have an email service which creates a task when an inbound email comes to salesforce. I have created this on opportunity and the logic is as follows:
global class OppsEmailService implements Messaging.InboundEmailHandler 
{
    global Messaging.InboundEmailResult  handleInboundEmail(Messaging.inboundEmail email, 
                                                            Messaging.InboundEnvelope env)
    {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();            
        String myPlainText= '';
        myPlainText = email.plainTextBody;           
        Task[] newTask = new Task[0];
        try 
        {
            Opportunity opps = [SELECT Id, Name, Email__c FROM Opportunity WHERE Email__c = :email.fromAddress   LIMIT 1];
            newTask.add(new Task(Description =  myPlainText,
                                 Priority = 'Normal',
                                 Status = 'Inbound Email',
                                 Subject = email.subject,
                                 IsReminderSet = true,
                                 ActivityDate= System.Today(),
                                 WhatId =  opps.Id));
            insert newTask;    
            System.debug('New Task Object: ' + opps.name+opps.id);   
        }
        catch (QueryException e) {
            System.debug('Query Issue: ' + e);
        }
        System.debug(email);
        result.success = true;
        return result;
    }
}

The above code is working fine and i could able to see a task created for inbound emails on opportunities. But when the same email is configured on multiple records, the response is getting stored on other record but not on the record which was used to send outbound email.

Can anyone let me know how to attach the inbound response under its appropriate oppty record.

Thanks!
 
  • February 21, 2022
  • Like
  • 0
I have a requirement to display Accounts-->child Accounts-->Tasks-->Child Tasks in the JSON.

Here is my Apex code:
 
List<Account> accountRecordsList = new list<Account>(); 
List<Custom_Tasks__c> taskRecordsList = new list<Custom_Tasks__c>(); 

accountRecordsList = [SELECT Id,Name,parent_account__c, (SELECT Id, Name FROM Accounts1__r) FROM Account WHERE Id = '<some record id>'];
string strJSON = JSON.serialize(accountRecordsList); //Account and Child Accounts

 Set<Id> accountIds = new Set<Id>();
        for(Account pr : accountRecordsList){
            for(Account cpr : pr.Accounts1__r){
            if(cpr.id != null){
                accountIds.add(cpr.id);
            }
            }
        }
taskRecordsList = [SELECT id, name,account__c, (SELECT id, name,pse__Start_Date__c, pse__End_Date__c from Sub_Tasks1__r ) from Custom_Tasks__c where account__c in :accountIds];
string ptJSON = JSON.serialize(taskRecordsList); //Tasks and Child Tasks related to above obtained child accounts

From the above code,
  • in strJSON, I am getting Accounts and its child accounts data.
  • in ptJSON, I am getting Tasks and Child Tasks related to above Child accounts
Now, is there anyway, I can append ptJSON under its related child Accounts in strJSON. Can anyone please suggest solution on how to get this done.

Thanks! 
  • August 03, 2021
  • Like
  • 0
I have a requirement to fetch Parent, Child, and Grandchild and Store them as JSON in the same hierarchy.

Here is my logic:
 
public List<Parent_Project__c> ProjectRecordsList {get; set;}
    ProjectRecordsList = [SELECT Id, Name,Parent_Project__c, (SELECT Id, Name, (select name from Orders__r) FROM Child_Projects__r) FROM Parent_Project__c];
    string strJSON = JSON.serialize(ProjectRecordsList);

Now the issue here is that, when I run this query, I am getting the error as
SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.

I could able to fetch Parent Project and its child Project successfully whereas when I include Orders (Grandchild), I am seeing this error. I know that I can write queries 5 levels up if I start with Child but in this case, I need to fetch the records starting from Parent to Grandchild.

Can anyone please let me know how to add Orders of Child Projects in the JSON?
  • July 04, 2021
  • Like
  • 0
I have a requirement to display Account and its child Accounts using Gantt Chart. Here is my Logic:

Controller:
public with Sharing class Account_Gantt {
    public Account ParentRecord{get; set;}
    public Account ChildRecord{get; set;}
    public Account_Gantt() {
        ParentRecord = [SELECT Id, Name,start_date__c, end_date__c FROM Account  WHERE name = 'Test Parent Account'];
    }
    public Account_Gantt(Account_Gantt Controller){
         ChildRecord = [SELECT ID, Name, start_date__c, end_date__c from Account where parent_account__r.name = 'Test Parent Account'];
    }
}

VF Page:
<apex:page controller="Account_Gantt"  extensions="Account_Gantt" standardStylesheets="false" showHeader="false">
    <head>
       <apex:stylesheet value="{!URLFOR($Resource.Timeline, 'codebase/dhtmlxgantt.css')}"/>
    <apex:includeScript value="{!URLFOR($Resource.Timeline, 'codebase/dhtmlxgantt.js')}"/>
        <style type="text/css" media="screen">
            html, body { margin:0px; padding:0px; height:100%; overflow:hidden; }
        </style>
    </head>
    <body>
        <div id="gantt_here" style='width:100%; height:100%;'></div>
        <script type="text/javascript">
            let ganttDataArr = [];
            for(let newParntObj=1; newParntObj <=1; newParntObj++ ) {
                let ganttDataObj = {};
                ganttDataObj["id"] = newParntObj;
                ganttDataObj["text"] = "{!ParentRecord.Name}";
                ganttDataObj["start_date"] = new Date("{!ParentRecord.start_date__c}");
                ganttDataObj["duration"] = 18;
                //ganttDataObj["order"] = "10";
                ganttDataObj["progress"] = "0.6";
                ganttDataObj["open"] = true;
                ganttDataArr.push(ganttDataObj);
            }
        
            for(let newObj = ganttDataArr.length+1; newObj <= 15; ++newObj ) {
                let ganttDataObj = {};
                ganttDataObj["id"] = newObj;
                ganttDataObj["text"] = "{!ChildRecord.Name}";
                ganttDataObj["start_date"] = new Date("{!ParentRecord.start_date__c}");
                ganttDataObj["duration"] = newObj*2;
                ganttDataObj["order"] = '10';
                ganttDataObj["progress"] = newObj%2;
                ganttDataObj["parent"] = '1';
                ganttDataArr.push(ganttDataObj);
            }

            let tasks =  {
                data: ganttDataArr,
                links:[
                    { id:1, source:1, target:2, type:"1"},
                    { id:2, source:2, target:3, type:"0"},
                    { id:3, source:3, target:4, type:"0"},
                    { id:4, source:2, target:5, type:"2"},
                ]
            };
                    
            gantt.init("gantt_here");
            gantt.parse(tasks);
                    
        </script>        
    </body>
</apex:page>


Under the Parent Account, I have 15 child Accounts. The issue here is that I could able to see Parent Account Name in the chart but not Child Accounts. I am seeing only the blank values instead of proper account names. The screenshot is as follows:

Gantt


Can anyone please let me know how to display all the 15 child account names under the parent account in the chart?
  • July 01, 2021
  • Like
  • 0
I have a requirement to fetch Contact Region from Contact and update the same on User.

Here is my logic:
 
list<user> user = [SELECT name,Region__c from User where isactive = true];
  Set<string> str = new Set<string>();
        for(user u1 : user){
            str.add(u1.name);
        }

        List <Contact> Contact = [
 select id,Salesforce_User__c,Contact_Region__r.name  from contact where Contact_Region__c != null];
                                      
                                      
        Map<id, list<String>> usertcMap = new Map<id, list<String>> ();
        for (Contact Contacts : Contact) {
            if(!usertcMap.containsKey(Contacts.Salesforce_User__c))
                usertcMap.put(Contacts.Salesforce_User__c, new list<string>{Contacts.Contact_Region__r.name});
        else
            usertcMap.get(Contacts.Salesforce_User__c).add(Contacts.Contact_Region__r.name);
        }
        list<User> userupdates = new list<user>();
        for(User us : user){ 
            if(usertcMap.containsKey(us.id))
            {
                 
                list<string> allProsList =usertcMap.get(us.id);
                us.Region__c = allProsList;
                userupdates.add(us);
            }
        }

        if(!userupdates.IsEmpty())
            update userupdates;


now when i am trying to run the above logic, i am seeing this error:
Illegal assignment from List<String> to String

Can anyone please let me know how to overcome this error?
Thanks!
  • June 18, 2021
  • Like
  • 0
I have a requirement to get all the Project Ids of Resource under User Detail page.

Below is my Object Schema:
Parent: Project (Field: ProjectId)
Child: Timecard (Field: Project__c, Resource_Name__c)


Now, if the Resource Name under timecard matches with User Name, the Project Ids from that timecard should be stored on User detail page separated by a semicolon.
Below is my logic that I have achieved so far:
 
list<user> user = [SELECT  name from User where isactive = true]; 
list<string> str = new list<string>();
for(user u1 : user){
    str.add(u1.name);
}

List <Timecard__c> timecard = [
  SELECT ID,Project__c,resource_name__c  
  FROM Timecard__c 
  Where Resource_name__c = :str  and Project__c != null and Resource_Name__c != null];
            
    set<string> allProsset = new set<string>();
    for (Timecard__c timecards : timecard) {
      allProsset.add(timecards.Project__c);
    }
    list<string>allProsList = new list<string>(allProsset);
    list<User> userupdates = new list<user>();
    
    for(User us : user){
     
        us.Project_Ids__c = String.join(allProsList,';');
        userupdates.add(us);
        }
        
    update userupdates;

Now when i execute the above logic, Project Ids under User record is getting updated with some random Project IDs but not from the timecard where the User name is matching. Instead of pulling all the project Ids that the resource is working under, I am seeing some random project ids


Is there anyway that I can update user records with the exact project ids that matches resource name with user name in timecard under a project?


 
  • June 16, 2021
  • Like
  • 1
Below is my Object Schema:
  • Parent: User
  • Child: Contact
  • Grand-Child: Sponsor. Sponsor Holds a field called ProId. These as 16 digit Ids.
Now, my requirement is to get all the ProIds from the sponsor records populate on the User record as a multi-select picklist value. The field on User is named All_Pros__c
For eg: On User A, All_Pros__c field should hold values as 'id1';'id2';'id3'.

Can anyone please suggest any approach on ths regard.
  • June 09, 2021
  • Like
  • 0
I know this isnt possible, but is there anyway that we can use transformed lens to an Einstein Discovery Story.

We have some complex calculations that are built using formula in lens and we want the same in Einstein Discovery Story. Along with that we have also columns created for standard deviation which we want to use in our story.

Instead of uploading the calculated columns in csv and using them in Story, can anyone please let me know if there is any possibility lf using lens itself while building the story.
Thanks!
  • March 15, 2021
  • Like
  • 0
I have a requirement to get all the Project Ids of Resource under User Detail page.

Below is my Object Schema:
Parent: Project (Field: ProjectId)
Child: Timecard (Field: Project__c, Resource_Name__c)


Now, if the Resource Name under timecard matches with User Name, the Project Ids from that timecard should be stored on User detail page separated by a semicolon.
Below is my logic that I have achieved so far:
 
list<user> user = [SELECT  name from User where isactive = true]; 
list<string> str = new list<string>();
for(user u1 : user){
    str.add(u1.name);
}

List <Timecard__c> timecard = [
  SELECT ID,Project__c,resource_name__c  
  FROM Timecard__c 
  Where Resource_name__c = :str  and Project__c != null and Resource_Name__c != null];
            
    set<string> allProsset = new set<string>();
    for (Timecard__c timecards : timecard) {
      allProsset.add(timecards.Project__c);
    }
    list<string>allProsList = new list<string>(allProsset);
    list<User> userupdates = new list<user>();
    
    for(User us : user){
     
        us.Project_Ids__c = String.join(allProsList,';');
        userupdates.add(us);
        }
        
    update userupdates;

Now when i execute the above logic, Project Ids under User record is getting updated with some random Project IDs but not from the timecard where the User name is matching. Instead of pulling all the project Ids that the resource is working under, I am seeing some random project ids


Is there anyway that I can update user records with the exact project ids that matches resource name with user name in timecard under a project?


 
  • June 16, 2021
  • Like
  • 1
I have a date/time field Due_Date__c which I am using as a default value in an email quick action body. The return type of this formula is Text.

Here is the Due_Date__c field output: 2022-03-24 16:00:00Z

Now, is there anyway that I can convert this field into 12 hour format in this way 2022-03-24 4:00 PM. Please suggest
  • March 28, 2022
  • Like
  • 0
I have a requirement to create a new email_capture__c record whenever a new task gets created.

Here is the logic I have:
trigger EmailTrigger on Task (after insert) {
    Email_Capture__c ec = new Email_Capture__c();
        for(Task t:trigger.new){
           for(Email_Capture__c e : [SELECT id, email__c from Email_Capture__c where email__c != null]){
               if(e.email__c != t.description.substringBefore('CC:').substringAfter('To:')){
                   
                   ec.email__c = t.description.substringBefore('CC:').substringAfter('To:');
                   
               }
        }
    }
    insert ec;
}

Now, whenever I send an email from a record and new task is getting created, instead of 1 email capture record, I am seeing multiple records getting created.

Can anyone let me know how to overcome this error.

Thanks!
  • February 23, 2022
  • Like
  • 0
I have a requirement to display Accounts-->child Accounts-->Tasks-->Child Tasks in the JSON.

Here is my Apex code:
 
List<Account> accountRecordsList = new list<Account>(); 
List<Custom_Tasks__c> taskRecordsList = new list<Custom_Tasks__c>(); 

accountRecordsList = [SELECT Id,Name,parent_account__c, (SELECT Id, Name FROM Accounts1__r) FROM Account WHERE Id = '<some record id>'];
string strJSON = JSON.serialize(accountRecordsList); //Account and Child Accounts

 Set<Id> accountIds = new Set<Id>();
        for(Account pr : accountRecordsList){
            for(Account cpr : pr.Accounts1__r){
            if(cpr.id != null){
                accountIds.add(cpr.id);
            }
            }
        }
taskRecordsList = [SELECT id, name,account__c, (SELECT id, name,pse__Start_Date__c, pse__End_Date__c from Sub_Tasks1__r ) from Custom_Tasks__c where account__c in :accountIds];
string ptJSON = JSON.serialize(taskRecordsList); //Tasks and Child Tasks related to above obtained child accounts

From the above code,
  • in strJSON, I am getting Accounts and its child accounts data.
  • in ptJSON, I am getting Tasks and Child Tasks related to above Child accounts
Now, is there anyway, I can append ptJSON under its related child Accounts in strJSON. Can anyone please suggest solution on how to get this done.

Thanks! 
  • August 03, 2021
  • Like
  • 0
I have a requirement to fetch Parent, Child, and Grandchild and Store them as JSON in the same hierarchy.

Here is my logic:
 
public List<Parent_Project__c> ProjectRecordsList {get; set;}
    ProjectRecordsList = [SELECT Id, Name,Parent_Project__c, (SELECT Id, Name, (select name from Orders__r) FROM Child_Projects__r) FROM Parent_Project__c];
    string strJSON = JSON.serialize(ProjectRecordsList);

Now the issue here is that, when I run this query, I am getting the error as
SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.

I could able to fetch Parent Project and its child Project successfully whereas when I include Orders (Grandchild), I am seeing this error. I know that I can write queries 5 levels up if I start with Child but in this case, I need to fetch the records starting from Parent to Grandchild.

Can anyone please let me know how to add Orders of Child Projects in the JSON?
  • July 04, 2021
  • Like
  • 0
I have a requirement to get all the Project Ids of Resource under User Detail page.

Below is my Object Schema:
Parent: Project (Field: ProjectId)
Child: Timecard (Field: Project__c, Resource_Name__c)


Now, if the Resource Name under timecard matches with User Name, the Project Ids from that timecard should be stored on User detail page separated by a semicolon.
Below is my logic that I have achieved so far:
 
list<user> user = [SELECT  name from User where isactive = true]; 
list<string> str = new list<string>();
for(user u1 : user){
    str.add(u1.name);
}

List <Timecard__c> timecard = [
  SELECT ID,Project__c,resource_name__c  
  FROM Timecard__c 
  Where Resource_name__c = :str  and Project__c != null and Resource_Name__c != null];
            
    set<string> allProsset = new set<string>();
    for (Timecard__c timecards : timecard) {
      allProsset.add(timecards.Project__c);
    }
    list<string>allProsList = new list<string>(allProsset);
    list<User> userupdates = new list<user>();
    
    for(User us : user){
     
        us.Project_Ids__c = String.join(allProsList,';');
        userupdates.add(us);
        }
        
    update userupdates;

Now when i execute the above logic, Project Ids under User record is getting updated with some random Project IDs but not from the timecard where the User name is matching. Instead of pulling all the project Ids that the resource is working under, I am seeing some random project ids


Is there anyway that I can update user records with the exact project ids that matches resource name with user name in timecard under a project?


 
  • June 16, 2021
  • Like
  • 1