You need to sign in to do that
Don't have an account?
bellardina
trigger on standard object in order to update a field on custom object
There are 3 objects- Account(std object),oppurtunity(std object),Application(custom object).Oppurtunity and application are linked via master detail relationship.I I have created 2 record types for account. I need to write a trigger on account so that when account record type is set to a specific value and client id(text field on account) is not null then status(picklist field on application )is automatically updated to a specific value.
FYI: this code places SOQL inside for loops and is not bulk safe. There are other issues as well: If no application exists, you will get an attempt to dereference a nul object. You need to know the exact recordtypeID instead of looking it up,
All Answers
try this code!
if(!Trigger.isInsert) {
for(Account ac: Trigger.new) {
if(ac.Recortypeid == <some record type id> && ac.clientid__c != null) {
Application__c ap = [select id, status__c from application__c where account__c =: ac.Id])
ap.status__c = <some status>;
update ap;
}
}
}
you can add extra spices to this code...
let me know if this helps you!! i would be happy if this works for you!!
baskaran
It is throwing an error:-' there is no column called account__c on entity application__c'. Account and application are not directly linked to each other.Account(std object) is related to oppurtunity(std object) by lookup relationship.Oppurtunity is linked to application(custom object) by master-detail relationship.Please help
my bad!
try this now..
if(!Trigger.isInsert) {
for(Account ac: Trigger.new) {
if(ac.Recortypeid == <some record type id> && ac.clientid__c != null) {
Opportunity op = [select id from Opportunity where AccountId =: ac.Id];
if(op != null) {
Application__c ap = [select id, status__c from application__c where OppID__c =: op.Id])
ap.status__c = <some status>;
update ap;
}
}
if you still have issues post your code here!
try this: Please note that this will update ALL application__c object for the given opportunity. If you only want to update a specific application for an Opportunity for a specific account, you will need to provide that criteria and add that to the loop as a filter when updating the Application__c object records....
FYI: this code places SOQL inside for loops and is not bulk safe. There are other issues as well: If no application exists, you will get an attempt to dereference a nul object. You need to know the exact recordtypeID instead of looking it up,
Thanks for pin pointing the issues in my code. i really appreciate!! can you tell how much batch size a trigger can handle if you say it is bulk safe?
- baskaran
In order to be "Bulkified" the trigger must be able to handle ANY amount of records thrown at it. With that said, a trigger runs in maximum batches of 200 records per batch.
thanks a lot!
You should collate the data outside of the for loop, using collection data types, then use those within the for loop so you are not possibly hitting governor limits.