• damion me
  • NEWBIE
  • -14 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 14
    Replies
I have two custom objects, Booking and related Services. I want to implement an override for the standars New button of the Service object as a new Service record can only be created in the context of a Booking. So I created a Lightning component for that, which should open a new page saying 'please create a Service record from within a Booking, showing below a datatable of the most recent edited Booking records. 

<aura:component controller="BookingController" implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride" access="global">
    <ui:message title="Information" severity="warning" closable="false">
        Please create new Service records from a Booking record.
    </ui:message>
    
    <aura:attribute type="Booking__c[]" name="bookList"/>
    <aura:attribute name="mycolumns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.fetchBookings}"/>
    
    <lightning:datatable data="{! v.bookList }"
                         columns="{! v.mycolumns }"
                         keyField="id"
                         hideCheckboxColumn="true"/>          
</aura:component>

The component controller has following code:

({
    fetchBookings : function(component, event, helper) 
    {    
        helper.fetchBookingsHelper(component, event, helper);
    }
})

And the helper:

({
    fetchBookingsHelper : function(component, event, helper) 
    {
        component.set('v.mycolumns', [
            {label: 'Booking Number', fieldName: 'Name', type: 'text'},
            {label: 'Booking Reference', fieldName: 'Booking_Name__c', type: 'text'},
            {label: 'Arrival Date', fieldName: 'Arrival_Date__c', type: 'date'},
            {label: 'Departure Date', fieldName: 'Departure_Date__c', type: 'date '},
            {label: 'Agent', fieldName: 'Agent__c', type: 'text'}
           ]);

        var action = component.get("c.fetchBookings");
        
        action.setParams({});
        
        action.setCallback(this, 
            function(response)
            {
                var state = response.getState();
                
                if (state === "SUCCESS") 
                { 
                    component.set("v.bookList", response.getReturnValue());
                    alert("Success: " + response.getReturnValue());
                }
                else if (state === "INCOMPLETE")
                {
                    // do something
                }
                else if (state === "ERROR") 
                {
                    var errors = response.getError();
                    
                    if (errors) 
                    {
                        if (errors[0] && errors[0].message) 
                        {
                            alert("Error message: " + errors[0].message);
                        }
                    }
                } 
                else 
                {
                    alert("Unknown error");
                }
            }
        );
        
        $A.enqueueAction(action);
    }
})

To retrieve the data I wrote an Apex class:

public class BookingController {
    @AuraEnabled
    public static List <Booking__c> fetchBookings() {
        //Qyery 20 recent bookings
        List <Booking__c> bookList = 
            [SELECT Id, Name, Booking_Name__c, Arrival_Date__c, Departure_Date__c, Agent__c 
             FROM Booking__c
             ORDER BY LastModifiedDate DESC
             LIMIT 20];
        //return list of bookings
        return bookList;
    }
}

The BookingController() function works perfectly fine. The data is retrieved correctly. However, when clicking the New button within one of the Service record views, the Lightning components appears (without data) on the screen, followed by an infinite loop of Success message.

I can't get my head around why the callback function that should receive a result set is not receiving any result and on top of that is being called in an endless loop.

Any idea?
 
Hi,

Use Case- Want to get the salesforce 1 mobile User location in background after every 10 mins. How can we develop it please assist.

thanks in advance.
Can we use custom quick action(Lightning components ) in swipe action bar of object records? If so then I am stuck because I am not able to add it in swipe action bar in salesforce1 app, have not found any articles reg this also, please help
Hi All,
I need to create a single connected app for both android and ios. How we can do this?
Thanks. 
  • August 05, 2019
  • Like
  • 0
Ans:  Text, Text Area, Text Area Long, Rich Text Area, URL. Is this is the right answer or is there something else????

13. Can we change the data type from Text to Auto Number for the Name when we already have?

Ans: I feel the answer is yes. If yes, please do let me know the explanation . If no, let me know the reason as well. Thanks guys. 

 
OK, I'm confused. I've deactivated this trigger and want to comment it out in the sandbox. Why am I getting:
Error: Compile Error: unexpected token: <EOF> at line 9 column 0
/*
trigger AuditTrigger on Audit__c (after insert, after update) {

//trigger deprecated by Process builder chatter feed .
    if (trigger.isAfter && (trigger.isInsert || trigger.isUpdate)) {
        ReportStatusChatterPost.postToChatter(trigger.newMap.keySet(), trigger.isInsert);
    }
}
*/
If I do this , no error. But I really don't want this.
 
trigger AuditTrigger on Audit__c (after insert, after update) {
/*
//trigger deprecated by Process builder chatter feed .
    if (trigger.isAfter && (trigger.isInsert || trigger.isUpdate)) {
        ReportStatusChatterPost.postToChatter(trigger.newMap.keySet(), trigger.isInsert);
    }
*/     
}


 
Hi Developers,

Can anyone help me on this issue, I have a Child object that has a Lookup to Parent. I wrote the below apex class and the trigger on child, such that the count of Child records should be shown on each Parent record. I have a number field on the Parent which should be update as per the Trigger.

It works fine except in one scenario, it does not consider the existing Child records on the Parent, hence it shows incorrect count on the Parent record. It works perfect if I add the new Child records. I heard that Batch Apex can resolve this issue, I am not sure how Batch Apex is related here to resolve the isssue. Can I get some guidance here to proceed further.


Any help on this is much appreciated.
Thank you.

Apex Class:

public class ChildCountHelper{
    
    //List<Parent__c> parentList = [select id, child_count__c, (select id from child__r) from Parent__c where id in :parentIDSet];
    
    public List<ID> conList= new List<ID>();
    
    public static void handleBeforeInsert(List<Child__c> childList){
        Set<ID> parentIDSet = new Set<ID>();
        
        for(Child__c childRec: childList){
     
            parentIDSet.add(childRec.Parent__c);
            
        }
        
        Map<ID, Parent__c> parentMap = new map<ID, parent__c>([select id, child_count__c from Parent__c where id in :parentIDSet]);
        for(Child__c childRec: childList){
            if(parentMap.get(childRec.Parent__c).child_count__c == null){
                parentMap.get(childRec.Parent__c).child_count__c = 0;
            }
            parentMap.get(childRec.Parent__c).child_count__c ++;
        }
        update parentMap.values();
    }
    
    public static void handleBeforeUpdate(List<Child__c> newChildList, List<Child__c> oldChildList){
        Set<ID> parentIDSet = new Set<ID>();
        Map<ID, ID> oldChildMap = new Map<ID, ID>();
        
        for(Child__c childRec: newChildList){
            parentIDSet.add(childRec.Parent__c);
        }
        
        for(Child__c childRec: oldChildList){
            parentIDSet.add(childRec.Parent__c);
            oldChildMap.put(childRec.Id, childRec.Parent__c);
        }
        
        Map<ID, Parent__c> parentMap = new map<ID, parent__c>([select id, child_count__c from Parent__c where id in :parentIDSet]);
        for(Child__c childRec: newChildList)
       {
        /*if(ChildRec.Parent__c!=null){  */
            if(parentMap.get(childRec.Parent__c).child_count__c == null){
                parentMap.get(childRec.Parent__c).child_count__c = 0;
            }
           // }
            if(childRec.Parent__c != oldChildMap.get(childRec.id)){
                if(oldChildMap.get(childRec.id) == null && childRec.Parent__c != null){
                    parentMap.get(childRec.Parent__c).child_count__c ++;
                }else if(oldChildMap.get(childRec.id) != null && childRec.Parent__c == null){
                    parentMap.get(oldChildMap.get(childRec.id)).child_count__c --;
                }else if(oldChildMap.get(childRec.id) != null && childRec.Parent__c != null){
                    parentMap.get(oldChildMap.get(childRec.id)).child_count__c --;
                    parentMap.get(childRec.Parent__c).child_count__c ++;
                }
            }
            
        }
        update parentMap.values();
    }
    
    public static void handleBeforeDelete(List<Child__c> childList){
        Set<ID> parentIDSet = new Set<ID>();
        for(Child__c childRec: childList){
            parentIDSet.add(childRec.Parent__c);
        }
        
        Map<ID, Parent__c> parentMap = new map<ID, parent__c>([select id, child_count__c from Parent__c where id in :parentIDSet]);
        for(Child__c childRec: childList){
            if(parentMap.get(childRec.Parent__c).child_count__c == null){
                parentMap.get(childRec.Parent__c).child_count__c = 0;
            }
            parentMap.get(childRec.Parent__c).child_count__c --;
        }
        update parentMap.values();
    }
    
    public static void handleBeforeUnDelete(List<Child__c> childList){
        Set<ID> parentIDSet = new Set<ID>();
        for(Child__c childRec: childList){
            parentIDSet.add(childRec.Parent__c);
        }
        
        Map<ID, Parent__c> parentMap = new map<ID, parent__c>([select id, child_count__c from Parent__c where id in :parentIDSet]);
        for(Child__c childRec: childList){
            if(parentMap.get(childRec.Parent__c).child_count__c == null){
                parentMap.get(childRec.Parent__c).child_count__c = 0;
            }
            parentMap.get(childRec.Parent__c).child_count__c ++;
        }
        update parentMap.values();
    }

}




Trigger:


trigger ChildTrigger on Child__c (before insert, after update, after delete, after undelete) {
    if (Trigger.isInsert) {
        ChildCountHelper.handleBeforeInsert((List<Child__c>)Trigger.NEW);
    }else if (Trigger.isUpdate) {
        ChildCountHelper.handleBeforeUpdate((List<Child__c>)Trigger.NEW, (List<Child__c>)Trigger.OLD);
    }else if (Trigger.isDelete) {
        ChildCountHelper.handleBeforeDelete((List<Child__c>)Trigger.OLD);
    }else if (Trigger.isUndelete) {
        ChildCountHelper.handleBeforeUnDelete((List<Child__c>)Trigger.NEW);
    }
}  
Hello,

How is it possible to get the developer name for a record type
  • September 30, 2015
  • Like
  • 1
hi gyus... This code is working fine..when ever I insert or update record it sends email.. but I am quite confused  so plz explain me the use of line 16,line 19,line 25 & what is the use of flag... and tell me that is messaging.singleEmailMessage is defined keyword...??
Last but not the least I want to edit the code in such a way that if i insert the data with dataloader where there is more than one contact then send email to more than one contact is inserted at a time....

************apex class**********
public with sharing class HelperContactTrigger {
    public static List<Contact> sendEmail(List<Contact>Contacts)
    {
     //query on template object
        EmailTemplate et=[Select id from EmailTemplate where name=:'Sales: New Customer Email'];

        //list of emails
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();   
        
        for(Contact con : Contacts)
        {
          //check for Account
            if(con.AccountId != null && con.Email != null){

                //initiallize messaging method
                Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();

                //set object Id
                singleMail.setTargetObjectId(con.Id);

                //set template Id
                singleMail.setTemplateId(et.Id);

                //flag to false to stop inserting activity history
                singleMail.setSaveAsActivity(false);

                //add mail
                emails.add(singleMail);
            }
        }
            //send mail
        Messaging.sendEmail(emails);

        return Contacts;          
        
    }

    public static List<Contact> sendEmailafter(List<Contact>Contacts)
    {
    //query on template object
        EmailTemplate et=[Select id from EmailTemplate where name=:'Sales: New Customer Email'];

        //list of emails
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();   
        
        for(Contact con : Contacts)
        {
          //check for Account
            if(con.AccountId != null && con.Email != null){

                //initiallize messaging method
                Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();

                //set object Id
                singleMail.setTargetObjectId(con.Id);

                //set template Id
                singleMail.setTemplateId(et.Id);

                //flag to false to stop inserting activity history
                singleMail.setSaveAsActivity(false);

                //add mail
                emails.add(singleMail);
            }
         }
            //send mail
        Messaging.sendEmail(emails);

        return Contacts;          
        }
    }

*********Apex trigger********
trigger SendEmailToAccount on Contact (after insert,after update) 
{
    if(Trigger.isAfter)
    {
        if(Trigger.isInsert )
        { 
            //helper class for single email but bulk messages
            HelperContactTrigger.sendEmail(trigger.new);
        }
    }
        if(trigger.isAfter && trigger.isUpdate )
        {           
         HelperContactTrigger.sendEmailafter(trigger.new);
        }
}

 
I have tried

// comment
/* comment */
<!-- comment -->

Any other ideas what the syntax might be? Or is it not possible at all?
Hi,

Sorry for the RTFM type question but, believe it or not, I'm having a bit of trouble finding the answer...

What is the syntax for Visualforce server side comments?

Thanks,
Mike