You need to sign in to do that
Don't have an account?
Akash Choudhary 17
Populate the Contact Description with the ownerId and name whenever an opportunity is created.
Hi All,
I have written a code but the code is not deploying as expected can somebody please help me rectify this code.
public class David_Update_desc {
public static void updateContactMethod(List <Opportunity> OppList){
Set <Id> IdCollect = new Set <Id>();
For(Opportunity Opp : OppList){
If(Opp.AccountId != null){
IdCollect.add(Opp.AccountId);
}
}
List<Contact> Con = [SELECT Id,
Description
FROM Contact
WHERE AccountId IN :IdCollect];
Map <Id, Id> OppMap = new Map<Id, Id>();
For(Opportunity Opp : OppList){
OppMap.put(Opp.AccountId , Opp.OwnerId);
}
If(Con.size() > 0){
For(Contact c : Con){
c.Description = 'the Creator is ' + OppMap.get(c.AccountId);
Update c;
}
}
}}
Thanks.
I have written a code but the code is not deploying as expected can somebody please help me rectify this code.
public class David_Update_desc {
public static void updateContactMethod(List <Opportunity> OppList){
Set <Id> IdCollect = new Set <Id>();
For(Opportunity Opp : OppList){
If(Opp.AccountId != null){
IdCollect.add(Opp.AccountId);
}
}
List<Contact> Con = [SELECT Id,
Description
FROM Contact
WHERE AccountId IN :IdCollect];
Map <Id, Id> OppMap = new Map<Id, Id>();
For(Opportunity Opp : OppList){
OppMap.put(Opp.AccountId , Opp.OwnerId);
}
If(Con.size() > 0){
For(Contact c : Con){
c.Description = 'the Creator is ' + OppMap.get(c.AccountId);
Update c;
}
}
}}
Thanks.
Small Update on the steven code:
public class David_Update_desc {
public static void updateContactMethod(List <Opportunity> OppList){
Set <Id> IdCollect = new Set <Id>();
For(Opportunity Opp : OppList){
If(Opp.AccountId != null){
IdCollect.add(Opp.AccountId);
}
}
List<Contact> Con = [SELECT Id,
AccountId,
Description
FROM Contact
WHERE AccountId IN :IdCollect];
Map <Id, Id> OppMap = new Map<Id, Id>();
For(Opportunity Opp : OppList){
OppMap.put(Opp.AccountId , Opp.OwnerId);
}
Map<Id, User> OwnerMap = new Map<Id, User>([SELECT Id,
Name
FROM User
WHERE Id IN :OppMap.values()]);
If(Con.size() > 0){
For(Contact c : Con){
c.Description = 'the Creator is ' + OppMap.get(c.AccountId) + '-' + OwnerMap.get(OppMap.get(c.AccountId)).Name;
}
Update con;
}
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
Please mark the best answer!!!
Thanks,
Raj