You need to sign in to do that
Don't have an account?
K@S
please help me on this i didn't get o/p
In opportunity object create a new Lookup – Deal Lead which is a lookup to Lead object.
Create new field Opportunity status and Lead status respectively in Opportunity and Lead.
Both pick list should contain below values: Open, In progres,Closed
When opportunity status is getting modified modify corresponding lead status also.
Assume that you can associate one lead with only one opportunity
trigger Update_status_Trigger on Opportunity (after update) {
Set<Id> oppId =new Set<Id>();
List<Lead> updList =new List<Lead>();
for(opportunity opps : Trigger.new){
if(opps.status__c!=Trigger.oldMap.get(opps.id).status__c){
oppId.add(opps.Id);
}
}
for(Lead led : ([select id,name,status__c FROM Lead WHERE oppId IN : oppId ])){
if(!Trigger.newMap.get(led.oppId).status__c.contains(led.status__c)){
updList.add(led);
}
}
try{
if(updList .size()>0){
Database.update(updList ,false);
}
}catch(Exception e){
System.debug('########'+e.getMessage());
}
}
Create new field Opportunity status and Lead status respectively in Opportunity and Lead.
Both pick list should contain below values: Open, In progres,Closed
When opportunity status is getting modified modify corresponding lead status also.
Assume that you can associate one lead with only one opportunity
trigger Update_status_Trigger on Opportunity (after update) {
Set<Id> oppId =new Set<Id>();
List<Lead> updList =new List<Lead>();
for(opportunity opps : Trigger.new){
if(opps.status__c!=Trigger.oldMap.get(opps.id).status__c){
oppId.add(opps.Id);
}
}
for(Lead led : ([select id,name,status__c FROM Lead WHERE oppId IN : oppId ])){
if(!Trigger.newMap.get(led.oppId).status__c.contains(led.status__c)){
updList.add(led);
}
}
try{
if(updList .size()>0){
Database.update(updList ,false);
}
}catch(Exception e){
System.debug('########'+e.getMessage());
}
}
Try with below code and do update by chaging the status of one opportunity with Deal_Lead__c look up field value .
Try to set a debug log.
I am for sure it will work .Incase any issue please send me the debug log to may mail .
manojjena202gmail.com .
Thanks
Manoj
All Answers
oppId is field on Lead ?? what is the dattype and what it contains ?
Thanks,
Sandeep
Then you should correct this query..
for(Lead led : ([select id,name,status__c FROM Lead WHERE oppId IN : oppId ])){
what you can do is, you can first collect all leadId's from opportunity as opporty is child and lead is parent
for(opportunity opps : Trigger.new){
if(opps.status__c!=Trigger.oldMap.get(opps.id).status__c){
oppId.add(opps.Id);
}
}
here insetad of collecting opportunity Id you can collect Lead Id with that lookup field...
then that set you can us ein another query to get all leads
for(Lead led : ([select id,name,status__c FROM Lead WHERE Id IN : LeadId ])){
Please check with these and let me know if it helps you..
Thanks,
Sandeep
Your code will look like this
Thanks,
Sandeep
this is also error pls solve the issuse.
trigger Update_status_Trigger on Opportunity (after update) {
Set<Id> LeadId =new Set<Id>();
List<Lead> updList =new List<Lead>();
Map<Id,Opportunity> opportunity = new Map<Id,Opportunity>();
for(opportunity opps : Trigger.new){
if(opps.status__c!=Trigger.oldMap.get(opps.id).status__c){
LeadId.add(opps.Id);
}
}
for(Lead led : ([select id,name,status__c FROM Lead WHERE Id IN : LeadId])){
if(Trigger.newMap.get(led.opportunity).status__c != led.status__c){
updList.add(led);
}
}
try{
if(updList .size()>0){
Database.update(updList ,false);
}
}catch(Exception e){
System.debug('########'+e.getMessage());
}
}
Thanks
Please check and let m eknow if you still facing any issue..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
Try with below code it will help !
Let me know if it helps .
Thanks
Manoj
I didnt notice , yes you can use above code , because in that you dont need to query because you are updating the lead..you just need to provide the correct API name ..
Please go to setup adn check the correct API name for lookup field on opportunity for lead..and give the correct API name then it will work for you..
Thanks,
Sandeep
Please modify the code accordingly it wil help .
I have addes few language in code you need to modify accordingly it will help !
Thanks
Manoj
I was changed save the code but didn't get the out put.
trigger Update_status_Trigger on Opportunity (after update) {
List<Lead> leadListToupdate =new List<Lead>();
for(opportunity opps : Trigger.new){
if(opps.status__c!=Trigger.oldMap.get(opps.id).status__c){
Lead led=new Lead(id=opps.Deal_Lead__c(look up field),status__c=opps.status__c);
leadListToupdate.add(led);
}
}
try{
if(leadListToupdate.size()>0){
Database.update(leadListToupdate,false);
}
}Catch(DmlException de){
System.debug(de);
}
}
Try with below code and do update by chaging the status of one opportunity with Deal_Lead__c look up field value .
Try to set a debug log.
I am for sure it will work .Incase any issue please send me the debug log to may mail .
manojjena202gmail.com .
Thanks
Manoj
I got it o/p.
thank you very munch......