• Praveen Mehar
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
public class N1apex {
   @AuraEnabled
    public static ID mySearch(String phon){
        Contact acc=[select ID,Phone,AccountId from Contact where Phone=:phon];
        return acc.AccountId;
    }
    @AuraEnabled
    public static string names(String firstname,String lastname,ID accountId){
        String status;
        try{
        contact c=new contact();
        c.FirstName=firstname;
        c.LastName=lastname;
        c.AccountId=accountId;
        insert c;
        status='Record inserted';
    }
        catch(Exception e){
            status='Record Failed';
        }
        return status;
}
}
----------------------------------------------------------------------------------------------------------------
<aura:event type="COMPONENT" description="Event template" >
    <aura:attribute name="accountId" type="ID"/>
</aura:event>

----------------------------------------------------------------------------------------------------------------
<aura:component controller="N1apex">
    <aura:registerEvent name="myEvent" type="c:N1Event" />
    
    <div>
        <lightning:input label="phone" aura:id="pname"/>
        <lightning:button label="submit" onclick="{!c.show}"/>
    </div>
</aura:component>

({
	show : function(component, event, helper) {
    	var phone1=component.find("pname").get("v.value");        
        
        var action=component.get("c.mySearch");
        action.setParams({"phon":phone1});
        action.setCallback(this,function(response){
            console.log("Method invoked");
            var state=response.getState();
            if(state==='SUCCESS'){
                console.log("Operation Successfull");
                var accid=response.getReturnValue();
				var evt=component.getEvent("myEvent");
                evt.setParams({"accountId":accid});
                evt.fire();
            }
                else{
                    console.log("Operation Failed");
                }                
            }
        );
        $A.enqueueAction(action);
	}
})

----------------------------------------------------------------------------------------------------------------
<aura:component controller="N1apex">
    <aura:handler name="myEvent" event="c:N1Event" action="{!c.invoke}"/>
    <lightning:input label="LastName" aura:id="lname"/>
    <lightning:input label="FirstName" aura:id="fname"/>
    <c:N1Event_Child />
</aura:component>

({
	invoke : function(component, event, helper) {
        var lname=component.find("lname").get("v.value");
        var fname=component.find("fname").get("v.value");
        var acctid=component.getParams("accountId");
        var action=component.get("c.names");
        action.setParams({"lastname":lname,"firstname":fname,"accountid":acctid});
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state==='SUCCESS'){
                alert(response.getReturnValue());
            }
            else{
                alert('Failed');
            }
        });
        $A.enqueueAction(action);
        
	}
})

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

<aura:application extends="force:slds">
    <c:N1Event_Parent />
</aura:application>

 
public class params1 {
    @AuraEnabled
    public static List<Opportunity> ops(String oStagename,String oType){
        List<Opportunity> opportunities=[select Id,Name,Stagename,Type from Opportunity where StageName=:oStagename and Type=:oType limit 4];
        return opportunities;
    }
}


<aura:component controller="params1">
    <aura:attribute name="optylist" type="List"/>
    <lightning:input label="StageName" aura:id="sname" />
    <lightning:input label="CustomerType" aura:id="cust"/>
    <lightning:button label="Submit" onclick="{!c.invoke}"/>
    
    <aura:iteration items="{!v.optylist}" var="a">
    	<p>{!a.Name} &nbsp;&nbsp;&nbsp;{!a.Stagename}&nbsp;&nbsp;&nbsp;{!a.Type}</p>
    </aura:iteration>
</aura:component>


({
    invoke : function(component, event, helper) {
        var stagename=component.find("sname").get("v.value");
        var type=Component.find("cust").get("v.value");
        
        var action=component.get("c.ops");
        action.setParams({"oStagename":stagename,"oType":type});
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state==='SUCCESS'){
                console.log('Operation successful');
                component.set("v.optylist",response.getReturnValue());
            }
        })
        $A.enqueueAction(action);
    }
       
})


<aura:application extends="force:slds">
	<c:parasm />
</aura:application>

 
Params1:
public class params1 {
    @AuraEnabled
    public static List<Account> accountthod(){
        List<Account> accounts=[select id,name,industry,rating,phone from Account limit 4];
        return accounts;
    }
}

pasasm.cmp
<aura:component controller="params1">
    <aura:attribute name="acclist" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
    <aura:iteration items="{!v.acclist}" var="a">
        <p>{!a.name} &nbsp;&nbsp;&nbsp;{!a.industry} &nbsp;&nbsp;&nbsp;{!a.rating} &nbsp;&nbsp;&nbsp;{!a.phone}</p>
    </aura:iteration>
</aura:component>

parasmController.js
({
    invoke : function(component, event, helper) {
        var action=component.get("v.accountthod");
        action.setCallback(this,function(response){
            console.log("invoked");
            var state=response.getState();
            if(state==='SUCCESS'){
                console.log('Operation successfull');
                component.set("v.acclist",response.getReturnValue());
            }else{
                console.log('Operation failed');
            }            
        });
        $A.enqueueAction(action);
    }
})

parasmap.app
<aura:application extends="force:slds">
    <c:parasm />
</aura:application>
public class N1apex {
   @AuraEnabled
    public static ID mySearch(String phon){
        Contact acc=[select ID,Phone,AccountId from Contact where Phone=:phon];
        return acc.AccountId;
    }
    @AuraEnabled
    public static string names(String firstname,String lastname,ID accountId){
        String status;
        try{
        contact c=new contact();
        c.FirstName=firstname;
        c.LastName=lastname;
        c.AccountId=accountId;
        insert c;
        status='Record inserted';
    }
        catch(Exception e){
            status='Record Failed';
        }
        return status;
}
}
----------------------------------------------------------------------------------------------------------------
<aura:event type="COMPONENT" description="Event template" >
    <aura:attribute name="accountId" type="ID"/>
</aura:event>

----------------------------------------------------------------------------------------------------------------
<aura:component controller="N1apex">
    <aura:registerEvent name="myEvent" type="c:N1Event" />
    
    <div>
        <lightning:input label="phone" aura:id="pname"/>
        <lightning:button label="submit" onclick="{!c.show}"/>
    </div>
</aura:component>

({
	show : function(component, event, helper) {
    	var phone1=component.find("pname").get("v.value");        
        
        var action=component.get("c.mySearch");
        action.setParams({"phon":phone1});
        action.setCallback(this,function(response){
            console.log("Method invoked");
            var state=response.getState();
            if(state==='SUCCESS'){
                console.log("Operation Successfull");
                var accid=response.getReturnValue();
				var evt=component.getEvent("myEvent");
                evt.setParams({"accountId":accid});
                evt.fire();
            }
                else{
                    console.log("Operation Failed");
                }                
            }
        );
        $A.enqueueAction(action);
	}
})

----------------------------------------------------------------------------------------------------------------
<aura:component controller="N1apex">
    <aura:handler name="myEvent" event="c:N1Event" action="{!c.invoke}"/>
    <lightning:input label="LastName" aura:id="lname"/>
    <lightning:input label="FirstName" aura:id="fname"/>
    <c:N1Event_Child />
</aura:component>

({
	invoke : function(component, event, helper) {
        var lname=component.find("lname").get("v.value");
        var fname=component.find("fname").get("v.value");
        var acctid=component.getParams("accountId");
        var action=component.get("c.names");
        action.setParams({"lastname":lname,"firstname":fname,"accountid":acctid});
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state==='SUCCESS'){
                alert(response.getReturnValue());
            }
            else{
                alert('Failed');
            }
        });
        $A.enqueueAction(action);
        
	}
})

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

<aura:application extends="force:slds">
    <c:N1Event_Parent />
</aura:application>

 
Params1:
public class params1 {
    @AuraEnabled
    public static List<Account> accountthod(){
        List<Account> accounts=[select id,name,industry,rating,phone from Account limit 4];
        return accounts;
    }
}

pasasm.cmp
<aura:component controller="params1">
    <aura:attribute name="acclist" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
    <aura:iteration items="{!v.acclist}" var="a">
        <p>{!a.name} &nbsp;&nbsp;&nbsp;{!a.industry} &nbsp;&nbsp;&nbsp;{!a.rating} &nbsp;&nbsp;&nbsp;{!a.phone}</p>
    </aura:iteration>
</aura:component>

parasmController.js
({
    invoke : function(component, event, helper) {
        var action=component.get("v.accountthod");
        action.setCallback(this,function(response){
            console.log("invoked");
            var state=response.getState();
            if(state==='SUCCESS'){
                console.log('Operation successfull');
                component.set("v.acclist",response.getReturnValue());
            }else{
                console.log('Operation failed');
            }            
        });
        $A.enqueueAction(action);
    }
})

parasmap.app
<aura:application extends="force:slds">
    <c:parasm />
</aura:application>