You need to sign in to do that
Don't have an account?

Need Simple trigger to update case fields
Hi Experts,
I'm new to salesforce coding. I need a trigger for updating case fields based on account number.
For more information please find below image.

Regards,
Manu
I'm new to salesforce coding. I need a trigger for updating case fields based on account number.
For more information please find below image.
Regards,
Manu
This trigger will help you.
Regards,
niraj Kumar.
Refer below code:
Trigger:
Controller:
You can use above code for updating Account details.
Since for one Account there will be many Contact, so not sure which Contact's name you want to display. Is there any criteria to display Contact Name?
Thanks,
Dhanya
Thanks for your inputs.
Finally I have resolved my trigger issue with my own effort. Please find below trigger code.
Trigger AccountandContactUpdateTrigger on Case(before insert, before update){
List<String> AccNoSet = new List<String>();
for(Case c: trigger.new){
AccNoSet.add(c.Account_Number__c);
}
Map<String, Account> AccMap = new Map<String, Account>();
for(Account acc : [SELECT Id, Parent_VRP_Number__c, VRP_Account_Number__c from Account where VRP_Account_Number__c IN :AccNoSet]){
AccMap.put(acc.Parent_VRP_Number__c , acc);
}
for(Case c:trigger.new){
c.Accountid = AccMap.get(c.Account_Number__c).id;
if(c.accountid!=null){
List<Contact> ConList = [select id, name from Contact where accountid =:c.accountid];
if(!ConList.isempty()){
c.Contactid = ConList[0].id;
}
}
}
}
Regards,
Sai
You have used query inside for loop. So it will fail if you insert large amount of records from data loader.
Please check below code:
Trigger:
Controller: Thanks,
Dhanya
@thanks in adv