How are you executing the anonymous code - is it through the API, developer console, Eclipse? You need to give us some information if we are to help you.
There's too much code to go through there I'm afraid - I'd try commenting out chunks of it to see where the problems are.
If you want one-to-one help from me that will cost you a couple of thousand dollars a day - I don't mind helping in public on these boards for free, but if you want to keep it all to yourself you have to pay.
Try saving / compiling your Apex class to your org first. Then, using execute anonymous, you could construct your class and call the method or methods you wish to call. The compiling of your Apex class will help you resolve any initial errors, and then you could execute each method via execteAnonymous like below:
Public String login(String username, String password) {
Blob md5PasswordBlob = Crypto.generateDigest('md5',Blob.valueOf(password));
String md5PasswordString = EncodingUtil.convertToHex(md5PasswordBlob);
HttpRequest Req = New HttpRequest();
Req.SetHeader('Content-Type','application/x-www-form-urlencoded');
String url = 'http://sugarcrm.jeevantechnologies.net/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON&rest_data={"user_auth":{"version":"1","password":"'+md5PasswordString+'","user_name":"'+username+'"},"application_name":"RESTAPI","name_value_list":"[]"}';
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('user_auth');
gen.writeStartObject();
gen.writeStringField('version','1');
gen.writeStringField('user_name',username);
gen.writeStringField('password', md5PasswordString);
gen.writeEndObject();
gen.writeStringField('application_name','RESTAPI');
gen.writeStringField('name_value_list','[]');
gen.writeEndObject();
req.setEndpoint(url);
req.setMethod('GET');
// req.setBody(restData);
Http http = new Http();
HTTPResponse res = http.send(req);
JSONParser parser = JSON.createParser(res.getBody());
String id;
while (parser.nextToken() != null) {
parser.nextToken();
parser.nextValue();
if(parser.getCurrentName() == 'id') {
id = parser.getText();
}
}
return id;
}
public String getIndustries() {
Schema.DescribeFieldResult fieldResult = Custom_Account__c.Industry__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
String industries;
for( Schema.PicklistEntry f : ple ){
if(industries == null) {
industries = '"'+ f.getValue() +'"';
} else {
industries += ',"'+ f.getValue() +'"';
}
}
return industries;
}
public void create (String session, String moduleName) {
// String industryWhereClause = 'accounts.industry IN ('+ this.getIndustries() +')';
String url = 'http://sugarcrm.jeevantechnologies.net/service/v4_1/rest.php?method=get_entry_list&input_type=JSON&response_type=JSON&rest_data={"session":"'+session+'","module_name":"'+moduleName+'","query":"","order_by":"","offset":"0","select_fields":["id","name","website","phone_office","account_type","industry","annual_revenue","phone_fax"],"link_name_to_fields_array":[],"max_results":"","deleted":"0","Favorites":false}';
HttpRequest req = new HttpRequest();
Http h = new Http();
req.setEndpoint(url);
req.setMethod('GET');
HttpResponse res = h.send(req);
Map<String, Object> resBody = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
List<Object> entryList = (List<Object>)resBody.get('entry_list');
List<String> sugarColumns = new List<String> { 'name', 'website', 'phone_office', 'account_type', 'industry', 'annual_revenue', 'phone_fax','id'};
List<String> sfdcColumns = new List<String> { 'Name', 'Website__c', 'Office_phone__c','Type__c', 'Industry__c', 'Annual_Revenue__c', 'Fax__c','External_ID__c'};
List<Custom_Account__c> accountsList = new List<Custom_Account__c>();
for(Integer i = 0; i < entryList.size(); i++) {
Custom_Account__c account = new Custom_Account__c();
Map<String, Object> entry = (Map<String, Object>)entryList[i];
Map<String, Object> recordMap = (Map<String, Object>)entry.get('name_value_list');
for (Integer j = 0; j < sugarColumns.size(); j++) {
Map<String, Object> columnMap = (Map<String, Object>)recordMap.get(sugarColumns[j]);
if (j == 0) {
account.Name = (String) columnMap.get('value');
} else if (j == 1) {
account.Website__c = (String) columnMap.get('value');
} else if (j == 2) {
account.Office_phone__c = (String) columnMap.get('value');
} else if (j == 3) {
account.Account_Type__c = (String) columnMap.get('value');
} else if (j == 4) {
account.Industry__c = (String) columnMap.get('value');
} else if (j == 5) {
account.Annual_Revenue__c = (String) columnMap.get('value');
} else if (j == 6) {
account.Fax__c = (String) columnMap.get('value');
}
else if (j == 7) {
account.External_id__c = (String) columnMap.get('value');
}
else {
}
}
account.From_External_System__c = true;
try {
insert account;
} catch (Exception e) {
System.debug(entry.get('id'));
}
}
//insert accountsList;
}
public void createcontact (String session, String moduleName) {
String url = 'http://sugarcrm.jeevantechnologies.net/service/v4_1/rest.php?method=get_entry_list&input_type=JSON&response_type=JSON&rest_data={"session":"'+session+'","module_name":"'+moduleName+'","query":"","order_by":"","offset":"0","select_fields":["id","name","Last Name","Title","Account Name","Mobile Phone","Office Phone","Fax"],"link_name_to_fields_array":[],"max_results":"","deleted":"0","Favorites":false}';
HttpRequest req = new HttpRequest();
Http h = new Http();
req.setEndpoint(url);
req.setMethod('GET');
HttpResponse res = h.send(req);
Map<String, Object> resBody = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
List<Object> entryListcon = (List<Object>)resBody.get('entry_list');
List<String> sugarColumnscon = new List<String> { 'name', 'Last Name', 'Title', 'account_type', 'Mobile Phone', 'Office Phone', 'Fax','id'};
List<String> sfdcColumnscon = new List<String> { 'Name', 'Last_Name__c', 'Title__c','Account_Name__c', 'Mobile_Phone__c', 'Office_Phone__c', 'Fax__c','External_id__c'};
List<Custom_contact__c> contactlist = new List<Custom_contact__c>();
for(Integer i = 0; i < entrylistcon.size(); i++) {
Custom_contact__c contact = new Custom_contact__c();
Map<String, Object> entrylist = (Map<String, Object>)entryListcon[i];
Map<String, Object> recordMap = (Map<String, Object>)entrylist.get('name_value_list');
for (Integer j = 0; j < sugarColumnscon.size(); j++) {
Map<String, Object> columnMap = (Map<String, Object>)recordMap.get(sugarColumnscon[j]);
if (j == 0) {
contact.Name = (String) columnMap.get('value');
} else if (j == 1) {
contact.Last_Name__c = (String) columnMap.get('value');
} else if (j == 2) {
contact.Title__c = (String) columnMap.get('value');
} else if (j == 3) {
contact.Account_Name__c = (String) columnMap.get('value');
} else if (j == 4) {
contact.Mobile_Phone__c = (String) columnMap.get('value');
} else if (j == 5) {
contact.Office_Phone__c = (String) columnMap.get('value');
} else if (j == 6) {
contact.Fax__c = (String) columnMap.get('value');
} else if ( j == 7) {
contact.External_Id__c = (String) columnMap.get('value');
List<Custom_Account__c> externalAccount = [SELECT Id FROM Custom_Account__C WHERE External_Id__c = :contact.External_ID__c];
if(!externalAccount.isEmpty()) {
// contact.Account__c = (String) externalAccount[0].get('id');
}
}
else {
}
}
try {
insert contact;
} catch (Exception e) {
System.debug(entrylist.get('id'));
}
}
}
}
If you want one-to-one help from me that will cost you a couple of thousand dollars a day - I don't mind helping in public on these boards for free, but if you want to keep it all to yourself you have to pay.
saihareesh,
Then you should be able to check the debug logs for any further errors or exceptions that are encountered.Try saving / compiling your Apex class to your org first. Then, using execute anonymous, you could construct your class and call the method or methods you wish to call. The compiling of your Apex class will help you resolve any initial errors, and then you could execute each method via execteAnonymous like below:
Description__c = 'Invoice 1');
insert inv;
In this first line anonymous error executes.
Please resolve this