• Aakanksha Singh 11
  • NEWBIE
  • 39 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 15
    Replies
I wrote a trigger to prevent task creation if customer Account is blocked.

This is my code,

trigger EventBlocked on Event (Before insert,after update) {
  
    list<Contact> clist =new list<Contact>();
    string Cname;
    
        for (Event t : Trigger.new) {
        
            if (t.WhoId !=Null) {
                
                clist= [select ID, Account_name__C, Account.Lock_record__C from Contact where 
                ID=:t.WhoId and Account.Lock_record__C=True]; 
                
            }
            
            IF(Clist.size()>0)
            {
            T.adderror('You Cant create a Event under the blocked Contact');
            }
            }
            }


How to write a test class for this trigger to improve the code coverage?
Hello Everyone,

I'm working on creating dynamic components, It is working succesfully just for once, and not afterwards. I'm posting my code as well, Please help me with this:
<!--DynamicModalBox(Component)-->
<aura:component >
    <c:DynamicModalBoxButton/>
</aura:component>
 
<!--DynamicModalBoxButton(Component)-->
<aura:component >
    <ltng:require styles="{!$Resource.SLDS +'/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
    <aura:registerEvent name="openPopup" type="c:DynamicModalBoxEvent"/>
    <aura:handler name="RemoveComponent" action="{!c.removeComponent}" event="c:RemoveComponent"/>
	<div class="static">
    	<button class="slds-button slds-button--neutral" onclick="{!c.getCompnent}">Open Modal</button>
    
        <div aura:id="cmpBody">
            {!v.body}
        </div>
    </div>
</aura:component>


<!--Controller-->
({
	getCompnent: function(cmp,event) {
        //var articleId = cmp.get("v.ArticleId");
        var cmpBody=cmp.find("cmpBody");     
        $A.createComponent(
            "c:DynamicModalBoxPopup",{},
            function(newcomponent){
                //Add the new button to the body array
                if (cmp.isValid()) {
                    var body = cmp.get("v.body");
                    body.push(newcomponent);
                    cmp.set("v.body", body);                    
                }
            }            
        );
        var compEvent = cmp.getEvent("openPopup");
       	compEvent.fire();
    },
    removeComponent:function(cmp,event){
        var cmpBody=cmp.find("cmpBody");
        var comp = event.getParam("comp");
		//alert(comp.toString());
        $A.createComponent(
            comp.toString(),{},
            function(newcomponent){
                //Add the new button to the body array
                if (cmp.isValid()) {
                    var body = cmp.get("v.body");
                    cmpBody.set("v.body",[]);
                }
            }
        );
    },
})
 
<!--DynamicModalBoxPopup(Component)-->
<aura:component >
    <ltng:require styles="{!$Resource.SLDS +'/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
    <aura:handler name="init" value="{!this}" action="{!c.initialize}"/>
    <aura:handler name="openPopup" action="{!c.initialize}" event="c:DynamicModalBoxEvent"/>
    <aura:registerEvent name="RemoveComponent" type="c:RemoveComponent"/>
	<div class="wk_static">
        <div role="dialog" tabindex="-1" aura:id="Modalbox" aria-labelledby="header43" class="slds-modal ">
            <div class="slds-modal__container">
                <div class="slds-modal__header">
                    <button class="slds-button slds-button--icon-inverse slds-modal__close" onclick="{!c.removeComponent}">
                        <span>
                            <c:SVG class="slds-button__icon slds-button__icon--large" xlinkHref="/resource/SLDS/assets/icons/action-sprite/svg/symbols.svg#close" />
                            <span class="slds-assistive-text">Close</span>
                        </span>                 
                    </button>
                    <h2 id="header43" class="slds-text-heading--medium">Modal Header</h2>
                </div>
                <div class="slds-modal__content slds-p-around--medium">
                    <div>
                        <p>Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit officia tempor esse quis. Cillum sunt ad dolore
                        quis aute consequat ipsum magna exercitation reprehenderit magna. Tempor cupidatat consequat elit dolor adipisicing.</p>
                        <p>Dolor eiusmod sunt ex incididunt cillum quis nostrud velit duis sit officia. Lorem aliqua enim laboris do dolor eiusmod officia. Mollit incididunt nisi consectetur esse laborum eiusmod pariatur proident. Eiusmod et adipisicing culpa deserunt
                        nostrud ad veniam nulla aute est. Labore esse esse cupidatat amet velit id elit consequat minim ullamco mollit enim excepteur ea.</p>
                    </div>
                </div>
                <div class="slds-modal__footer">
                    <button class="slds-button slds-button--neutral" onclick="{!c.removeComponent}">Close</button>
                    <!--<button class="slds-button slds-button-neutral slds-button-brand">Save</button>-->
                </div>
            </div>
        </div>
        <div class="slds-backdrop " aura:id="MB-Back"></div>
        
    </div>
</aura:component>




<!--Controller-->
({
	initialize:function(cmp,event){        
        var cmpTarget = cmp.find('Modalbox');
       	var cmpBack = cmp.find('MB-Back');
        $A.util.addClass(cmpTarget, 'slds-fade-in-open');
        $A.util.addClass(cmpBack, 'slds-backdrop--open'); 
    },
    removeComponent:function(component, event, helper){
        var compEvent = component.getEvent("RemoveComponent");
        compEvent.setParams({
        	"comp" : component
        });
	    compEvent.fire();
    }
})
 
<!--Events Used-->

<!--RemoveComponent-->
<aura:event type="COMPONENT" description="Event template" >
    <aura:attribute name="comp" type="Aura.Component"/>
</aura:event>

<!--DynamicModalBoxEvent-->
<aura:event type="COMPONENT" description="Event template" />

Regards
Aakanksha Singh
Hello Everyone,

Greetings!!

I want know how SOQL subquery can be written in  REST explorer on workBench, for example, I have to fetch accounts and related contacts with the following SOQL query:

-> SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account

How this query could be written IB REST Explorer?

Please respond. Thanks in advance.

Regards
Aakanksha Singh
Hello Everyone,

I want to know the possible ways through which we can fetch more than 50k/1million records through apex class in salesforce.

Please respond.

Thanks in advance.

Rregards
Aakanksha Singh
Hello Everyone,

I'm trying to assing a value of a variable from an Batch class to a static variable in apex class. When I debug it though the developer console, I observe that the value is assigned succussfully, but when I access it through class I don't get any value i.e null. You can view my code below:

<pre>
//----Batch Class----//
global with sharing class fetchAccountBatch implements Database.Batchable<sObject>, Database.stateful{
    
    public list<account> acc= new list<account>();
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        
        string query = 'Select Id,Name from Account';
        return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, list<Account> scope){
    
        for(account a: scope){
            acc.add(a);
        }
        
    }
    global void finish(Database.BatchableContext BC){
        
        system.debug(acc);
        
        fetchAccountClass.acc.addAll(acc);
        
        system.debug(fetchAccountClass.acc);
    
    }
    
}
</pre>

<pre>
//----Scheduled Class----//
global with sharing class fetchAccountSchedule implements Schedulable{     
     
     global void execute(SchedulableContext sc) {

        fetchAccountBatch bc = new fetchAccountBatch();
        database.executeBatch(bc,2000);
        system.debug(fetchAccountClass.acc);
    }
    
}
</pre>

<pre>
//----Apex Class----//
global with sharing class fetchAccountClass {   
    
    global static list<account> acc{get{
        
        if(acc==null)
            acc = new list<account>();
            
        return acc; 
    }set;}
    
    public void fetchAccount(){
        
        DateTime dt = system.now().addSeconds(1);
        integer h = integer.valueOf(dt.hour());
        integer m = integer.valueOf(dt.minute());
        integer s = integer.valueOf(dt.second());
        
        
        try{
            CronTrigger cr = [SELECT Id, CronJobDetail.Name FROM CronTrigger where CronJobDetail.Name ='TestJob'];
            if(cr!=null && cr!= new crontrigger()){
                     system.abortJob(cr.Id);
                 }
        }catch(exception e){}
        
        try{
            string cronExp = s+' '+m+' '+h+' ? * * *';
            system.schedule('TestJob',cronExp,new fetchAccountSchedule());            
            
        }catch(Exception e){
            
            apexpages.addMessages(e);
                    
        }
    }
}
</pre>

<pre>
<!--Visualforce Page-->
<apex:page controller="fetchAccountClass">

    <apex:form >
        
        <apex:sectionHeader Title="Account" subtitle="List View"/>
        
        <apex:pageblock title="Account List" >
            <apex:pageblockbuttons>
                <apex:commandButton value="Get Data" action="{!fetchAccount}" rerender="AccountTable"/>
            </apex:pageblockbuttons>
        
            <apex:pageMessages/>
            <apex:pageblocktable value="{!acc}" var="key" id="AccountTable">
            
                <apex:column value="{!key.Id}"/>
                <apex:column value="{!key.name}"/>
            
            </apex:pageblocktable>
        </apex:pageblock>
    </apex:form>

</apex:page>

</pre>

Please Respond.

Thanks in advance.

Regards
Aakanksha Singh
 
Hello Everyone,

I'm trying to use force:navigateToComponent, but its not working. Here is my code:
<pre>
({
    NavigatetoComp : function(component, event, helper) {
        
        console.log('Enter Here');
        var evt = $A.get("e.force:navigateToComponent");
        console.log('evt'+evt);
        evt.setParams({
            componentDef: "c:MyComponent2",
            //componentAttributes :{ }
        });
       
        evt.fire();
    }
})
</pre>

It throws following error:
User-added image

Can any body tell why is it so?

Thanks In Advance
Aakanksha Singh
Hi, 

I want to display list of accounts with contacts in lightning page. Here the code i have written. Here accounts are displaying but contacts are not display. Please help me to display the accounts with contacts.

Thank you.


 
<aura:component controller="accountsWithContactsClass" implements="flexipage:availableForAllPageTypes" access="global">
	 
    <aura:attribute name="accounts" type="Account[]" />
    <ui:button label="click this" press="{!c.myAction}" />
    <table>
            <tr><td><b>Name</b></td><td><b>Industry</b></td></tr>

    <aura:iteration items="{!v.accounts}" var="accs1" >
        <tr>   
        <td> {!accs1.Name}  </td>
         
      <td>   {!accs1.Industry}  </td> 
      <!--   <td>   {!accs1.Contacts.lastName}  </td> -->
        </tr>     
     <tr>   <aura:iteration items="{!v.accs1.contacts}" var="con1" >
            
             <td>{!con1.lastName} </td>
            
        </aura:iteration></tr>
     </aura:iteration>                                            
        </table>
    
</aura:component>








({
	myAction : function(component, event, helper) {
		var action =component.get("c.getAllAccounts");
        console.log('The action value is: '+action);
         action.setCallback(this, function(a){ 
             
            component.set("v.accounts", a.getReturnValue());
           //  console.log('The accs are :'+JSON.stringify(a.getReturnValue()));
            console.log('The accs are :'+JSON.stringify(a.getReturnValue()));
          
        });
        $A.enqueueAction(action);
	}
})











public class accountsWithContactsClass {

@auraEnabled
public static list<account> getAllAccounts()
    {
       list<account> accs =[select id,name,phone,industry,(select lastName from contacts) from account limit 10];
      //  list<account> accs =[select id,name,phone,industry from account limit 10];
     //   return [select Id,Name from account limit 10];
     return accs;
    }
}

 

I have done the workaround for the sort line items.   The lines are sorted via a custom web service so there is no need to pop up the /oppitm/lineitemsort.jsp page.    I create the form and hidden fields dynamically and hit submit.   This pops up the jsp page.   I want to skip that and auto submit via ajax or something.    It works when I have form.submit() and the form pops up and I click the Save button.   Is there a way to replace the form.submit() and having the user click the save button.

 

I tried to use jquery ajax and ajaxSubmit, but I get an error with the error message so not sure what is wrong.   Can this be done and does anyone know how to do that part.

 

--------------------------------------------------------------------------------------------

 

So I had this originally:

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")}

var quoteID = '{!Quote.Id}';

//call the apex web service to get the QLIs in the desired sort order for this opp
//var result = sforce.apex.execute("customSort","MRsort",{quoteID:quoteID});   
var result = sforce.apex.execute("customSort","QLI_SortByPrdQty",{quoteID:quoteID});   

//need to post a form to /oppitm/lineitemsort.jsp because this is how SFDC
//does it but there is not direct API to do the sorting (thus the awkward workaround)
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "/oppitm/lineitemsort.jsp");

form.setAttribute("id", "sortForm");

//set the id of the request to the quote ID
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'id');
hiddenField.setAttribute("value", '{!Quote.Id}');   
form.appendChild(hiddenField);

//the name of the sorted OLI list that the JSP is expecting is "duel0"
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'duel0');
hiddenField.setAttribute("value", String(result));
form.appendChild(hiddenField);

var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'retURL');
hiddenField.setAttribute("value", '/{!Quote.Id}');
form.appendChild(hiddenField);

//set to save
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", 'hidden');
hiddenField.setAttribute("name", 'save');
hiddenField.setAttribute("value", ' Save ');
form.appendChild(hiddenField);

//need to do this so it works in IE
document.body.appendChild(form);

//submit!!
form.submit();

 

I have been commenting out the form.submit and trying to use jquery / ajax to automate:

 

I include the jquery js scripts:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
    <script src="http://malsup.github.com/jquery.form.js"></script>

 

I tried using $.ajax where formData is the form data serialized but get the error alert with error=error. 

 

         $.ajax({
             type: "post",
             url:  "https://na14.salesforce.com/oppitm/lineitemsort.jsp",
             data: formData,
             success: function() {
                 alert('>> ajax submit successful <<');
             },
             error: function(req, status, error) {
                 alert('>> ajax submit failed: status='+ status + ' error=' + error + ' <<');
             }
         });
        

Then tried and get the error alert with error=error again.
         
         $('#sortForm').ajaxSubmit({
             success: function() {
                 alert('>> ajax submit successful <<');
             },
             error: function(req, status, error) {
                 alert('>> ajax submit failed: req='+req+' status='+ status + ' error=' + error + ' <<');
             }
         });