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

(simple ?) range problem. error: Variable does not exist
Hello,
I have a range problem with one of my variables :
I have a range problem with one of my variables :
String MCLU1 = 'BK2200 0015 -- 41'; if (MCLU1 != null || MCLU1 != '') { String bk = null; String bk_full = null; String bk_extension = '--'; String [] bkAfterSplit = null; bk_full = MCLU1; if (bk_full.contains(bk_extension)) { bkAfterSplit = bk_full.split(' -- '); bk = bkAfterSplit[0]; System.debug(LoggingLevel.DEBUG, 'bk inside my if : ' + bk); } else { bk = bk_full; System.debug(LoggingLevel.DEBUG, 'bk inside my else : ' + bk); } } else { System.debug(LoggingLevel.DEBUG, 'MCLU1__c is empty'); } String external_id = 'FRA-BLIP-' + bk; System.debug(LoggingLevel.DEBUG, 'bk outside my if/else : ' + bk); System.debug(LoggingLevel.DEBUG, 'external_id : ' + external_id);line 22, I need to get my bk variable but i get a Variable does not exist: bk. And I don't seem to understand why. I try almost the same code in eclipse and it worked :
public class BkDoesNotExist { public static void main(String[] args) { String MCLU1__c = "BK2200 0015 -- 41"; String bk = null; String bk_full = null; String bk_extension = "--"; String [] bkAfterSplit = null; if (MCLU1__c != null || MCLU1__c != "") { // variables nécessaires pour split mon BK proprement bk_full = MCLU1__c; if (bk_full.contains(bk_extension)) { bkAfterSplit = bk_full.split(" -- "); bk = bkAfterSplit[0]; System.out.println("bk inside my if : " + bk); } else { bk = bk_full; } } else { System.out.println("MCLU1__c is empty"); } String external_id = "FRA-BLIP-"+bk; System.out.println("bk outside my if : " + bk); System.out.println("external_id : " + external_id); } }result in console :
bk inside my if : BK2200 0015 bk outside my if : BK2200 0015 external_id : FRA-BLIP-BK2200 0015Any idea on what I am missing here ?
If you could declare the variable String bk = null; outside the if statement below String MCLU1 = 'BK2200 0015 -- 41';
for example your code would look something like below
String MCLU1 = 'BK2200 0015 -- 41';
String bk = null;
String bk_full = null;
String bk_extension = '--';
String [] bkAfterSplit = null;
if (MCLU1 != null || MCLU1 != '') {
bk_full = MCLU1;
if (bk_full.contains(bk_extension)) {
bkAfterSplit = bk_full.split(' -- ');
bk = bkAfterSplit[0];
System.debug(LoggingLevel.DEBUG, 'bk inside my if : ' + bk);
} else {
bk = bk_full;
System.debug(LoggingLevel.DEBUG, 'bk inside my else : ' + bk);
}
} else {
System.debug(LoggingLevel.DEBUG, 'MCLU1__c is empty');
}
String external_id = 'FRA-BLIP-' + bk;
System.debug(LoggingLevel.DEBUG, 'bk outside my if/else : ' + bk);
System.debug(LoggingLevel.DEBUG, 'external_id : ' + external_id)
This should work..
Hope this helps !!!
Thank you !