Getting issues while using SoftwareSerial
SoftwareSerial only works on a few select GPIO pins on the Mega. Specifically those pins that have PCINT on them.

But that is irrelevant. There is no reason to use SoftwareSerial on a Mega except in exceptional circumstances.  You have four hardware UARTs on the Mega, so there is no call to use SoftwareSerial.  Use the real UART pins and objects:

Serial -&gt; RX(0) / TX(1)
Serial1 -&gt; RX1(19) / TX1(18)
Serial2 -&gt; RX2(17) / TX2(16)
Serial3 -&gt; RX3(15) / TX3(14)


Just replace all references in your code to the SoftwareSerial instance with Serial1 (delete the #include and the object instance constructor) and use TX1 and RX1 to connect your module:

String data="true";

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    Serial1.begin(9600);
}

void loop() {
    // put your main code here, to run repeatedly:
    if(Serial1.available()){
        data=Serial1.readString();
    }
    Serial.println(data);
    //Serial.write(data);
    delay(2000);
}