You need to sign in to do that
Don't have an account?
Bobby Steele 9
Update Text Field, IF Statement, Error: Expression cannot be a statement, Please help Super Simple
I am fairly new to writing triggers, so I took a shot at this one because I thought it would be pretty simple. I have looked a tons of example and can't seem to figure out what I am doing wrong. I would like to update base address information from a field called Metro Area when address is null. However I keep getting the error "Expression cannot be a statement at line 4 column 14".
Code is listed below:
trigger UpdateMailingAddressMetro on Contact (Before Insert, Before Update) {
for(contact c: trigger.new){
If(c.Metro_Area__c.contains('Houston') && (c.mailingcity == NULL) && (c.mailingstate == NULL) && (c.mailingpostalcode == NULL)){
(c.mailingcity == 'Houston');
(c.mailingstate == 'TX');
(c.mailingpostalcode == '77001');
(c.mailingcountry == 'United States');
}else {
c.mailingstate == NULL;
}
}
}
Code is listed below:
trigger UpdateMailingAddressMetro on Contact (Before Insert, Before Update) {
for(contact c: trigger.new){
If(c.Metro_Area__c.contains('Houston') && (c.mailingcity == NULL) && (c.mailingstate == NULL) && (c.mailingpostalcode == NULL)){
(c.mailingcity == 'Houston');
(c.mailingstate == 'TX');
(c.mailingpostalcode == '77001');
(c.mailingcountry == 'United States');
}else {
c.mailingstate == NULL;
}
}
}
==(Logical Operator) is used only when we are comparing. We should not use it when assigning a value. In this case '='(assignment operator)should be used
instead of (c.mailingcity == 'Houston'); use c.mailingcity = 'Houston';
Try the below code
Thanks & Regards,
Bhanu Mahesh Gadi
Awesome! It worked. Thank you very much!
Best Regards,
Bobby