• RohitJ
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
I have a requirement, where I have a scheduled apex which runs every 5 mins and invokes a future method of an apex class. This future method invokes a managed package method for making the callout. So the current logic is that in a for loop for every record I am forming the request and invoking the Managed package method to perform the callout. The callout gives a response and on the basis of response I have to perform another callout or just move ahead. Now the problem is that there is DML transaction happening in the Managed package method as confirmed by the client. So while performing the 2nd callout or the callout for next record, I get the System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out.

What approach can I take achieve this requirement?

Here is the snippet of how logic is written now

Schedule Class -> invokes Apex class method
processRecords()
{
In this there are 3 SObjects maps which are serialized and sent to the future method
}
futureMethod(){
Deserialize the input
for(every record)
{ create the request invoke the managed package method to perform callout if response success put data in map for DML in the end after for loop if response failure invoke 2nd callout
}
}
In the end perform DML operations.
Hi All,
I have added two lightning component inside a parent lightning component. I have added slds-scrollable to both div class of the 2 lightning components as below

<div class="slds-grid slds-gutters">
            <div class="slds-col slds-size_1-of-3 slds-scrollable">
                <c:Cmp1 recordId="xxxxxxx"/>
            </div>
            <div class="slds-col slds-size_2-of-3 slds-scrollable">
                <c:Cmp2/>
            </div>
</div>
But for some reason the scroll bar is not appearing on the two components, rather i get a scroll bar for the complete page.
User-added image

Issue 2: 
Under the observation section, the Textarea is not aligning with other components. It appears bit below.
Code for the component is below
<div class="slds-grid slds-gutters ">
      <div class="slds-col slds-size_4-of-12">
              <!-- <label class="slds-form-element__label">{!field.fieldDescription}</label>  -->
              <label class="slds-form-element__label">Description</label> 
               <!-- <lightning:outputField variant="label-hidden" fieldName="{!field.fieldDescription}"/> -->
                    </div>
               <div class="slds-col slds-size_1-of-12">
                        <lightning:helptext
                        content="{!field.fieldHint}" />
                    </div>
                    <div class="slds-col slds-size_3-of-12">
                        <lightning:radioGroup name="radioGroup" options="{! v.Ratings }" value="{! v.value }" type="button"
                            class="customRadioCls" />
                    </div>
                    <div class="slds-col slds-size_4-of-12">
                        <lightning:textarea name="input3" placeholder="Comments/Remarks for the observation" />
                    </div>
                </div>

Need help on above 2 issue.

Thank you in advance
  • April 13, 2020
  • Like
  • 0
Hi All,

I am very new to this. I have two selectList on my VF page, when i select the event selectList i am passing it to Apex class, in the apex class i am running another SOQL query to fetch sessions on basis of Event value passed. I am unable to populate the table.

VF code :
<apex:page controller="AgendaBuilderController">
    <apex:form >
        <apex:pageBlock title="Agenda Builder">
            <apex:outputLabel value="Select Attendee">
        <apex:selectList multiselect="false" size="1">
                <apex:selectOptions value="{!leadNames}">
            </apex:selectOptions>
        </apex:selectList>
                </apex:outputLabel>            
            <apex:outputLabel value="Select Event">
        <apex:selectList multiselect="false" size="1" value="{!selectedEvent}">
                <apex:selectOptions value="{!campgnNames}">
            </apex:selectOptions>
            <apex:commandButton value="Go" action="{!showSessions}" reRender="abcd">
                </apex:commandButton>
        </apex:selectList>
                </apex:outputLabel>
             <apex:outputLabel value="{!selectedEvent}" id="abcd"></apex:outputLabel>
            <apex:pageBlockTable value="{!displaySessions}" var="a" title="Session Details">
                <apex:column value="{!a.Name}">
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Code :

public class AgendaBuilderController {
    
    public String attendee { get;set;}
    public String event { get;set;}
    public String selectedEvent { get;set;}
    public String session { get;set;}
    List<Campaign> eventId = new List<Campaign>();
    List<Session__c> sessionList = new List<Session__c>();
    public List<Session__c> displaySessions { get; set;}
    
    List<Campaign> campgn = [SELECT Name from Campaign];
    public List<Campaign> getCampgn(){
        return campgn;
    }
    
    List<selectOption> options = new List<selectOption>();
    public List<selectOption> getLeadNames() {
        for(Lead leads : [select name from Lead]) {
            options.add(new selectOption(leads.name,leads.name));
        }
        return options;
    }
    
     List<selectOption> camgnOptions = new List<selectOption>();
    public List<selectOption> getCampgnNames() {
        for(Campaign campaigns : [SELECT name from Campaign]) {
            camgnOptions.add(new selectOption(campaigns.name,campaigns.name));
        }
        return camgnOptions;
    }
    
    public void showSessions(){
        
        System.debug('Selected Event '+selectedEvent);
        eventId = [SELECT Id from Campaign WHERE Name=:selectedEvent];
        System.debug('Campaign Id ' +eventId);
                                                             
        displaySessions = [SELECT Name from Session__c where event__c =:eventId];
        
    }
}

I am pretty sure i am going wrong in the code. Please help in this.

Regards,
Rohit
  • April 13, 2019
  • Like
  • 0
I have followed numerous guides on creating Apex Test Classes, however I am using the class to reference data on my LWC and I am unsure how to go about testing.

Please see current Apex Code:
public class AccountContactController{
      
    @AuraEnabled(cacheable=true)
    public static List<AccountContactListWrapper> getAllAccountWithContacts(string searchKey){
        string searchKeyword = '%' + searchKey + '%';
        List<AccountContactListWrapper> accWrapperList = new List<AccountContactListWrapper>();
        List<Account> accList = [SELECT Id, Name, 
                                (SELECT Id, Name, Email, Phone, Title FROM Contacts), 
                                (SELECT Id, Name, Region_picklist__c, Total_Units__c FROM ChildAccounts) 
                                FROM Account WHERE Active__c = TRUE AND RecordTypeId = '0122K000001Dio1QAC' ORDER BY Name];
        if(!accList.isEmpty()){
            for(Account acc : accList){
                AccountContactListWrapper accWrapper = new AccountContactListWrapper();
                accWrapper.accRecord = acc;
                accWrapper.contactList = acc.Contacts;
                accWrapper.contactCount = acc.Contacts.size();
                accWrapper.NumberOfChildAccounts=acc.ChildAccounts.size();
                accWrapperList.add(accWrapper);
            }
        }
        return accWrapperList;
    }
    
    // wrapper class with @AuraEnabled and {get;set;} properties 
    public class AccountContactListWrapper{
        @AuraEnabled
        public Account accRecord{get;set;}
        @AuraEnabled
        public List<Contact> contactList{get;set;}
        @AuraEnabled
        public Integer contactCount{get;set;}
        @AuraEnabled
        public Integer NumberOfChildAccounts{get;set;}
    }
}

Can anyone help guide me on the proper method to testing this code so that we can push it to production with over 75% coverage?
Hi,
Appreciate any help here. New to Apex
I have code which updates on Contacts when Account is updated. I put the code together with the assistance of some code snippets I found online and put the rest of it together based off the requirements.

I'm trying to understand the reason for the use of Trigger.New and Trigger.oldMap. They are concepts I'm not fully familiar with and want to make sure I understand them.

Thanks for any help
for(Account account : [SELECT Id, Total__c, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :Trigger.new]){
        if(account.Total__c != Trigger.oldMap.get(account.id).Total__c){
            Integer numContacts = account.Contacts.size();
            Decimal shareOfTotal = account.Total__c.divide(numberOfContacts,2)

 
I am not able to figure out anything. I used splice method to remove the item from array but it is not removing that item of the checkbox which I am unchecking. Please help If there is any other solution.
Hi All,
I have added two lightning component inside a parent lightning component. I have added slds-scrollable to both div class of the 2 lightning components as below

<div class="slds-grid slds-gutters">
            <div class="slds-col slds-size_1-of-3 slds-scrollable">
                <c:Cmp1 recordId="xxxxxxx"/>
            </div>
            <div class="slds-col slds-size_2-of-3 slds-scrollable">
                <c:Cmp2/>
            </div>
</div>
But for some reason the scroll bar is not appearing on the two components, rather i get a scroll bar for the complete page.
User-added image

Issue 2: 
Under the observation section, the Textarea is not aligning with other components. It appears bit below.
Code for the component is below
<div class="slds-grid slds-gutters ">
      <div class="slds-col slds-size_4-of-12">
              <!-- <label class="slds-form-element__label">{!field.fieldDescription}</label>  -->
              <label class="slds-form-element__label">Description</label> 
               <!-- <lightning:outputField variant="label-hidden" fieldName="{!field.fieldDescription}"/> -->
                    </div>
               <div class="slds-col slds-size_1-of-12">
                        <lightning:helptext
                        content="{!field.fieldHint}" />
                    </div>
                    <div class="slds-col slds-size_3-of-12">
                        <lightning:radioGroup name="radioGroup" options="{! v.Ratings }" value="{! v.value }" type="button"
                            class="customRadioCls" />
                    </div>
                    <div class="slds-col slds-size_4-of-12">
                        <lightning:textarea name="input3" placeholder="Comments/Remarks for the observation" />
                    </div>
                </div>

Need help on above 2 issue.

Thank you in advance
  • April 13, 2020
  • Like
  • 0
Hi All,

I am very new to this. I have two selectList on my VF page, when i select the event selectList i am passing it to Apex class, in the apex class i am running another SOQL query to fetch sessions on basis of Event value passed. I am unable to populate the table.

VF code :
<apex:page controller="AgendaBuilderController">
    <apex:form >
        <apex:pageBlock title="Agenda Builder">
            <apex:outputLabel value="Select Attendee">
        <apex:selectList multiselect="false" size="1">
                <apex:selectOptions value="{!leadNames}">
            </apex:selectOptions>
        </apex:selectList>
                </apex:outputLabel>            
            <apex:outputLabel value="Select Event">
        <apex:selectList multiselect="false" size="1" value="{!selectedEvent}">
                <apex:selectOptions value="{!campgnNames}">
            </apex:selectOptions>
            <apex:commandButton value="Go" action="{!showSessions}" reRender="abcd">
                </apex:commandButton>
        </apex:selectList>
                </apex:outputLabel>
             <apex:outputLabel value="{!selectedEvent}" id="abcd"></apex:outputLabel>
            <apex:pageBlockTable value="{!displaySessions}" var="a" title="Session Details">
                <apex:column value="{!a.Name}">
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Code :

public class AgendaBuilderController {
    
    public String attendee { get;set;}
    public String event { get;set;}
    public String selectedEvent { get;set;}
    public String session { get;set;}
    List<Campaign> eventId = new List<Campaign>();
    List<Session__c> sessionList = new List<Session__c>();
    public List<Session__c> displaySessions { get; set;}
    
    List<Campaign> campgn = [SELECT Name from Campaign];
    public List<Campaign> getCampgn(){
        return campgn;
    }
    
    List<selectOption> options = new List<selectOption>();
    public List<selectOption> getLeadNames() {
        for(Lead leads : [select name from Lead]) {
            options.add(new selectOption(leads.name,leads.name));
        }
        return options;
    }
    
     List<selectOption> camgnOptions = new List<selectOption>();
    public List<selectOption> getCampgnNames() {
        for(Campaign campaigns : [SELECT name from Campaign]) {
            camgnOptions.add(new selectOption(campaigns.name,campaigns.name));
        }
        return camgnOptions;
    }
    
    public void showSessions(){
        
        System.debug('Selected Event '+selectedEvent);
        eventId = [SELECT Id from Campaign WHERE Name=:selectedEvent];
        System.debug('Campaign Id ' +eventId);
                                                             
        displaySessions = [SELECT Name from Session__c where event__c =:eventId];
        
    }
}

I am pretty sure i am going wrong in the code. Please help in this.

Regards,
Rohit
  • April 13, 2019
  • Like
  • 0