You need to sign in to do that
Don't have an account?
Help with a basic Trigger
Hi people, I'm a Salesforce admin without code knowledge but I have to make a Trigger that I think is really basic, but I still can't do it.
I need to have a mirror Record Type text field that has to be filled before the matching rules are executed. With Process Builder I can't do that so I need a Trigger.
I wrote this with some videos that I watched, please don't laugh at me haha:
trigger RecordType on Account (before insert) {
for(Account a: Trigger.New) {
if(a.RecordTypeId = "012150000013uJx") {a.RecordType__c = 'Advertiser';}
if(a.RecordTypeId = "012150000013uJs") {a.RecordType__c = 'Agencia';}
if(a.RecordTypeId != "012150000013uJs" && a.RecordTypeId != "012150000013uJx" ) {a.RecordType__c = ' ';}
}
I'm recieving the following error message: Error de compilación: Unrecognized symbol '"', which is not a valid Apex identifier. en la línea 3 columna 25
Please use the == in if conditions like belowbelow will solve your error.
trigger RecordType on Account (before insert) {
for(Account a: Trigger.New) {
if(a.RecordTypeId == "012150000013uJx") {
a.RecordType__c = 'Advertiser';
}
if(a.RecordTypeId == "012150000013uJs")
{a.RecordType__c = 'Agencia';
}
if(a.RecordTypeId != "012150000013uJs" && a.RecordTypeId != "012150000013uJx" ) {a.RecordType__c = ' ';} }
}
Thanks,
Maharajan.C
Don't use the ID's directly in code. Simply don't hard code the ids
You can use schema to get the record type I'd by using the record type developer name.
Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Record Type Name').getRecordTypeId();
use the above value in code to comparsion like below.
if(a.RecordTypeId == recordTypeId)
{
}
http://smukov.github.io/blog/2018/06/09/Record-Type-Id-By-Developer-Name/
Unrecognized symbol '"', which is not a valid Apex identifier. en la línea 3 columna 32
use this code as it is