You need to sign in to do that
Don't have an account?
bhanu_prakash
update lookup field with help of another
Hi,
Iam trying to update field on oppournity, where recordid(lookup) is equal to 00528000001KyAT, need to update account id(lookup ) as 0012800000lIenH.
I have written a trigger
trigger updateif on Opportunity (before insert,before update) {
if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
list<string> lstStr = new list<string>();
for(opportunity opp : trigger.new){
if(opp.record_id__c = '00528000001KyAT'){
opp.update__c = '0012800000lIenH';
}
}
}
}
Help me to fix this
Iam trying to update field on oppournity, where recordid(lookup) is equal to 00528000001KyAT, need to update account id(lookup ) as 0012800000lIenH.
I have written a trigger
trigger updateif on Opportunity (before insert,before update) {
if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
list<string> lstStr = new list<string>();
for(opportunity opp : trigger.new){
if(opp.record_id__c = '00528000001KyAT'){
opp.update__c = '0012800000lIenH';
}
}
}
}
Help me to fix this
<pre>
trigger updateif on Opportunity ( before insert, before update )
{
if ( trigger.isBefore && (trigger.isInsert || trigger.isUpdate) )
{
User specialUser =
[ SELECT Id
FROM User
WHERE UserName = 'put.correct@username.here'
];
Account specialAccount =
[ SELECT Id
FROM Account
WHERE Name = 'Put Correct Account Name Here'
];
for ( Opportunity opp : Trigger.new )
{
if ( opp.Record_Id__c = specialUser.Id ) opp.Update__c = specialAccount.Id;
}
}
}
</pre>
All Answers
Best,
Nithesh
Actually you are not comparing value for record_id__c in your code so added equalignorecase(). Please try below code and please let me know if it works for you.
-------------------------------------------------------
trigger updateif on Opportunity(before insert, before update) {
if (trigger.isBefore && (trigger.isInsert || trigger.isUpdate)) {
list < string > lstStr = new list < string > ();
for (opportunity opp: trigger.new) {
if ((opp.record_id__c).equalsignorecase('00528000001KyAT')) {
opp.update__c = '0012800000lIenH';
}
}
}
}
--------------------------------------------
Regards,
Pawan Kumar
<pre>
trigger updateif on Opportunity ( before insert, before update )
{
if ( trigger.isBefore && (trigger.isInsert || trigger.isUpdate) )
{
User specialUser =
[ SELECT Id
FROM User
WHERE UserName = 'put.correct@username.here'
];
Account specialAccount =
[ SELECT Id
FROM Account
WHERE Name = 'Put Correct Account Name Here'
];
for ( Opportunity opp : Trigger.new )
{
if ( opp.Record_Id__c = specialUser.Id ) opp.Update__c = specialAccount.Id;
}
}
}
</pre>
<pre>
if ( opp.Record_Id__c == specialUser.Id ) opp.Update__c = specialAccount.Id;
</pre>