+ Start a Discussion
Neil Hatch 9Neil Hatch 9 

replace string in Apex Class

I've inherited an app that has very little apex code. However, the one bit of reusable code we have now needs modifying and I'm struggling to make the right change.  This line is now causing an issue as a number of new fields are already reference fields and results in the class failing and stopping the process that runs it! Is there a simple change to this line that will replace any __[rc] with __r? This will capture those that need changing "c" and those that are actually already correct "r"?  
activeFieldName = userFieldName.replace('__c', '__r.IsActive');

Nayana KNayana K
activeFieldName = userFieldName;
activeFieldName = activeFieldName.replace('__c', '__r');
activeFieldName = activeFieldName.replace('__r, '__r.IsActive');

Please try this.