You need to sign in to do that
Don't have an account?
Jaanu
Creating apex class reading json static resource file
1. I have created a Json file and uploaded into static resources in salesfoce. The file name is "xyz"
2. Converted the json file to apex class using - http://json2apex.herokuapp.com/.
3. I have the below structure of the class ... can someone validate this please ? it's not working for some reason .. pls give me the correct code.
basically 3 separate classes or ... do I need to nest these classes in the main class ? can you pls suggest on the structure of these classes.
global class preparemysandbox implements SandboxPostCopy {
global void runApexClass(SanboxContext context) {
Here I need to update the custom setting fields with the values from Json text files saved as static resource.
e.g url (custom setting field) = (Here I need to assign value from static resource value)
}
}
Public class JSON2Apex {
Converted the json file to apex class using - http://json2apex.herokuapp.com/. I have all that here in this class.
}
Public static JSON2Apex parse(string cd) {
StaticResource sr = [select id, body from StaticResource where name = 'xyz'; - I am getting error on Select, id and name on this line of code.
cd = sr.ody.toString();
return (JSON2Apex) System.JSON.deserialize(cd, JSON2Apex.class)
}
2. Converted the json file to apex class using - http://json2apex.herokuapp.com/.
3. I have the below structure of the class ... can someone validate this please ? it's not working for some reason .. pls give me the correct code.
basically 3 separate classes or ... do I need to nest these classes in the main class ? can you pls suggest on the structure of these classes.
global class preparemysandbox implements SandboxPostCopy {
global void runApexClass(SanboxContext context) {
Here I need to update the custom setting fields with the values from Json text files saved as static resource.
e.g url (custom setting field) = (Here I need to assign value from static resource value)
}
}
Public class JSON2Apex {
Converted the json file to apex class using - http://json2apex.herokuapp.com/. I have all that here in this class.
}
Public static JSON2Apex parse(string cd) {
StaticResource sr = [select id, body from StaticResource where name = 'xyz'; - I am getting error on Select, id and name on this line of code.
cd = sr.ody.toString();
return (JSON2Apex) System.JSON.deserialize(cd, JSON2Apex.class)
}
Hi jaanu , when using covertor to covert the json to wrapper class. Please ensure the type of variables are correct . Some times this connectors put variables and unecessary line of code in between
global class PrepareMySandbox implements SandboxPostCopy {
global void runApexClass(SandboxContext context) {
System.debug('Org ID: ' + context.organizationId());
System.debug('Sandbox ID: ' + context.sandboxId());
System.debug('Sandbox Name: ' + context.sandboxName());
run();
}
public class JSON2Apex {
public class APIUrls__c {
public String Provider_Base_URL__c;
public String Banking_Base_URL__c;
public String PlatformOrganizationId__c;
}
public class CustomLabel {
public String URL_ePA_Endpoint__c;
public String URL_ePA_iFrame_Endpoint__c;
}
public Dev dev;
public Dev test;
public Dev uat;
public class Dev {
public CustomSetting CustomSetting;
public CustomLabel CustomLabel;
public RemoteSiteSettings RemoteSiteSettings;
}
public class API_token_URL__c {
public String client_secret__c;
public String outbound_end_point_url__c;
public String token_url__c;
}
public class RemoteSiteSettings {
}
public class CustomSetting {
public API_token_URL__c API_token_URL__c;
public APIUrls__c APIUrls__c;
}
public static JSON2Apex parse(String cd) {
StaticResource sr= [SELECT Id, body from StaticResource WHERE Name = 'XYZ'];
cd = sr.body.toString();
return (JSON2Apex) System.JSON.deserialize(cd, JSON2Apex.class);
}
}
global static void run() {
}
}