You need to sign in to do that
Don't have an account?

Apex Trigger on new web to cases
We are using the web to case feature and are able to populate P21_Customer_ID (custom field, this is the customer number in our ERP system). However we are not able to populate the account name on the case which assings the case to the account in sales force. This is my first time wrtting a trigger in Apex. This is what I came up with so far.
Basically I want to take the P21_Customer_ID entered on the case, look up the account name from the account table and add it to the case.
trigger populate_customer_name on Case (after insert) {
Case TheCase = trigger.new[0];
if(TheCase.P21_Customer_ID != null) {
Account theAccount = [Select Name from Account
where Account.P21_CompanyCustomer_ID__c = TheCase.P21_Customer_ID];
TheCase.AccountId = theAccount.Name;
update TheCase;
}
}
Thank you,
Basically I want to take the P21_Customer_ID entered on the case, look up the account name from the account table and add it to the case.
trigger populate_customer_name on Case (after insert) {
Case TheCase = trigger.new[0];
if(TheCase.P21_Customer_ID != null) {
Account theAccount = [Select Name from Account
where Account.P21_CompanyCustomer_ID__c = TheCase.P21_Customer_ID];
TheCase.AccountId = theAccount.Name;
update TheCase;
}
}
Thank you,
Did you happen to try that?
Thank you,
https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_wf.htm&language=en_US
https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_wfrules.htm&language=en_US
Since you wish to update a field on Case - I am assuming the Acocunt field is a custom field - please aslo read the field update help link
https://help.salesforce.com/htviewhelpdoc?id=workflow_defining_field_updates.htm&siteLang=en_US