• Mokshada
  • NEWBIE
  • 70 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 38
    Questions
  • 31
    Replies
Hi, 
I have a question , I have one batch class in salesforce  which creates prospects after batch run I want to know like whenever new prospect got created after any batch run will prospect owner get any mail? 
like when we change manually we will get option to select email notification so I want know after creation of mail did prospect owner  gets mail or not?

can anyone help in this?

Thanks in advance!
Hi , I am new to flow can anyone help is doing this flow :
flow for whenever Account is created description should be added as "updated via Flow".



Thanks,
Hi, I was trying to implement Bmi calculator using aura component but it is not working when i click on button it is showing zero after adding alerts in js i got to know that I am getting value as 0 of height and weight, how to make this code work can anyone help?
apex:
public class BMICalculatorController {
    @AuraEnabled
    public static Decimal calculateBMI(Decimal height, Decimal weight) {
        Decimal heightInMeters = height / 100;
        Decimal bmi = weight / (heightInMeters * heightInMeters);
        System.debug(bmi);
        return bmi;
    }
}

component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" controller="BMICalculatorController">
    <aura:attribute name="height" type="Decimal" default="0"/>
    <aura:attribute name="weight" type="Decimal" default="0"/>
    <aura:attribute name="bmiResult" type="Decimal" default="0"/>
    
    <div>
        <label>Height (in CM):</label>
        <input type="number" aura:id="heightInput" value="{!v.height}"/>
    </div>
    <div>
        <label>Weight (in KG):</label>
        <input type="number" aura:id="weightInput" value="{!v.weight}"/>
    </div>
    <div>
        <button onclick="{!c.calculateBMI}">Calculate BMI</button>
    </div>
    <div>
        <h2>BMI Result: {!v.bmiResult}</h2>
    </div>
</aura:component>

Controller:
({
    calculateBMI: function(component, event, helper) {
        var height = component.get("v.height");
        var weight = component.get("v.weight");
        alert(component.get("v.height"));
        alert(component.get("v.weight"));
        //if (height > 0 && weight > 0) {
            var action = component.get("c.calculateBMI");
            action.setParams({
                height: height,
                weight: weight
            });
            
            action.setCallback(this, function(response) {
                var state = response.getState();
                //alert(response.getState())
                alert(state)
                if (state === "SUCCESS") {
                    var bmiResult = response.getReturnValue();
                    
                    component.set("v.bmiResult", bmiResult);
                } else {
                    alert("Error");
                }
            });
            
            $A.enqueueAction(action);
        
    }
})


Thanks,
 
I have a apex Trigger on contact if we have contact related account the number of opportunities will be updated in amount like amount = no.of contacts*1000 
trigger trigoncontact on Contact (after insert, after delete) {
    List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
    
    Set<Id> accountIds = new Set<Id>();
    
    if (Trigger.isInsert) {
        for (Contact contact : Trigger.new) {
            accountIds.add(contact.AccountId);
        }
    }
    
    if (Trigger.isDelete) {
        for (Contact contact : Trigger.old) {
            accountIds.add(contact.AccountId);
        }
    }
    
    List<Account> accounts = [SELECT Id, (SELECT Id, Amount FROM Opportunities), (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds];
    
    for (Account acc : accounts) {
        List<Contact> contacts = acc.Contacts;
        List<Opportunity> opportunities = acc.Opportunities;
        
        for (Opportunity opportunity : opportunities) {
            opportunity.Amount = contacts.size() * 1000;
            opportunitiesToUpdate.add(opportunity);
        }
    }
    
    update opportunitiesToUpdate;
}

now I want to create salesforce flow for whenever a new opportunity is created at that time also amount should be updated on opportunity. can anyone help how to do that ?


Thanks,
Hi I have written two triggers on teacher and student like whenever teacher is inserted student should be inserted or vice versa and same for updation and deletion also. but while saving a record I am getting error as :-
TeacherTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, StudentTrigger: maximum trigger depth exceeded Teacher trigger event AfterInsert Student trigger event AfterInsert Teacher trigger event AfterInsert Student trigger event AfterInsert Teacher trigger event AfterInsert Student trigger event AfterInsert Teacher trigger event AfterInsert Student trigger event
can anyone hep in resolving this can we do like in both the cases afterinsert and after update check with the help of id if trigger is running on teacher then we need to check that if student is not present with that teacher id then only it will create student record.how to do this? can anyone help
code:
trigger StudentTrigger on Student__c (after insert, after update, before delete) {
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
                List<Teacher__c> teachersToInsert = new List<Teacher__c>();
                
                for (Student__c student : Trigger.new) {
                    Teacher__c teacher = new Teacher__c();
                    teacher.Name = student.Name;
                    teacher.Email__c = student.Email__c;
                    teacher.Mobile__c = student.Mobile__c;
                    teacher.Address__c = student.Address__c;
                    teacher.teacherid__c = student.Id;
                    teachersToInsert.add(teacher);
                }
                
                if (!teachersToInsert.isEmpty()) {
                    insert teachersToInsert;
                }
            }
        
        if (Trigger.isUpdate) {
            List<Teacher__c> teachersToUpdate = new List<Teacher__c>();
            Set<Id> studentIds = new Set<Id>();
            
            for (Student__c student : Trigger.new) {
                studentIds.add(student.Id);
            }
            
            List<Teacher__c> existingTeachers = [SELECT Id, Name, Email__c, Mobile__c, Address__c, teacherid__c FROM Teacher__c WHERE teacherid__c IN :studentIds];
            Map<Id, Teacher__c> teacherMap = new Map<Id, Teacher__c>();
            
            for (Teacher__c teacher : existingTeachers) {
                teacherMap.put(teacher.teacherid__c, teacher);
            }
            for (Student__c student : Trigger.new) {
                if (teacherMap.containsKey(student.Id)) {
                    Teacher__c teacher = teacherMap.get(student.Id);
                    teacher.Name = student.Name;
                    teacher.Email__c = student.Email__c;
                    teacher.Mobile__c = student.Mobile__c;
                    teacher.Address__c = student.Address__c;
                    teachersToUpdate.add(teacher);
                }
            }
            if (!teachersToUpdate.isEmpty()) {
                update teachersToUpdate;
            }
        }
    }
    
    if (Trigger.isBefore) {
        if (Trigger.isDelete) {
            List<String> studentIds = new List<String>();
            for (Student__c student : Trigger.old) {
                studentIds.add(student.Id);
            }
            List<Teacher__c> listOfTeachers = [SELECT Id, teacherid__c FROM Teacher__c WHERE teacherid__c IN :studentIds];
            System.debug('listOfTeachers: ' + listOfTeachers);
            if (!listOfTeachers.isEmpty()) {
                delete listOfTeachers;
            }
        }
    }
}
trigger TeacherTrigger on Teacher__c (after insert, after update, before delete) {
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
                List<Student__c> studentsToInsert = new List<Student__c>();
                for (Teacher__c teacher : Trigger.new) {
                    Student__c student = new Student__c();
                    student.Name = teacher.Name;
                    student.Email__c = teacher.Email__c;
                    student.Mobile__c = teacher.Mobile__c;
                    student.Address__c = teacher.Address__c;
                    student.id__c = teacher.Id;
                    studentsToInsert.add(student);
                }
                if (!studentsToInsert.isEmpty()) {
                    insert studentsToInsert;
                }
            }
        }
        
        if (Trigger.isUpdate) {
            List<Student__c> studentsToUpdate = new List<Student__c>();
            Set<Id> teacherIds = new Set<Id>();
            for (Teacher__c teacher : Trigger.new) {
                teacherIds.add(teacher.Id);
            }
            List<Student__c> existingStudents = [SELECT Id, Name, Email__c, Mobile__c, Address__c, id__c FROM Student__c WHERE id__c IN :teacherIds];
            Map<Id, Student__c> studentMap = new Map<Id, Student__c>();
            for (Student__c student : existingStudents) {
                studentMap.put(student.id__c, student);
            }
            for (Teacher__c teacher : Trigger.new) {
                    if (studentMap.containsKey(teacher.Id)) {
                        Student__c student = studentMap.get(teacher.Id);
                        student.Name = teacher.Name;
                        student.Email__c = teacher.Email__c;
                        student.Mobile__c = teacher.Mobile__c;
                        student.Address__c = teacher.Address__c;
                        studentsToUpdate.add(student);
                    }
                }
            }
            if (!studentsToUpdate.isEmpty()) {
                update studentsToUpdate;
            }
        }
    }
    
    if (Trigger.isBefore) {
        if (Trigger.isDelete) {
            List<String> teacherIds = new List<String>();
            
            for (Teacher__c teacher : Trigger.old) {
                teacherIds.add(teacher.Id);
            }
            List<Student__c> listOfStudents = [SELECT Id, id__c FROM Student__c WHERE id__c IN :teacherIds];
            System.debug('Number of students found: ' + listOfStudents.size());
            System.debug('listOfStudents' + listOfStudents);
            if (!listOfStudents.isEmpty()) {
                delete listOfStudents;
            }
        }
    }
}
Thanks,
I have Created two Objects say Teacher__c(Parent) and Student__c(Child) having similar fields such as name, email, mobile and Address. and they have two unique fields on both objects such as teacherid__c on teacher object and id__c on student object On deleting record of Teacher__c, associated Student__c record should be deleted and vice versa.
here in my code insertion and updation is working but deletion is not working can anyone help me doing that
code:
trigger TeacherTrigger on Teacher__c (after insert, after update, before delete) {
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
            List<Student__c> studentsToInsert = new List<Student__c>();
            for (Teacher__c teacher : Trigger.new) {
                if(triggerCount.runonce()){
                    Student__c student = new Student__c();
                    student.Name = teacher.Name;
                    student.Email__c = teacher.Email__c;
                    student.Mobile__c = teacher.Mobile__c;
                    student.Address__c = teacher.Address__c;
                    student.id__c = teacher.Id;
                    studentsToInsert.add(student);
                }
            }
            if (!studentsToInsert.isEmpty()) {
                insert studentsToInsert;
            }
        }
        if (Trigger.isUpdate) {
            List<Student__c> studentsToUpdate = new List<Student__c>();
            for (Teacher__c teacher : Trigger.new) {
                if(triggerCount.runonce()){
                    List<Student__c> existingStudents = [SELECT Id, Name, Email__c, Mobile__c, Address__c, id__c FROM Student__c WHERE id__c = :teacher.Id LIMIT 1];
                    if (!existingStudents.isEmpty()) {
                        Student__c student = existingStudents[0];
                        student.Name = teacher.Name;
                        student.Email__c = teacher.Email__c;
                        student.Mobile__c = teacher.Mobile__c;
                        student.Address__c = teacher.Address__c;
                        studentsToUpdate.add(student);
                    }
                }
            }
            if (!studentsToUpdate.isEmpty()) {
                update studentsToUpdate;
            }
        }
        if (Trigger.isDelete) {
            list<String> teacherIds=new list<String>();
            for(Teacher__c teacher:trigger.old)
            {
                teacherIds.add(teacher.id);
            }
            list<Student__c> listOfStudents=[select id,id__c from Student__c where id__c in:teacherIds];
            System.debug('Number of students found: ' + listOfStudents.size());
            system.debug('listOfstudents'+listOfStudents);
            if (!listOfStudents.isEmpty()) {
                delete listOfStudents;
            }
        }
    }
}


trigger StudentTrigger on Student__c (after insert, after update, before delete) {
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
            List<Teacher__c> teachersToInsert = new List<Teacher__c>();
            
            for (Student__c student : Trigger.new) {
                if(triggerCount.runonce()){
                    Teacher__c teacher = new Teacher__c();
                    teacher.Name = student.Name;
                    teacher.Email__c = student.Email__c;
                    teacher.Mobile__c = student.Mobile__c;
                    teacher.Address__c = student.Address__c;
                    teacher.teacherid__c = student.Id;
                    teachersToInsert.add(teacher);
                }
            }
            
            if (!teachersToInsert.isEmpty()) {
                insert teachersToInsert;
            }
        }
        
        if (Trigger.isUpdate) {
            List<Teacher__c> teachersToUpdate = new List<Teacher__c>();
            for (Student__c student : Trigger.new) {
                if(triggerCount.runonce()){
                    List<Teacher__c> existingTeachers = [SELECT Id, Name, Email__c, Mobile__c, Address__c, teacherid__c FROM Teacher__c WHERE teacherid__c = :student.id LIMIT 1];
                    if (!existingTeachers.isEmpty()) {
                        Teacher__c teacher = existingTeachers[0];
                        teacher.Name = student.Name;
                        teacher.Email__c = student.Email__c;
                        teacher.Mobile__c = student.Mobile__c;
                        teacher.Address__c = student.Address__c;
                        teachersToUpdate.add(teacher);
                    }
                }
            }
            
            if (!teachersToUpdate.isEmpty()) {
                update teachersToUpdate;
            }
        }
        if (Trigger.isDelete) {
            list<String> studentIds=new list<String>();
            for(Student__c student:trigger.old)
            {
                studentIds.add(student.id);
            }
            list<Teacher__c> listOfTeachers=[select id,teacherid__c from Teacher__c where teacherid__c in:studentIds];
            system.debug('listOfTeachers'+listOfTeachers);
            if (!listOfTeachers.isEmpty()) {
                delete listOfTeachers;
            }
        }
    }
}
Thanks
I have lookup relationship between 2 objects on both objects if i delete the parent record i want to delete the child record also .how can i do this.
I was trying to do this but it is not getting deleted can anyone help where I am doing wrong.can anyone help

trigger TriggerOnTeacher on Teacher__c (after insert, after update, before delete) {
    List<Student__c> studentRecordsToUpdate = new List<Student__c>();
    List<Student__c> studentRecordsToDelete = new List<Student__c>();
    Set<Id> studentIdsToDelete = new Set<Id>();
    if (Trigger.isUpdate) {
        for (Teacher__c teacherRecord : Trigger.new) {
            Student__c studentRecord = [SELECT Id, Name, Firstname__c, Lastname__c, Email__c, Mobile__c, DOB__c, Address__c, City__c, Country__c
                                        FROM Student__c
                                        WHERE Teacher__c = :teacherRecord.Id];
            if (studentRecord != null) {
                studentRecord.Name = teacherRecord.Name;
                studentRecord.Firstname__c = teacherRecord.Firstname__c;
                studentRecord.Lastname__c = teacherRecord.Lastname__c;
                studentRecord.Email__c = teacherRecord.Email__c;
                studentRecord.Mobile__c = teacherRecord.Mobile__c;
                studentRecord.DOB__c = teacherRecord.DOB__c;
                studentRecord.Address__c = teacherRecord.Address__c;
                studentRecord.City__c = teacherRecord.City__c;
                studentRecord.Country__c = teacherRecord.Country__c;
                studentRecordsToUpdate.add(studentRecord);
            }
        }
    }
    
    if (Trigger.isInsert) {
        for (Teacher__c teacherRecord : Trigger.new) {
            if(triggerCount.runonce()){
                Student__c studentRecord = new Student__c();
                studentRecord.Teacher__c = teacherRecord.Id;
                studentRecord.Name = teacherRecord.Name;
                studentRecord.Firstname__c = teacherRecord.Firstname__c;
                studentRecord.Lastname__c = teacherRecord.Lastname__c;
                studentRecord.Email__c = teacherRecord.Email__c;
                studentRecord.Mobile__c = teacherRecord.Mobile__c;
                studentRecord.DOB__c = teacherRecord.DOB__c;
                studentRecord.Address__c = teacherRecord.Address__c;
                studentRecord.City__c = teacherRecord.City__c;
                studentRecord.Country__c = teacherRecord.Country__c;
                studentRecordsToUpdate.add(studentRecord);
            }
        }
    }
    
    if (Trigger.isDelete) {
        for (Teacher__c teacherRecord : Trigger.old) {
            studentIdsToDelete.add(teacherRecord.Student__c);
        }
    }
    
    if (!studentRecordsToUpdate.isEmpty()) {
        upsert studentRecordsToUpdate;
    }
    
    if (!studentRecordsToDelete.isEmpty()) {
        List<Student__c> studentsToDelete = [SELECT Id FROM Student__c WHERE Teacher__c IN :studentIdsToDelete];
        delete studentsToDelete;
    }
}

Thanks,
Create two Objects say Teacher(Parent) and Student(Child) having similar fields. On creating record of Teacher, associated student record should be created and vice versa. Additionally, updates should also be in sync i.e. updating the parent should reflect in the child and vice versa.
I want to do this with the help of salesforce flow how to do that?

Thanks
I have one JSON data as_
[
    {
        "AccountName":"Test Account new",
        "Desc":"Test Desc",
        "Phone":"9898989898",
        "ContactLastName":"Test contact
    }
]
 
I want to create Account and Contact from above json data. How to do that? Can anyone help.

Thanks,


 
Hi, 

I have apex code like 
 description = wrapperRec.accountName + '\'s ' + wrapperRec.shippingCity + ' location has shown a very high engagement with Siemens Energy\'s \"IP Address Targeting\" ' +wrapperRec.unitTypeFamily + ' ad.';
                                        description = description + '\nWe advise our account manager to reach out to their customer contact and to gauge their interest in the product.';
                                        description = description + '\n\nIn case more details are needed, please contact'+ accountBasedMarketingDetails.IP_Address_Contact__c;
                                        description = description + '\n\n' + dt.format('MMMM') + ' '+d.day() +','+d.year();
                                        prospect.Description__c = description;

and here IP_Address_Contact__c is a custom field on custom setting, I want that value should be populted and I want to check that in test class so I have written test function like ,
 @isTest
    public static void testCreateProspectsJabmoDescCheck()   {
        Account_Based_Marketing_Settings__c abmCustomSetting = new Account_Based_Marketing_Settings__c();
        abmCustomSetting.Jabmo_Automation_Is_Active__c = true;
        abmCustomSetting.Jabmo_Automation_Urgency__c = 'High Urgency';
        abmCustomSetting.JABMO_CLICKS__c = 3;
        abmCustomSetting.JABMO_CTR__c = 0.03;
        abmCustomSetting.IP_Address_Contact__c ='Digi Sales at digi.sales@siemens-energy.com.';
        insert abmCustomSetting;
        Account acc = [Select id from account where name ='Taqa' limit 1];
        String fullJson = '[{"Account Name": "Taqa","Unit Type Family": "FDS-IST-MGT-SGT-AGT-TCP","Country Code": "GB","Shipping City": "Brough","clicks": 5,"ctr": 0.0538677009},{"Account Name": "Taqa","Unit Type Family": "Cyber-IST-MGT-SGT-AGT-TCP-RCE","Country Code": "GB","Shipping City": "Brough","clicks": 6,"ctr": 0.0658761528}]';
        Test.setMock(HttpCalloutMock.class, new RestMock(200,fullJson));
        List<Prospect__c> prospectList = [Select id from Prospect__c where Account_Name__c =: acc.id];
        System.assertEquals(0, prospectList.size());
        Test.startTest();
        CreateProspectsFromJabmo_Batch obj = new CreateProspectsFromJabmo_Batch();
        DataBase.executeBatch(obj); 
        Test.stopTest();
         prospectList = [Select id, Description__c from Prospect__c where Account_Name__c =: acc.id];
        for(Prospect__c pro : prospectList){
         System.assertEquals('In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.', pro.Description__c,'Description should match');
         }  

but getting error as, assertion failed
System.AssertException: Assertion Failed: Description should match: Expected: In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com., Actual: Taqa's Brough location has shown a very high engagement with Siemens Energy's "IP Address Targeting" FDS-IST-MGT-SGT-AGT-TCP ad.
We advise our account manager to reach out to their customer contact and to gauge their interest in the product.

In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.

February 9,2023

can anyone help in writing correct assert statement for this?


Thanks,
 
Hi,
create one button on account, upload one csv file to account and whenever I click on button It should create Accounts from the data present in csv file using lightning component. can anyone help how can I do that?


Thanks,
I want to create one picklist namely rating and having values 1,2,3,4,5 and we have five images of 1 star , 2 star etc upto 5 star and wanted to create one image formula field where we will be able able to see images which we have from 1 star to 5 star.
How to acieve this?

Thanks
Here I have a trigger whenever I create a new account it should create new contact with the account name.
if account name is updated of existing account then it will check if related contact exist with new name if not exist then create new contact .


Trigger:
trigger AccountContactTrig on Account (after insert,after update) {
     Set<Id> accIds= new Set<Id>();
    If(Trigger.isinsert && Trigger.isafter){
        List<Contact> cont = new List <Contact>();
        for(Account acc : trigger.new){
            Contact c = new Contact();
            c.AccountId=acc.id;
            c.LastName = acc.name;
            cont.add(c);
        }
        insert cont; 
    }
    if(Trigger.isupdate && Trigger.isafter){
        Set<String> accnames= new Set<String>();
        For(Account acc:Trigger.new){
            Account oldacc= Trigger.oldmap.get(acc.id);
            if(acc.name!= oldacc.Name){
                accnames.add(acc.name);
            }
        }
        Map<Id,Account> mapaccounts = new Map<Id,Account>([Select Name,(Select id, Lastname from contacts where Lastname in: accnames) from Account where id in:Trigger.new]);
        List<Contact> cont = new List <Contact>();
        if(mapaccounts.size()>0){
        for(Account ac: Trigger.new){
            if(Ac.Name != trigger.OldMap.get(Ac.Id).Name){               
            if(mapaccounts.containsKey(ac.id)){
                if(mapaccounts.get(ac.id).Contacts.size()==0){
                        Contact c = new Contact();
                        c.AccountId=ac.id;
                        c.LastName = ac.name;
                        cont.add(c);
                }
            }
        }
         insert cont;
    }
        }
    }
}
Trigger:-

trigger AccountContactTrig on Account (after insert,after update) {
     Set<Id> accIds= new Set<Id>();
    If(Trigger.isinsert && Trigger.isafter){
        List<Contact> cont = new List <Contact>();
        for(Account acc : trigger.new){
            Contact c = new Contact();
            c.AccountId=acc.id;
            c.LastName = acc.name;
            cont.add(c);
        }
        insert cont; 
    }
    if(Trigger.isupdate && Trigger.isafter){
        Set<String> accnames= new Set<String>();
        For(Account acc:Trigger.new){
            Account oldacc= Trigger.oldmap.get(acc.id);
            if(acc.name!= oldacc.Name){
                accnames.add(acc.name);
            }
        }
        Map<Id,Account> mapaccounts = new Map<Id,Account>([Select Name,(Select id, Lastname from contacts where Lastname in: accnames) from Account where id in:Trigger.new]);
        List<Contact> cont = new List <Contact>();
        if(mapaccounts.size()>0){
        for(Account ac: Trigger.new){
            if(Ac.Name != trigger.OldMap.get(Ac.Id).Name){               
            if(mapaccounts.containsKey(ac.id)){
                if(mapaccounts.get(ac.id).Contacts.size()==0){
                        Contact c = new Contact();
                        c.AccountId=ac.id;
                        c.LastName = ac.name;
                        cont.add(c);
                }
            }
        }
         insert cont;
    }
        }
    }
}
I have writen trigger for create contact when accountname is update  if I change any field on account it is creating new contact But I want it for account name only. supoose 
if I update any field on account it is creating new contact
I want to create contact only if account name is updated.

code:-
trigger AccountContactTrig on Account (after insert,before update) {
    
    If(Trigger.isinsert && Trigger.isafter){
        List<Contact> cont = new List <Contact>();
        
        for(Account acc : trigger.new){
            
            Contact c = new Contact();
            c.AccountId=acc.id;
            c.LastName = acc.name;
            cont.add(c);
        }
        insert cont; 
    }
    if(Trigger.isupdate && Trigger.isbefore){
        Set<String> accnames= new Set<String>();
        For(Account acc:Trigger.new){
            Account oldacc= Trigger.oldmap.get(acc.id);
            if(acc.name!= oldacc.Name){
                accnames.add(acc.name);
            }
        }
        Map<Id,Account> mapaccounts = new Map<Id,Account>([Select Name,(Select id, Lastname from contacts where Lastname in: accnames) from Account where id in:Trigger.new]);
        List<Contact> cont = new List <Contact>();
        for(Account ac: Trigger.new){
            if(mapaccounts.containsKey(ac.id)){
                if(mapaccounts.get(ac.id).Contacts.size()==0){
                        Contact c = new Contact();
                        c.AccountId=ac.id;
                        c.LastName = ac.name;
                        cont.add(c);
               
                }
                    
            }
        }
         insert cont;
    }
}
can anyone help?
Thanks
Hello, I have two dropdowns one is of contacts lastname and another is for contacts title and I want to show the data according to both dropdowns selected value.
suppose in lastname deshmukh is selected and for title abc is selected then it should the contacts whose lastname is deshmukh and title is abc.
I have attached  my code here I can see data according to lastname value but for title it is not working. can anyone help how can I do that.
stuck here from two days.
code:-
component:-
<aura:component controller="relatedcontactlist" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="ContactList" type="Contact[]"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="options" type="List" />
    <aura:attribute name="conOption" type="List" />
    <aura:attribute name="titOption" type="List" />
    <aura:attribute name="selectedContact" type="String" />
    <aura:attribute name="selectedtitle" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    <lightning:card iconName="standard:work_capacity_usage" title="Related Contacts">
        <!--  <lightning:layoutItem padding="around-small" size="4">  
            <div class="slds-dropdown slds-dropdown_left"> -->
        <lightning:layout>
            <lightning:layoutItem size="6" class="left-align">
                <lightning:select name="con" label="Select a Contact:" aura:id="con" value="{!v.selectedContact}" onchange="{!c.changeAction}">
                    <aura:iteration items="{!v.conOption}" var="opt">
                        <option text="{!opt}" value="{!opt}" selected="{!opt.selected}"/>
                    </aura:iteration>
                </lightning:select>
            </lightning:layoutItem> 
            <!--  <lightning:layoutItem padding="around-small" size="4"> 
            <div class="slds-dropdown slds-dropdown_right" size="4"> -->
            <lightning:layoutItem size="6" class="right-align">
                <lightning:select name="tit" label="Select a title:" aura:id="tit" value="{!v.selectedtitle}" onchange="{!c.changetitle}">
                    <aura:iteration items="{!v.titOption}" var="opt">
                        <option text="{!opt}" value="{!opt}" selected="{!opt.selected}"/>
                    </aura:iteration>
                </lightning:select>   
            </lightning:layoutItem> 
        </lightning:layout>
                <aura:if isTrue="{!not(empty(v.ContactList))}">
                    <lightning:datatable data="{!v.ContactList }" 
                                         columns="{!v.columns }" 
                                         keyField="Id"
                                         hideCheckboxColumn="true"/>
                    <aura:set attribute="else">
                        <div Style="text-align : center"> " There are no related contacts " </div>
                    </aura:set>
                </aura:if>
            </lightning:card>
        </aura:component>

controller:-
({
    myAction : function(component, event, helper) 
    {
        
        component.set('v.columns', [
            {label: 'Title', fieldName: 'Title', type: 'text' },
            {label: 'First Name', fieldName: 'FirstName', type: 'text' },
            {label: 'Last Name', fieldName: 'LastName', type: 'text' },
            {label: 'Email', fieldName: 'Email', type: 'Email' },
            {label: 'Phone', fieldName: 'Phone', type: 'Phone' }
            
        ]);
        
        var ConList = component.get("c.getRelatedList");
        ConList.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        ConList.setCallback(this, function(data) 
                            {
                                var a = data.getReturnValue();
                                component.set("v.ContactList", data.getReturnValue().contactListt);
                                component.set("v.conOption", data.getReturnValue().lastnameSet);
                                component.set("v.titOption", data.getReturnValue().titleSet);
                            });
        
        
        $A.enqueueAction(ConList);
    },
    changeAction : function(component, event, helper) {
        var sel = component.get("v.selectedContact");
        var ConListt = component.get("c.getSelectedList");
        if(sel == "All")
        {
            $A.enqueueAction(component.get('c.myAction'));
        }
        else{
            ConListt.setParams
            ({
                recordId: component.get("v.recordId"),
                selectedCon : component.get("v.selectedContact")
            });
            ConListt.setCallback(this, function(data)
                                 {
                                     component.set("v.ContactList", data.getReturnValue());
                                 });
            
            $A.enqueueAction(ConListt);
        }
        
    },
    changetitle : function(component, event, helper) {
        alert(component.get("v.selectedtitle"));
        var sel = component.get("v.selectedtitle");
        var ConLists = component.get("c.getSelectedListoftitle");
        console.log(ConLists);
            ConLists.setParams
            ({
                recordId: component.get("v.recordId"),
                selectedtit : component.get("v.selectedtitle")
            });
            console.log(selectedtit);
            ConLists.setCallback(this, function(data)
                                 {
                                     component.set("v.ContactList", data.getReturnValue());
                                 });
            
            $A.enqueueAction(ConLists);
        }
        
    
})

apex:-
public class relatedcontactlist {
    @AuraEnabled
    public static wrapContact getRelatedList(String recordId)
    {
        List<Contact> Conlist = [Select AccountId,Id,firstname,lastname,Email,Phone,title from Contact where AccountId=: recordId ];
        Set<String> lastnames = new Set<String>();
        Set<String> titles = new Set<String>();
        wrapContact wrapinst = new wrapContact();
        wrapinst.contactListt = Conlist;
        lastnames.add('All');
        titles.add('All');
        for(Contact con :Conlist)
        {
            lastnames.add(con.lastname);
            titles.add(con.title);
        }
        wrapinst.lastnameSet = lastnames;
        wrapinst.titleSet = titles;
        System.debug(wrapinst.contactListt);
        System.debug(wrapinst.lastnameSet);
        System.debug(wrapinst.titleSet);
        return wrapinst;
        
    }
    @AuraEnabled 
    public static List<Contact> getSelectedList(String recordId, String selectedCon)
    {
        
        List<Contact> showCon = [SELECT AccountId,LastName ,FirstName,Email,Phone,title FROM Contact WHERE AccountId =: recordId AND LastName =:selectedCon];
        System.debug('recordId'+recordId);
        System.debug('selectedCon'+selectedCon);
        return showCon;
    }  
    public static List<Contact> getSelectedListoftitle(String recordId, String selectedtit)
    {
        
        List<Contact> showtit = [SELECT AccountId,LastName ,FirstName,Email,Phone,title FROM Contact WHERE AccountId =: recordId AND title =:selectedtit];
        System.debug('recordId'+recordId);
        System.debug('selectedtit'+selectedtit);
        return showtit;
    }  
    public class wrapContact{
        @AuraEnabled 
        public list<contact> contactListt{get;set;}
        @AuraEnabled 
        public set<String> lastnameSet{get;set;}
        @AuraEnabled
        public set<String> titleSet{get;set;}
        
    }
}
 I have attached UI too
Thanks,User-added image
I have one lightning component which shows related contacts of that account and one dropdown which contains lastnames of all related contacts.
now I want to show suppose if I select Jain lastname from that dropdown I want to show only related contacts whose lastname is jain. How to achieve this?

code:-
apex:
public class relatedcontactlist {
    @AuraEnabled
    public static wrapContact getRelatedList(String recordId)
    {
        List<Contact> Conlist = [Select AccountId,Id,firstname,lastname from Contact where AccountId=: recordId ];
        Set<String> lastnames = new Set<String>();
        wrapContact wrapinst = new wrapContact();
        wrapinst.contactListt = Conlist;
        lastnames.add('All');
        for(Contact con :Conlist)
        {
            lastnames.add(con.lastname);
        }
        wrapinst.lastnameSet = lastnames;
        System.debug(wrapinst.contactListt);
       System.debug(wrapinst.lastnameSet);
        return wrapinst;
        
    }
    public class wrapContact{
         @AuraEnabled 
        public list<contact> contactListt{get;set;}
         @AuraEnabled 
        public set<String> lastnameSet{get;set;}
      
    }
}

component:
<aura:component controller="relatedcontactlist" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="ContactList" type="Contact[]"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="options" type="List" />
    <aura:attribute name="conOption" type="List" />
    <aura:attribute name="selectedContact" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    <lightning:card iconName="standard:work_capacity_usage" title="Related Contacts">
        
   <lightning:select name="con" label="Select a Contact:" aura:id="con" value="{!v.selectedContact}" onchange="{!c.changeAction}">
            <aura:iteration items="{!v.conOption}" var="opt">
                <option text="{!opt}" value="{!opt}"/>
            </aura:iteration>
        </lightning:select>
        
        <aura:if isTrue="{!not(empty(v.ContactList))}">
            <lightning:datatable data="{!v.ContactList }" 
                                 columns="{!v.columns }" 
                                 keyField="Id"
                                 hideCheckboxColumn="true"/>
            <aura:set attribute="else">
                <div Style="text-align : center"> " There are no related contacts " </div>
            </aura:set>
        </aura:if>
    </lightning:card>
</aura:component>

controller:-
({
myAction : function(component, event, helper) 
     {

component.set('v.columns', [
            {label: 'First Name', fieldName: 'FirstName', type: 'text' },
            {label: 'Last Name', fieldName: 'LastName', type: 'text' }
         ]);

         var ConList = component.get("c.getRelatedList");
         ConList.setParams
         ({
             recordId: component.get("v.recordId")
         });

         ConList.setCallback(this, function(data) 
                           {
                               var a = data.getReturnValue();
                               component.set("v.ContactList", data.getReturnValue().contactListt);
                               component.set("v.conOption", data.getReturnValue().lastnameSet);
                               //console.log(a);
                               //alert(a.contactListt);
                               //alert(a.lastnameSet);
                               //alert(a);
                               
                           });
     
        
         $A.enqueueAction(ConList);
},
  changeAction : function(component, event, helper) {
        var ConAccID = component.get("v.selectedContact");
        var action = component.get("c.getRelatedList");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(actionResult) {
            component.set('v.conOption.lastnameSet', actionResult.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})


Thanks,
how can I display account objects related contact's lastname in dropdown formal using aura.


Thanks,
 
I have one dropdown list for lastname of contacts in my lightning component which have values like all, deshmukh etc and if I select deshmukh from dropdown it should display contacts whose lastname is deshmukh, if it is jail it should display contact whose lastname is jain like that.

code:-
component:-
<aura:component controller="relatedcontactlist" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
   <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="ContactList" type="Contact[]"/>
    <aura:attribute name="columns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    <lightning:card iconName="standard:work_capacity_usage" title="Related Contacts">
        <lightning:select name="select1" label="Lastnames" required="true">
        <option value="1">All</option>
        <option value="2">Deshmukh</option>
        <option value="3">Pagar</option>
        <option value="4">Joshi</option>
        <option value="4">Jain</option>
    </lightning:select>
        <aura:if isTrue="{!not(empty(v.ContactList))}">
            <lightning:datatable data="{!v.ContactList }" 
                         columns="{!v.columns }" 
                         keyField="Id"
                         hideCheckboxColumn="true"/>
            <aura:set attribute="else">
                <div Style="text-align : center"> " There are no related contacts " </div>
            </aura:set>
        </aura:if>
    </lightning:card>
</aura:component>

controller:-
({
 myAction : function(component, event, helper) 
     {

 component.set('v.columns', [
            {label: 'First Name', fieldName: 'FirstName', type: 'text' },
            {label: 'Last Name', fieldName: 'LastName', type: 'text' }
         ]);

         var ConList = component.get("c.getRelatedList");
         ConList.setParams
         ({
             recordId: component.get("v.recordId")
         });
        
         ConList.setCallback(this, function(data) 
                           {
                               component.set("v.ContactList", data.getReturnValue());
                           });
         $A.enqueueAction(ConList);
 }
})

apex:-
public class relatedcontactlist {
    @AuraEnabled
    public static list<Contact> getRelatedList(Id recordId)
    {
        List<Contact> Conlist = [Select id, name,firstname,lastname from Contact where AccountId=: recordId ];
        return Conlist;
    }
}


Thanks
 
when we open a account record we can see details, related and news , how to create one more there and I want to show related contacts there.

User-added image
I have lookup relationship between 2 objects on both objects if i delete the parent record i want to delete the child record also .how can i do this.
I was trying to do this but it is not getting deleted can anyone help where I am doing wrong.can anyone help

trigger TriggerOnTeacher on Teacher__c (after insert, after update, before delete) {
    List<Student__c> studentRecordsToUpdate = new List<Student__c>();
    List<Student__c> studentRecordsToDelete = new List<Student__c>();
    Set<Id> studentIdsToDelete = new Set<Id>();
    if (Trigger.isUpdate) {
        for (Teacher__c teacherRecord : Trigger.new) {
            Student__c studentRecord = [SELECT Id, Name, Firstname__c, Lastname__c, Email__c, Mobile__c, DOB__c, Address__c, City__c, Country__c
                                        FROM Student__c
                                        WHERE Teacher__c = :teacherRecord.Id];
            if (studentRecord != null) {
                studentRecord.Name = teacherRecord.Name;
                studentRecord.Firstname__c = teacherRecord.Firstname__c;
                studentRecord.Lastname__c = teacherRecord.Lastname__c;
                studentRecord.Email__c = teacherRecord.Email__c;
                studentRecord.Mobile__c = teacherRecord.Mobile__c;
                studentRecord.DOB__c = teacherRecord.DOB__c;
                studentRecord.Address__c = teacherRecord.Address__c;
                studentRecord.City__c = teacherRecord.City__c;
                studentRecord.Country__c = teacherRecord.Country__c;
                studentRecordsToUpdate.add(studentRecord);
            }
        }
    }
    
    if (Trigger.isInsert) {
        for (Teacher__c teacherRecord : Trigger.new) {
            if(triggerCount.runonce()){
                Student__c studentRecord = new Student__c();
                studentRecord.Teacher__c = teacherRecord.Id;
                studentRecord.Name = teacherRecord.Name;
                studentRecord.Firstname__c = teacherRecord.Firstname__c;
                studentRecord.Lastname__c = teacherRecord.Lastname__c;
                studentRecord.Email__c = teacherRecord.Email__c;
                studentRecord.Mobile__c = teacherRecord.Mobile__c;
                studentRecord.DOB__c = teacherRecord.DOB__c;
                studentRecord.Address__c = teacherRecord.Address__c;
                studentRecord.City__c = teacherRecord.City__c;
                studentRecord.Country__c = teacherRecord.Country__c;
                studentRecordsToUpdate.add(studentRecord);
            }
        }
    }
    
    if (Trigger.isDelete) {
        for (Teacher__c teacherRecord : Trigger.old) {
            studentIdsToDelete.add(teacherRecord.Student__c);
        }
    }
    
    if (!studentRecordsToUpdate.isEmpty()) {
        upsert studentRecordsToUpdate;
    }
    
    if (!studentRecordsToDelete.isEmpty()) {
        List<Student__c> studentsToDelete = [SELECT Id FROM Student__c WHERE Teacher__c IN :studentIdsToDelete];
        delete studentsToDelete;
    }
}

Thanks,
I have one JSON data as_
[
    {
        "AccountName":"Test Account new",
        "Desc":"Test Desc",
        "Phone":"9898989898",
        "ContactLastName":"Test contact
    }
]
 
I want to create Account and Contact from above json data. How to do that? Can anyone help.

Thanks,


 
Hi, 

I have apex code like 
 description = wrapperRec.accountName + '\'s ' + wrapperRec.shippingCity + ' location has shown a very high engagement with Siemens Energy\'s \"IP Address Targeting\" ' +wrapperRec.unitTypeFamily + ' ad.';
                                        description = description + '\nWe advise our account manager to reach out to their customer contact and to gauge their interest in the product.';
                                        description = description + '\n\nIn case more details are needed, please contact'+ accountBasedMarketingDetails.IP_Address_Contact__c;
                                        description = description + '\n\n' + dt.format('MMMM') + ' '+d.day() +','+d.year();
                                        prospect.Description__c = description;

and here IP_Address_Contact__c is a custom field on custom setting, I want that value should be populted and I want to check that in test class so I have written test function like ,
 @isTest
    public static void testCreateProspectsJabmoDescCheck()   {
        Account_Based_Marketing_Settings__c abmCustomSetting = new Account_Based_Marketing_Settings__c();
        abmCustomSetting.Jabmo_Automation_Is_Active__c = true;
        abmCustomSetting.Jabmo_Automation_Urgency__c = 'High Urgency';
        abmCustomSetting.JABMO_CLICKS__c = 3;
        abmCustomSetting.JABMO_CTR__c = 0.03;
        abmCustomSetting.IP_Address_Contact__c ='Digi Sales at digi.sales@siemens-energy.com.';
        insert abmCustomSetting;
        Account acc = [Select id from account where name ='Taqa' limit 1];
        String fullJson = '[{"Account Name": "Taqa","Unit Type Family": "FDS-IST-MGT-SGT-AGT-TCP","Country Code": "GB","Shipping City": "Brough","clicks": 5,"ctr": 0.0538677009},{"Account Name": "Taqa","Unit Type Family": "Cyber-IST-MGT-SGT-AGT-TCP-RCE","Country Code": "GB","Shipping City": "Brough","clicks": 6,"ctr": 0.0658761528}]';
        Test.setMock(HttpCalloutMock.class, new RestMock(200,fullJson));
        List<Prospect__c> prospectList = [Select id from Prospect__c where Account_Name__c =: acc.id];
        System.assertEquals(0, prospectList.size());
        Test.startTest();
        CreateProspectsFromJabmo_Batch obj = new CreateProspectsFromJabmo_Batch();
        DataBase.executeBatch(obj); 
        Test.stopTest();
         prospectList = [Select id, Description__c from Prospect__c where Account_Name__c =: acc.id];
        for(Prospect__c pro : prospectList){
         System.assertEquals('In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.', pro.Description__c,'Description should match');
         }  

but getting error as, assertion failed
System.AssertException: Assertion Failed: Description should match: Expected: In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com., Actual: Taqa's Brough location has shown a very high engagement with Siemens Energy's "IP Address Targeting" FDS-IST-MGT-SGT-AGT-TCP ad.
We advise our account manager to reach out to their customer contact and to gauge their interest in the product.

In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.

February 9,2023

can anyone help in writing correct assert statement for this?


Thanks,
 
Hi,
create one button on account, upload one csv file to account and whenever I click on button It should create Accounts from the data present in csv file using lightning component. can anyone help how can I do that?


Thanks,
I want to create one picklist namely rating and having values 1,2,3,4,5 and we have five images of 1 star , 2 star etc upto 5 star and wanted to create one image formula field where we will be able able to see images which we have from 1 star to 5 star.
How to acieve this?

Thanks
Here I have a trigger whenever I create a new account it should create new contact with the account name.
if account name is updated of existing account then it will check if related contact exist with new name if not exist then create new contact .


Trigger:
trigger AccountContactTrig on Account (after insert,after update) {
     Set<Id> accIds= new Set<Id>();
    If(Trigger.isinsert && Trigger.isafter){
        List<Contact> cont = new List <Contact>();
        for(Account acc : trigger.new){
            Contact c = new Contact();
            c.AccountId=acc.id;
            c.LastName = acc.name;
            cont.add(c);
        }
        insert cont; 
    }
    if(Trigger.isupdate && Trigger.isafter){
        Set<String> accnames= new Set<String>();
        For(Account acc:Trigger.new){
            Account oldacc= Trigger.oldmap.get(acc.id);
            if(acc.name!= oldacc.Name){
                accnames.add(acc.name);
            }
        }
        Map<Id,Account> mapaccounts = new Map<Id,Account>([Select Name,(Select id, Lastname from contacts where Lastname in: accnames) from Account where id in:Trigger.new]);
        List<Contact> cont = new List <Contact>();
        if(mapaccounts.size()>0){
        for(Account ac: Trigger.new){
            if(Ac.Name != trigger.OldMap.get(Ac.Id).Name){               
            if(mapaccounts.containsKey(ac.id)){
                if(mapaccounts.get(ac.id).Contacts.size()==0){
                        Contact c = new Contact();
                        c.AccountId=ac.id;
                        c.LastName = ac.name;
                        cont.add(c);
                }
            }
        }
         insert cont;
    }
        }
    }
}
Trigger:-

trigger AccountContactTrig on Account (after insert,after update) {
     Set<Id> accIds= new Set<Id>();
    If(Trigger.isinsert && Trigger.isafter){
        List<Contact> cont = new List <Contact>();
        for(Account acc : trigger.new){
            Contact c = new Contact();
            c.AccountId=acc.id;
            c.LastName = acc.name;
            cont.add(c);
        }
        insert cont; 
    }
    if(Trigger.isupdate && Trigger.isafter){
        Set<String> accnames= new Set<String>();
        For(Account acc:Trigger.new){
            Account oldacc= Trigger.oldmap.get(acc.id);
            if(acc.name!= oldacc.Name){
                accnames.add(acc.name);
            }
        }
        Map<Id,Account> mapaccounts = new Map<Id,Account>([Select Name,(Select id, Lastname from contacts where Lastname in: accnames) from Account where id in:Trigger.new]);
        List<Contact> cont = new List <Contact>();
        if(mapaccounts.size()>0){
        for(Account ac: Trigger.new){
            if(Ac.Name != trigger.OldMap.get(Ac.Id).Name){               
            if(mapaccounts.containsKey(ac.id)){
                if(mapaccounts.get(ac.id).Contacts.size()==0){
                        Contact c = new Contact();
                        c.AccountId=ac.id;
                        c.LastName = ac.name;
                        cont.add(c);
                }
            }
        }
         insert cont;
    }
        }
    }
}
I have one dropdown list for lastname of contacts in my lightning component which have values like all, deshmukh etc and if I select deshmukh from dropdown it should display contacts whose lastname is deshmukh, if it is jail it should display contact whose lastname is jain like that.

code:-
component:-
<aura:component controller="relatedcontactlist" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
   <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="ContactList" type="Contact[]"/>
    <aura:attribute name="columns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    <lightning:card iconName="standard:work_capacity_usage" title="Related Contacts">
        <lightning:select name="select1" label="Lastnames" required="true">
        <option value="1">All</option>
        <option value="2">Deshmukh</option>
        <option value="3">Pagar</option>
        <option value="4">Joshi</option>
        <option value="4">Jain</option>
    </lightning:select>
        <aura:if isTrue="{!not(empty(v.ContactList))}">
            <lightning:datatable data="{!v.ContactList }" 
                         columns="{!v.columns }" 
                         keyField="Id"
                         hideCheckboxColumn="true"/>
            <aura:set attribute="else">
                <div Style="text-align : center"> " There are no related contacts " </div>
            </aura:set>
        </aura:if>
    </lightning:card>
</aura:component>

controller:-
({
 myAction : function(component, event, helper) 
     {

 component.set('v.columns', [
            {label: 'First Name', fieldName: 'FirstName', type: 'text' },
            {label: 'Last Name', fieldName: 'LastName', type: 'text' }
         ]);

         var ConList = component.get("c.getRelatedList");
         ConList.setParams
         ({
             recordId: component.get("v.recordId")
         });
        
         ConList.setCallback(this, function(data) 
                           {
                               component.set("v.ContactList", data.getReturnValue());
                           });
         $A.enqueueAction(ConList);
 }
})

apex:-
public class relatedcontactlist {
    @AuraEnabled
    public static list<Contact> getRelatedList(Id recordId)
    {
        List<Contact> Conlist = [Select id, name,firstname,lastname from Contact where AccountId=: recordId ];
        return Conlist;
    }
}


Thanks
 
How to create aura component for we need to enter firstname lastname and email and one contact should be created related to that account. 
I have tried like this but new account and contact is also getting created.
apex:-
public class contactRegistrationController {
@AuraEnabled
    public static Contact saveContact(Contact Contact) {
        account acc=new account();
        acc.Name=contact.FirstName +' ' +contact.LastName;
        insert acc;
        Contact.AccountId=acc.Id;
        upsert Contact;
        return Contact;
    }
}


component:-
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global"  controller="contactRegistrationController" >
    <aura:attribute name="contacts" type="Contact[]"/>
    <aura:attribute name="accounts" type="Account[]"/> 
    <aura:attribute name="newContact" type="Contact"
                    default="{ 'sobjectType': 'Contact',
                             'FirstName': '',
                             'LastName': '',
                             'Email': '',
                             'Phone': '','MailingStreet':'','MailingCity':'','MailingState':'','Zip':'','MailingCountry':'',
                             'Password__c': '' }"/>
    <div class="slds-page-header" role="banner">
        <div class="slds-grid">
            <div class="slds-col">
                <p class="slds-text-heading--label">Contact</p>
                <h1 class="slds-text-heading--medium">My Contact</h1>
            </div>
        </div>
    </div>
    <div class="slds-col slds-col--padded slds-p-top--large">
        <div aria-labelledby="newcontactform">
            <fieldset class="slds-box slds-theme--default slds-container--small">
                <legend id="newexpenseform" class="slds-text-heading--small 
                                                   slds-p-vertical--medium">
                    Add Contact
                </legend>
                <form class="slds-form--stacked">
                    <div class="slds-form-element slds-is-required">
                        <div class="slds-form-element__control">
                            <ui:inputText aura:id="fstname" label="First Name"
                                          class="slds-input"
                                          labelClass="slds-form-element__label"
                                          value="{!v.newContact.FirstName}"
                                          required="true"/>
                        </div></div>
                    <div class="slds-form-element slds-is-required">
                        <div class="slds-form-element__control">
                            <ui:inputText aura:id="lstname" label="Last Name"
                                          class="slds-input"
                                          labelClass="slds-form-element__label"
                                          value="{!v.newContact.LastName}"
                                          required="true"/>
                        </div>
                    </div>
                    
                    <div class="slds-form-element slds-is-required">
                        <div class="slds-form-element__control">
                            <ui:inputText aura:id="email" label="Email"
                                          class="slds-input"
                                          labelClass="slds-form-element__label"
                                          value="{!v.newContact.Email}"
                                          required="true"/>
                        </div>
                    </div>
                    
                    <div class="slds-form-element">
                        <ui:button label="Submit"
                                   class="slds-button slds-button--brand"
                                   press="{!c.clickCreateContact}"/>
                    </div>
                </form>
            </fieldset>
        </div>
    </div>
</aura:component>

controller:-
({
    clickCreateContact: function(component, event, helper) {
        console.log('inside click create contact');
        var validExpense = true;
        var firstnameField = component.find("fstname");
        var frtname = firstnameField.get("v.value");
        
        if ($A.util.isEmpty(frtname)){
            validExpense = false;
            firstnameField.set("v.errors", [{message:"First name can't be blank."}]);
        }
        else {
            firstnameField.set("v.errors", null);
        }
        
        var lastnameField = component.find("lstname");
        var larname = lastnameField.get("v.value");
        if ($A.util.isEmpty(larname)){
            validExpense = false;
            lastnameField.set("v.errors", [{message:"Last Name can't be blank."}]);
        }
        else {
            lastnameField.set("v.errors", null);
        }
        
       if(validExpense){
            var newContact = component.get("v.newContact");
            //var newAccount = component.get("v.newAccount");
            console.log("Create Contact: " + JSON.stringify(newContact));
           // console.log("Create Account: " + JSON.stringify(newAccount));

           //helper.createAccount(component, newAccount);
           helper.createContact(component, newContact);
           
       }
    },
})

Helper:-
({
   
    createContact: function(component, contact) {
        console.log('inside helper');
        
    var action = component.get("c.saveContact");
        console.log('after method called ');
    action.setParams({
        "Contact": contact
        //component.get("v.contacts")
         
    });
    action.setCallback(this, function(response){
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            var contacts = component.get("v.contacts");
            contacts.push(response.getReturnValue());
            component.set("v.contacts", contacts);
            alert('contact inserted successfully');
             
        }
    });
    $A.enqueueAction(action);
},
    
})


can anyone help how can I achieve this.
Thanks,
Mokshada