You need to sign in to do that
Don't have an account?
Trigger to update field in two unrelated objects
On a lead record , I have created custom button (ASSIGN) which creates new record in different object ( Partner Id) . There is auto generated field in partner ID object calle NAME (standard field) . I want as soon as user clicks on ASSIGN and new record is created , it should copy that NAME value in XL_Partner_Id__c on lead object.. I am not sure if this functionality can be achieved bu writing javascript custom button . Therefore , I am trying with trigger. it is giving me error :
Variable does not exist: partid.Name
trigger updateelitepartnerid on Partner_Id__c (before insert, before update){
List<ID> LeadIds = New List<ID>();
for(Partner_Id__c partid : Trigger.new){
if(partid.Name != null){
LeadIds.add(partid.Lead);
}
}
List<Lead> leadlist = [SELECT id, XL_Partner_Id__c FROM Lead WHERE id in :LeadIds];
for(integer i = 0 ; i < leadlist.size(); i++){
leadlist[i].XL_Partner_Id__c= partid.Name ;
}
update leadlist;
}
try this.
this is the error I am getting:
Invalid field Lead for SObject Partner_Id__c at line 9 column 25
Replace it with LeadId or Lead__c what ever the API is.
hey ,
Lead is standard object . I cannot append __c or Id. Even If I append , it is giviving me the same error.
Look for the API name of the lead field on the Partner_Id__c object. and replace it with it.
so if Lead_API_Name is the API Name of Lead field on the Partner_Id__c object then it should be like...
I think , I am not able to depict the the problem clearly. But , there is no field called "lead " on the object "Partner_Id"
then how are you trying to bring the Lead Ids from the Partner_Id__c records?
Hi ,
Thats one problems , I am facing in this scenario . Since , these two objects are not related to each other. I don't have any idea how to achieve this functionality . Is there anyway to achieve this ? I just want when user clicks the SSIGN button lead record it should create a new record in Partner_Id object. When the new record is created , the auto generated number should be copied to Tx_Partner_Id field.
Hi Naidu ,
I have created a lookuop field on Lead called Partner_Gen_Id__c to object Partner_Id__c . I was wondering if the value in the Partner ID field ( API name : Name) on Partner_Id__c object can populate the the same value in look up field on Lead object ?
below is your code is not showing any error but it the trigger is also not updating the value.
trigger updateelitepartnerid on Partner_Id__c (before insert)
{
List<ID> LeadIds = New List<ID>();
for(Elite_Partner_Id__c partid : Trigger.new)
{
if(partid.Name != null)
{
LeadIds.add(partid.Name);
}
}
Map<Id, Lead> leadMap = new Map<Id, Lead>([SELECT Id, Partner_Gen_Id__c FROM Lead WHERE Id IN :LeadIds]);
for(Partner_Id__c partid : Trigger.new)
{
if(partid.Name != null)
{
Lead Ld = leadMap.get(partId.Name);
Ld..Partner_Gen_Id__c= partid.Name;
leadMap.put(partId.Name, Ld);
}
}
update leadMap.values();
}
You should create the lookup field on the Partner_Id__c object instead of lead object, so you can have a lead id for the Partner_Id__c records. Then this code will work fine... but you still need to chage this part
Hey Naidu ,
I created a lookup field on Partner Id object , namely , lookup_field__c. I made all the modifications in the code. It is not giving any error, but , it is also not updating Elite_Id__c field on Lead with NAME field value on Partner_Id__C object. Below is the modified code. your help will be highly appreciated.
trigger updateelitepartnerid on Partner_Id__c (before insert)
{
List<ID> LeadIds = New List<ID>();
for(Partner_Id__c partid : Trigger.new)
{
if(partid.Name != null)
{
LeadIds.add(partid.lookup_field__c);
}
}
Map<Id, Lead> leadMap = new Map<Id, Lead>([SELECT Id, Elite_Id__c FROM Lead WHERE Id IN :LeadIds]);
for(Partner_Id__c partid : Trigger.new)
{
if(partid.Name != null)
{
Lead Ld = leadMap.get(partId.Name);
Ld.Elite_Id__c= partid.Name;
leadMap.put(partId.Name, Ld);
}
}
update leadMap.values();
}
try this.
Hi ,
It is still not updating the field.
Regards
can you provide the debug for this code?
You dont have a lead Id to this Partner_Id__c record and so it would not update any lead... is this a valid case?
But , In the lookup_field_c , I am selecting a lead. I don't know how it is showing NULL.