-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
0Questions
-
4Replies
System.LimitException: Too many SOQL queries: 101 for triggers
When I run the test class for the one trigger ,the system throws an as :
The Trigger which im running :
System.LimitException: Too many SOQL queries: 101 Trigger.MergeLeadTrigger: line 276, column 1 Trigger.Accountduplicate: line 6, column 1
The Trigger which im running :
trigger CampaignMemberSyncStatus on CampaignMember (after update) { // Sync response status on Campaign Member to lead or contact // Look for status changes List<Id> relatedIDs = new List<ID>(); List<Id> modifiedIDs = new List<ID>(); // Get the list of IDs for campaignmembers whose status changed for(CampaignMember cm : Trigger.new) { if(cm.Response_Status__c != trigger.oldMap.get(cm.Id).Response_Status__c) { modifiedIDs.add(cm.Id); if(cm.ContactId != null) { relatedIDs.add(cm.ContactId); } else { relatedIDs.add(cm.LeadId); } } } if(modifiedIds.size() == 0) return; /// No modified responses // Now pull the list of related leads and contacts Map<id,Lead> RelatedLeads; Map<id,Contact> RelatedContacts; RelatedLeads = new Map<ID,Lead>([Select id, Disqaulified_Reason__c, Status from Lead where Id in :relatedIDs]); RelatedContacts = new Map<ID,Contact>( [Select id, Status__c, Lead_Score__c, Campaign_Score__c, Account.Customer_Status__c, Admin_Nurture_Timeout__c from Contact where Id in :relatedIDs]); // Build lists of leads or contacts to update Map<ID,Lead> ModifiedLeads = new Map<ID,Lead>(); Map<ID,Contact> ModifiedContacts = new Map<ID,Contact>(); Map<String, CMStatusSettings__c> statusmapping = CMStatusSettings__c.getall(); // Now update the stautus for(id cmid : modifiedIDs) { CampaignMember cm = trigger.newMap.get(cmid); Boolean wasupdated; if(cm.ContactId != null) { wasupdated = CampaignMemberFunctions.SyncStatus(cm, null, RelatedContacts.get(cm.ContactId), statusmapping); if(wasupdated) ModifiedContacts.put(cm.ContactID,RelatedContacts.get(cm.ContactId)); } else { wasupdated = CampaignMemberFunctions.SyncStatus(cm, RelatedLeads.get(cm.LeadId), null, statusmapping); if(wasupdated) ModifiedLeads.put(cm.LeadId,RelatedLeads.get(cm.LeadId)); } } if(ModifiedLeads.size()>0) update ModifiedLeads.values(); if(ModifiedContacts.size()>0) update ModifiedContacts.values(); }Test Class :
@isTest public class TestCampaignMemberSync { static testMethod void TestStatusUpdates() { Account genericaccount = new Account(Name = 'someaccount'); insert genericaccount; Lead ld1 = new Lead(Company='colead1',LastName='colead1'); Lead ld2 = new Lead(Company='colead2',LastName='colead2'); Contact ct1 = new Contact(LastName='cocontact1', AccountID = genericaccount.Id); Contact ct2 = new Contact(LastName='cocontact2', AccountID = genericaccount.Id); Campaign cam = new Campaign(Name='campname'); insert cam; insert ld1; insert ld2; insert ct1; insert ct2; CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id, LeadId=ld1.Id, Buyer__c='a', user__c='b'); CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id, Buyer__c='a', user__c='b'); CampaignMember mc3 = new CampaignMember(CampaignId = cam.Id, ContactId=ct1.Id, Buyer__c='a', user__c='b'); CampaignMember mc4 = new CampaignMember(CampaignId = cam.Id, ContactId=ct2.Id, Buyer__c='a', user__c='b'); List<CampaignMember> cms = new List<CampaignMember>(); cms.add(mc1);cms.add(mc2);cms.add(mc3);cms.add(mc4); insert cms; List<Id> cmids = new List<id>(); for(CampaignMember thiscm: cms) { cmids.add(thiscm.id); } ld1.admin_CMSourceId__c = mc1.id; update ld1; // Needed later to simulate the button click on conversion ld2.admin_CMSourceId__c = mc2.id; update ld2; // Needed later to simulate the button click on conversion // Initialize the opp for later creation from CampaignMember Opportunity Opp = new Opportunity(CloseDate = Date.Today().addDays(30), AccountId = genericaccount.Id, Name='someopp', StageName='Selected' ); Test.StartTest(); mc1.Response_Status__c = 'Working'; mc2.Response_Status__c = 'Disqualified'; mc2.Disqualified_Reason__c = 'no budget'; mc3.Response_Status__c = 'Working'; mc4.Response_Status__c = 'Disqualified'; mc4.Disqualified_Reason__c = 'no budget'; mc4.Do_not_reassign_to_Landings__c = true; update cms; Test.StopTest(); List<CampaignMember> mcres = [Select Id, Response_Status__c, Contact.Admin_Nurture_Timeout__c , Contact.Status__c, Lead.Status, Do_not_reassign_to_Landings__c from CampaignMember where Id = :cmids ]; for(CampaignMember cm: mcres) { System.debug('Response ' + cm.Response_Status__c + ' lead status:' + cm.Lead.Status + ' contact status:' + cm.Contact.Status__c ); System.debug('Nurture date:' + mcres[3].Contact.Admin_Nurture_Timeout__c); } //System.assertEquals(mcres[3].Do_not_reassign_to_Landings__c, mcres[3].Contact.Do_not_reassign_to_Landings__c); } static testMethod void TestConversionsNoOpp() { Account genericaccount = new Account(Name = 'someaccount'); insert genericaccount; Lead ld1 = new Lead(Company='colead1',LastName='colead1'); Lead ld2 = new Lead(Company='colead2',LastName='colead2'); ld2.OwnerId = UserInfo.getUserId(); Campaign cam = new Campaign(Name='campname'); insert cam; insert ld1; insert ld2; CampaignMember mc1 = new CampaignMember(CampaignId = cam.Id, LeadId=ld1.Id, Buyer__c='a', user__c='b'); CampaignMember mc2 = new CampaignMember(CampaignId = cam.Id, LeadId=ld2.Id, Buyer__c='a', user__c='b'); List<CampaignMember> cms = new List<CampaignMember>(); cms.add(mc1); cms.add(mc2); insert cms; List<Id> cmids = new List<id>(); ld1.admin_CMSourceId__c = mc1.id; update ld1; // Needed later to simulate the button click on conversion ld2.admin_CMSourceId__c = mc2.id; update ld2; // Needed later to simulate the button click on conversion // Initialize the opp for later creation from CampaignMember Opportunity Opp = new Opportunity(CloseDate = Date.Today().addDays(30), AccountId = genericaccount.Id, Name='someopp', StageName='Selected' ); mc1.Response_Status__c = 'Working'; mc2.Response_Status__c = 'Disqualified'; mc2.Disqualified_Reason__c = 'no budget'; update cms; // We're checking CampaignMemberOpportunityInsertTrigger here Opp.admin_CMSourceId__c = mc2.Id; // Set the source ID insert Opp; Test.StartTest(); // Now let's do a lead convert Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(ld2.Id); lc.setConvertedStatus('Converted - Existing Opportunity'); lc.setDoNotCreateOpportunity(true); lc.setOwnerId(UserInfo.getUserId()); Database.LeadConvertResult lcr2 = Database.convertLead(lc); Test.StopTest(); try { } catch(Exception ex) { System.Debug('Exception during TestConversionsNoOpp StopTest (async error)' + ex.getMessage()); } System.assert(lcr2.isSuccess()); CampaignMember mc2b = [Select Id,Response_Status__c, Opportunity_Create_Date__c, Opportunity_Name__c, Buyer__c, User__c from CampaignMember where Id = :mc2.id]; Lead convertedleadinfo = [Select Id, isConverted, Status from Lead where id = :ld2.Id]; System.Debug('original leadid:' + ld2.Id + ' leadid result id:' + lcr2.getLeadId()); System.Debug('Converted lead isconverted:' + convertedleadinfo.IsConverted + ' status:' + convertedleadinfo.Status); system.assertEquals('Converted - Existing Opportunity', mc2b.Response_Status__c); } }The Error Lines Of other Triggers are
Error line for MergeLead Trigger : conrecords=[select id , Rep_Managing_Partner_del__c from Contact where id in: getconid1 and Rep_Managing_Partner_del__c !=null]; Error line for AccountDuplicateTrigger : lstusr =[SELECT Id,Name,Profile.Name FROM User WHERE Id=:UserInfo.getuserId()];Any help very much appreciated.
- SalesforceCrm AccountCRM
- March 28, 2016
- Like
- 0
Deserialization of JSON
Gurus,
I am having issues trying to parse JSON returned from the HTTP response.
Below is my APEX code:
HTTP response:
I converted Json to Apex and following classes were generated:
I am not sure what I am doing wrong, in the parsing and deserialization.
Regards,
Gaurav
I am having issues trying to parse JSON returned from the HTTP response.
Below is my APEX code:
public class JiraGetIssue { public String baseUrl = 'https://beta.pelco.com:8443/tasks/rest/api/latest/issue/SUSTAIN-4050'; // Base URL of your JIRA instance //public String baseUrl = 'https://beta.pelco.com:8443/tasks/rest/api/latest/issue/'; public String username = 'salesforce.connector'; // JIRA username public String password = 'password'; // JIRA password // Constructs Basic Http Authentication header from provided credentials public String authHeader() { Blob headerValue = Blob.valueOf(username+':'+password); return 'Basic ' + EncodingUtil.base64Encode(headerValue); } public void Execute() { Http http = new Http(); HttpRequest request = new HttpRequest(); string fields = 'key,'+ 'assignee,'+ 'project,'+ 'summary,'+ 'created,'+ 'updated,'+ 'priority,'+ 'status'; system.debug(fields); integer startAt = 0; integer maxResults= 10; string searchString='SUSTAIN'; //String CreateIssueJsonJIra= '{"fields": {"summary":"test create jira1","description":"test create jira1" ,"issuetype":{"name": "Bug"}}} '; //String CreateIssueJsonJIra= '{"fields": { "project":{ "key": "SUSTAIN"},"summary": "REST ye merry gentlemen2","description": "Creating of an issue using project keys and issue type names using the REST API2","issuetype": {"name": "Bug"}}}'; request.setMethod('GET'); //Set HTTPRequest header properties request.setHeader('Accept', 'application/json'); request.setHeader('Content-Type','application/json'); Blob headerValue = Blob.valueOf(username+':'+password); request.setHeader('Authorization','Basic '+ EncodingUtil.base64Encode(headerValue)); baseUrl='https://beta.pelco.com:8443/tasks/rest/api/latest/search?jql=summary~"gentlemen*"&project=SUSTAIN&fields=key,summary,status,priority,status,created,updated,assignee'; //baseUrl=baseUrl+searchString+'"'; //baseUrl=baseUrl+ '&fields=' + fields + '&startAt='+ startAt +'&maxResults='+maxResults; system.debug(baseUrl); request.setEndpoint(baseUrl); HttpResponse response = http.send(request); // Log the JSON content System.debug('JSON Response: ' + response.getBody()); string JSONContent = response.getBody(); system.debug(jiraGetIssueResponse.parse(JSONContent)); JSONParser parserJira = JSON.createParser(JSONContent); //system.debug('parserJira ='+parserJira); while (parserJira.nextToken() != null) { // Start at the array of issues. if(parserJira.getCurrentToken() == JSONToken.START_ARRAY) { while (parserJira.nextToken() != null) { if ((parserJira.getCurrentToken() == JSONToken.START_OBJECT)) { //JiraGetIssueResponse jiraIssue = (JiraGetIssueResponse)parserJira.readValueAs(JiraGetIssueResponse.class); //system.debug(jiraIssue); system.debug('Current TOKEN:'+parserJira.getCurrentToken()); system.debug('Current TEXT:'+parserJira.getText()); //parserJira.nextToken(); //system.debug('**************'); } } system.debug('**************'); //system.debug('Current TOKEN:'+parserJira.getCurrentToken()); //system.debug('Current TEXT:'+parserJira.getText()); } } //system.debug('JiraId='+jiraId+' JiraKey='+jirakey); } }
HTTP response:
09:24:00:084 USER_DEBUG [43]|DEBUG|JSON Response: {"expand":"schema,names","startAt":0,"maxResults":50,"total":4,"issues":[{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176072","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176072","key":"TEST-3","fields":{"summary":"REST ye merry gentlemen2","created":"2016-03-03T11:38:40.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-03T11:38:40.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}},{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176071","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176071","key":"TEST-2","fields":{"summary":"REST ye merry gentlemen.","created":"2016-03-02T16:15:49.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-02T16:15:49.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}},{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176073","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176073","key":"SUSTAIN-4052","fields":{"summary":"REST ye merry gentlemen2","created":"2016-03-03T13:01:31.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-03T13:01:31.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}},{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176074","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176074","key":"SUSTAIN-4053","fields":{"summary":"REST ye merry gentlemen3","created":"2016-03-04T09:52:23.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-04T09:52:23.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}}]}
I converted Json to Apex and following classes were generated:
// //Generated by AdminBooster // public class JiraGetIssueResponse { public String expand; //schema,names public Integer startAt; //0 public Integer maxResults; //50 public Integer total; //4 public cls_issues[] issues; public class cls_issues { public String expand; //operations,editmeta,changelog,transitions,renderedFields public String id; //176072 public String self; //https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176072 public String key; //TEST-3 public cls_fields fields; } public class cls_fields { public String summary; //REST ye merry gentlemen2 public String created; //2016-03-03T11:38:40.000-0800 public cls_assignee assignee; public cls_priority priority; public String updated; //2016-03-03T11:38:40.000-0800 public cls_status status; } public class cls_assignee { } Public class cls_priority { public String self; //https://beta.pelco.com:8443/tasks/rest/api/2/priority/6 public String iconUrl; //https://beta.pelco.com:8443/tasks/images/icons/help_16.gif public String name; //None public String id; //6 } public class cls_status { public String self; //https://beta.pelco.com:8443/tasks/rest/api/2/status/1 public String description; //The issue is open and ready for the assignee to start work on it. public String iconUrl; //https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png public String name; //Open public String id; //1 public cls_statusCategory statusCategory; } Public class cls_statusCategory { public String self; //https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2 public Integer id; //2 public String key; //new public String colorName; //blue-gray public String name; //New } public static JiraGetIssueResponse parse(String json) { return (JiraGetIssueResponse) System.JSON.deserialize(json, JiraGetIssueResponse.class); } /* static testMethod void testParse() { String json= '{"expand":"schema,names","startAt":0,"maxResults":50,"total":4,"issues":[{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176072","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176072","key":"TEST-3","fields":{"summary":"REST ye merry gentlemen2","created":"2016-03-03T11:38:40.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-03T11:38:40.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}},{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176071","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176071","key":"TEST-2","fields":{"summary":"REST ye merry gentlemen.","created":"2016-03-02T16:15:49.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-02T16:15:49.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}},{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176073","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176073","key":"SUSTAIN-4052","fields":{"summary":"REST ye merry gentlemen2","created":"2016-03-03T13:01:31.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-03T13:01:31.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}},{"expand":"operations,editmeta,changelog,transitions,renderedFields","id":"176074","self":"https://beta.pelco.com:8443/tasks/rest/api/latest/issue/176074","key":"SUSTAIN-4053","fields":{"summary":"REST ye merry gentlemen3","created":"2016-03-04T09:52:23.000-0800","assignee":null,"priority":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/priority/6","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/help_16.gif","name":"None","id":"6"},"updated":"2016-03-04T09:52:23.000-0800","status":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/status/1","description":"The issue is open and ready for the assignee to start work on it.","iconUrl":"https://beta.pelco.com:8443/tasks/images/icons/statuses/open.png","name":"Open","id":"1","statusCategory":{"self":"https://beta.pelco.com:8443/tasks/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"New"}}}}]}'; JiraGetIssueResponse obj = parse(json); System.assert(obj != null); } */ }
I am not sure what I am doing wrong, in the parsing and deserialization.
Regards,
Gaurav
- Gaurav Agnihotri
- March 24, 2016
- Like
- 0
Simple REST class won't work (Could not find a match for URL ....)
Here's the Apex REST class:
@RestResource(urlMapping='/abc/def/*') global with sharing class TheRESTclass { @HttpGet global static String doGet(RestRequest req, RestResponse res) { return 'hello'; } }
From the Apigee Salesforce console, I call the following URL (using OAuth authentication):
https://na7.salesforce.com/services/apexrest/abc/def
I've also tried it with the namespace in there:
https://na7.salesforce.com/services/apexrest/namespace/abc/def
But I keep getting this error:
"message": "Could not find a match for URL /namespace/abc/def", "errorCode": "NOT_FOUND"
I've looked at multiple tutorials and they all guided me in the same direction. So I don't know what I could be possibly missing. Do I need to comfigure Remote Site Settings or do any other type of configuration?
Thanks in advance.
- asadim2
- January 03, 2012
- Like
- 0
Render HTML stored in field?
Hello all-
I am trying to display HTML stored in a field on a Visualforce page. But not sure it is possible. For example:
I have a custom object "HTML_Object__c" with a field called "". I want to call a custom component in a page that calls a custom controller that queries SFDC for this fields data:
Code:
public HTML_Object__c getHTMLText() { HTML_Object__c HTMLText= [select from HTML_Object__c Where SOME CONDITION IS TRUE]; return HTMLText; }
Then in the controller I want to display it in the VF page:
Code:
{!HTMLText.HTML_output__c}
The problem is it displays the HTML as HTML. So if I had "<strong>Test</strong>" stored in the field it would display exactly that and not "test".
Any one know if I can do this?? Thanks in advance
- tinman44
- January 07, 2009
- Like
- 0