You need to sign in to do that
Don't have an account?
furamag
Trigger to Update custom field
I have two custom objects (SFDC_Employee__c Promotion__c). I need to update field Unit__c (text) in object SFDC_Employee__c when sombody add or change field Unit__c (Picklist) in object Promotions__c.
I made trigger in object Promotions__c with this code:
But this trigger doesn't work. Can you please explane what is the better way to fix my problem.
I made trigger in object Promotions__c with this code:
Code:
trigger Unit_update on Promotions__c (after insert, after update) { sObject s = [SELECT Unit__c FROM SFDC_Employee__c LIMIT 1]; s.Unit__c = 'sdfsfsdf'; update s; }
But this trigger doesn't work. Can you please explane what is the better way to fix my problem.
-David
Here is more on queries and select:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL.htm
http://www.salesforce.com/us/developer/docs/api/index_CSH.htm#sforce_api_calls_soql.htm
// Standard functionality is that mailing address is copied from Billing Address
// but that might not be filled.
// to a set so there are no duplicates.
Set<Id> accIds = new Set<Id>();
accIds.add(co.AccountId);
}
// in a map.
Map<Id, Account> accentries = new Map<Id, Account>(
[select PrimaryCity__c, PrimaryCountry__c, PrimaryState__c, PrimaryStreet__c, PrimaryPostalCode__c from Account
where id in :accIds]);
if (co.AccountId != null) {
if (co.MailingCity == null) {
co.MailingCity = accentries.get(co.AccountId).PrimaryCity__c;
co.MailingCountry = accentries.get(co.AccountId).PrimaryCountry__c;
co.MailingState = accentries.get(co.AccountId).PrimaryState__c;
co.MailingStreet = accentries.get(co.AccountId).PrimaryStreet__c;
co.MailingPostalCode = accentries.get(co.AccountId).PrimaryPostalCode__c;
}
}
}
// If the OLS flag is set on a contact, set the flag on the Account
Set<Id> accOlsIds = new Set<Id>();
{
if (co.OLSUser__c == true)
{
accOlsIds.add(co.AccountId);
}
}
// Create list of Accounts to update
List<Account> updAccount = new List<Account>();
for (Account ac : [select id, OLSUser__c from Account where
OLSUser__c = false and id in :accOlsIds])
{
ac.OLSUser__c = true;
updAccount.add(ac);
}
//update
update updAccount;
}
you should use the following instead of the above
otherwise you can access only the ID field
Message Edited by arnt72 on 10-15-2008 04:26 PM
I have another problem with this trigger.
SFDC_Employee__c - custom object. Promotions__c have field Employee__c (lookup to SFDC_Employee__c).
To update SFDC_Employee__c.Unit__c I use this code:
I don't now why, but str contain "a0I70000001pvU9EAI", it's wrong value. My id must contain "a0I70000001pvU9" (same value but without last 3 symbols). Why I have this problem?
Message Edited by furamag on 10-16-2008 03:46 PM
does this query return anything?
Message Edited by arnt72 on 10-17-2008 10:54 AM