• Manjunath SC 5
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 3
    Replies
Hello guys

i am new to the coding, i want to write test class for contact creation on new account, below is my code

trigger ConOnNewAcc on Account (after insert){
    Public List<Contact> con = new List<Contact>();
    For(Account Acc:Trigger.new ){
        Contact c=new contact();
        c.accountid=acc.id;
        c.Lastname=acc.Name;
        con.add(c);
    }
    Insert Con;
}
 
Hello guys

i am working on aura components where when checkbox is checked, 2nd checkbox needs to be unchecked, i refered the below link

https://developer.salesforce.com/forums/?id=906F0000000DCw7IAG

Still i am not able to achive the functionality
 
Apex class

public class UpdateUsingCheckboxC {
    
    @AuraEnabled
    public static List <Contact> fetchContact(string key) {
        system.debug('classname'+key);
        Class__c cls = [select id,Courses__r.name from Class__c where id=:key];
        string classname = cls.Courses__r.name;
        system.debug('classname'+classname);
        return [SELECT Id, Name,Account.Name,FirstName,LastName,Check_for_Attendance__c,Check_for_Absentee__c FROM Contact where (Check_for_Attendance__c=false AND Check_for_Absentee__c=false) AND Account.Name =:classname];
    }
    
    @AuraEnabled
    public static void updateRecord(List <String> lstRecordId,string key) {
        List<Contact> lstUpdate = new List<Contact>();
        List<Attendancess__c> listAttendnce = new List<Attendancess__c>();
        Class__c cls = [select id,Courses__r.name from Class__c where id=:key];
        if(cls.Id !=null){
            for(Contact con : [SELECT Id,AccountId, Name,Phone,FirstName,LastName,Check_for_Attendance__c,Check_for_Absentee__c  FROM Contact WHERE Id IN : lstRecordId]){
                con.Check_for_Attendance__c = true;
                con.Check_for_Absentee__c = false;
                lstUpdate.add(con);
                
                Attendancess__c attandenc = new Attendancess__c();
                attandenc.Class__c = cls.Id;
                attandenc.Student_Attended__c = true;
                attandenc.Name = con.Name;
                attandenc.Created_Date_Time__c = system.now();
                listAttendnce.add(attandenc);
                system.debug('listAttendnce'+listAttendnce);
            }
            
            if(lstUpdate.size() > 0){
                update lstUpdate;
            }
            if(listAttendnce.size() > 0){
                insert listAttendnce;
            }
        }
    }
    
    @AuraEnabled
    public static void updateSecondRecord(List <String> secondRecordId,string key) {
        system.debug('key1'+key);
        system.debug('secondRecordId '+secondRecordId);
        List<Contact> lstUpdate = new List<Contact>();
        List<Attendancess__c> listAttendnce = new List<Attendancess__c>();
        if(key !=null){
        Class__c cls = [select id,Courses__r.name from Class__c where id=:key];
            for(Contact con : [SELECT Id,AccountId, Name,Phone,FirstName,LastName,Check_for_Attendance__c,Check_for_Absentee__c  FROM Contact WHERE Id IN : secondRecordId]){
                con.Check_for_Absentee__c = true;
                con.Check_for_Attendance__c = false;
                lstUpdate.add(con);
                
                Attendancess__c attandenc = new Attendancess__c();
                attandenc.Class__c = cls.Id;
                attandenc.Student_Attended__c = false;
                attandenc.Name = con.Name;
                attandenc.Created_Date_Time__c = system.now();
                listAttendnce.add(attandenc);
                system.debug('listAttendnce'+listAttendnce);
            }
            
            if(lstUpdate.size() > 0){
                update lstUpdate;
            }
            if(listAttendnce.size() > 0){
                insert listAttendnce;
            }
        }
    }
    
}
----------------------
Component

<aura:component controller="UpdateUsingCheckboxC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="ContactList" type="List" />
    
    <aura:handler name="init" value="{!this}" action="{!c.loadContacts}"/>
    <aura:handler event="force:refreshView" action="{!c.loadContacts}" />
    
    <div class="slds-grid slds-grid--align-end"> 
        <button class="slds-button slds-button--brand" onclick="{!c.updateFields}">Update Attendance</button>
    </div>
    
    <table class="slds-table slds-table--bordered slds-table--cell-buffer">
        <thead>
            <tr class="slds-text-title--caps">
                <th></th>
                <th></th>
                <th>
                    <span class="slds-truncate">Attendee</span>      
                </th>
                <th style="width:3.25rem;" class="slds-text-align--right">
                    <div class="slds-form-element">
                        <div class="slds-form-element__control">
                            <label class="slds-checkbox">
                                <!--header checkbox for select all-->
                                <ui:inputCheckbox aura:id="box3" change="{!c.selectAll}"/>
                                <span >Attended</span>
                                <span class="slds-form-element__label text"></span>
                            </label>
                        </div>
                    </div>
                </th>
                <th style="width:3.25rem;" class="slds-text-align--right">
                    <div class="slds-form-element">
                        <div class="slds-form-element__control">
                            <label class="slds-checkbox">
                                <!--header checkbox for select all-->
                                <ui:inputCheckbox aura:id="boxPack" change="{!c.selectAll}"/>
                                <span >Absentee</span>
                                <span class="slds-form-element__label text"></span>
                                
                            </label>
                        </div>
                       </div>
                        </th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <td>
            
        </td>
        <tbody>
            <aura:iteration items="{!v.ContactList}" var="con">
                <tr>
                    <td></td>
                    <td></td>
                    <td scope="row">
                        <div class="slds-truncate" title="{!con.Name}"><a>{!con.Name}</a></div>
                    </td>
                    <td scope="row" class="slds-text-align--right" style="width:3.25rem;">
                        <div class="slds-form-element">
                            <div class="slds-form-element__control">
                                <label class="slds-checkbox">
                                    <ui:inputCheckbox  text="{!con.Id}" aura:id="boxPack" value="" change="{!c.onCheck1}"/>
                                     <span class="slds-checkbox--faux"></span>
                                    <span class="slds-form-element__label text"></span>
                                    </label>
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="slds-form-element">
                            <div class="slds-form-element__control">
                                <label class="slds-checkbox">
                                    <ui:inputCheckbox  text="{!con.Id}" aura:id="boxPack1" value="" change="{!c.onCheck2}"/>
                                     <span class="slds-checkbox--faux"></span>
                                    <span class="slds-form-element__label text"></span>
                                    </label>
                            </div>
                        </div>
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </aura:iteration>
        </tbody>
</table>
</aura:component>

----------------------------------------------------
controller

({
    loadContacts: function(component, event, helper) {
        var rid = component.get("v.recordId");
        var action = component.get('c.fetchContact');
        action.setParams({key : rid});
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set('v.ContactList', response.getReturnValue());
                component.find("box3").set("v.value", false);
            }
        });
        $A.enqueueAction(action);
    },

    selectAll: function(component, event, helper) {
        var selectedHeaderCheck = event.getSource().get("v.value");
        var getAllId = component.find("boxPack"); 
        if(! Array.isArray(getAllId)){
            if(selectedHeaderCheck == true){ 
                component.find("boxPack").set("v.value", true);    
            }else{
                component.find("boxPack").set("v.value", false);
            }
        }else{
            // check if select all (header checkbox) is true then true all checkboxes on table in a for loop  
            // and set the all selected checkbox length in selectedCount attribute.
            // if value is false then make all checkboxes false in else part with play for loop 
            // and select count as 0
            if (selectedHeaderCheck == true) {
                for (var i = 0; i < getAllId.length; i++) {
                    component.find("boxPack")[i].set("v.value", true);
                }
            } 
            else
            {
                for (var i = 0; i < getAllId.length; i++) {
                    component.find("boxPack")[i].set("v.value", false);
                }
                
            } 
        }  
    },
        
    updateFields: function(component, event, helper) {
        var updateId = [];
        var getAllId = component.find("boxPack");
        
        
        if(getAllId!=null){
            if(! Array.isArray(getAllId)){
                if (getAllId.get("v.value") == true) {
                    updateId.push(getAllId.get("v.text"));
                    
                }
            }else{
                
                for (var i = 0; i < getAllId.length; i++) {
                    if (getAllId[i].get("v.value") == true) {
                        updateId.push(getAllId[i].get("v.text"));
                        
                    }
                }
            } 
                var rid = component.get("v.recordId");
            var action = component.get('c.updateRecord');
            action.setParams({
                "lstRecordId": updateId,
                "key" : rid
            });
            action.setCallback(this, function(response) {
                
                var state = response.getState();
                if (state === "SUCCESS") {
                    console.log(state);
                    $A.get('e.force:refreshView').fire();
                }
            });
            $A.enqueueAction(action);
        }
        
        var updateId1 = [];
        var getAllIdUncheck = component.find("boxPack1");
        if(getAllIdUncheck!=null){
            if(! Array.isArray(getAllIdUncheck)){
                if (getAllIdUncheck.get("v.value") == true) {
                    updateId1.push(getAllIdUncheck.get("v.text"));
                    
                }
            }else{
                
                for (var i = 0; i < getAllIdUncheck.length; i++) {
                    if (getAllIdUncheck[i].get("v.value") == true) {
                        updateId1.push(getAllIdUncheck[i].get("v.text"));
                       
                    }
                }
            } 
            var rid1 = component.get("v.recordId");
            var action = component.get('c.updateSecondRecord');
            action.setParams({
                "secondRecordId": updateId1,
                "key" : rid1
            });
            action.setCallback(this, function(response) {
                
                var state = response.getState();
                if (state === "SUCCESS") {
                    console.log(state);
                    $A.get('e.force:refreshView').fire();
                }
            });
            $A.enqueueAction(action);
        }
    },
    
  
		onCheck1: function(cmp, evt) {
         var checkCmp1 =cmp.find("checkbox").get("v.value");
         var checkCmp2 =cmp.find("checkbox1").get("v.value");
         if(checkCmp1){
           var temp =cmp.find("checkbox1").set("v.value", true);
        }
         
	},
    onCheck2: function(cmp, evt) {
         var checkCmp1 =cmp.find("checkbox").get("v.value");
         var checkCmp2 =cmp.find("checkbox1").get("v.value");
         if(checkCmp1){
           var temp =cmp.find("checkbox").set("v.value", false);
        }
         
	}
})

User-added image
Hello all

i am new to the vf, i am trying to populate the field values in a table format for the custom object, (i have not used Custom controllers)
how do i populate the field values in 2 columns like shown in the snapshot




below is my code

<apex:page standardController="Apartment__c" showHeader="false" renderAs="pdf" DocType="html">
<apex:form >
   <apex:pageBlock title="Appartment Details">
           <apex:pageBlockSection >
         <table style="width:100%">   
         <tr> 
          <td> <apex:outputField value="{! Apartment__c.Name }" /> </td>
          <td> <apex:outputField value="{! Apartment__c.Floor_No__c }"/> </td>
          <td> <apex:outputField value="{! Apartment__c.Phase__c }" /> </td>
         <td> <apex:outputField value="{! Apartment__c.Property_No__c }"/> </td>
         <td> <apex:outputField value="{! Apartment__c.Facing__c }" /> </td>
          <td> <apex:outputField value="{! Apartment__c.Terrace_Area_Cost__c }"/> </td>
          </tr> 
    </table>
    </apex:pageBlockSection>     
</apex:pageBlock>
</apex:form>
</apex:page>

it should show something like this
Hello all

I want to  send an automatic email when lead status is converted to "Qualified" , i tried it in workflow and process, it worked fine, now i want to try it in apex , i have ready made email template named "XXX" which shows as 

Hello {!Lead.LastName} 

Thank you for the registering with us 
Soon we will get back to you 

Team EduProserra

my apex class is

public class emailSending {

    public String Lead { get; set; }
    public string toMail { get; set;}
    public string ccMail { get; set;}
    public string repMail { get; set;}
    
    public void sendMail(){
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        string[] to = new string[] {toMail};
        string[] cc = new string[] {ccMail};
        
        email.setToAddresses(to);
        if(ccMail!=null && ccMail != '')
            email.setCcAddresses(cc);
        if(repmail!=null && repmail!= '')
            email.setInReplyTo(repMail);
        
        email.setSubject('Thank you for the Registration');
        
        email.setHtmlBody('Hello, {!Lead.LastName} <br/><br/>Thank you for Registration. <br/>We will get back to you for more details<br/><br/>Regards<br/> EduPro Team');
        try{
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }catch(exception e){
            apexpages.addmessage(new apexpages.message(apexpages.severity.error,e.getMessage()));
        }
        
        toMail = '';
        ccMail = '';
        repMail = '';
    }
}

how do i design a trigger for this??
Hello All

I need small assistance, i have been given an assignment of creating demo app on Education management, i have created several custom objects, one of them is Application (Application__c), now i am trying to create a form through visualforce page just like (web to lead or web to case) where whenever a candidate fills the form and clicks submit, all the information shoulld sit in a Application custom object, i tried building an vf page, but information is not coming to the salesforce, due i need to create apex class for this (extension)??  below is my vf code

<apex:page showHeader="false" sidebar="false">
<html>
        <body>
            <form action="https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8" method="POST" align="center">
                
                <input type="hidden" name="orgid" value="00B4P000005iNvBUAU"/>
                <input type="hidden" name="retURL" value="http://google.com"/>
                
                <style>

                               
                    input[type=text], select {
                    width: 50%;
                    padding: 12px 20px;
                    margin: 8px 0;
                    display: inline-block;
                    border: 1px solid #ccc;
                    border-radius: 4px;
                    box-sizing: border-box;        
                    
                    }
                    
                    input[type=submit] {
                    width: 50%;
                    background-color: DarkGray;
                    color: white;
                    padding: 14px 20px;
                    margin: 8px 0;
                    border: none;
                    border-radius: 4px;
                    cursor: pointer;
                    
                    
                    }
                    
                    body {
                    background-image: url("{!$Resource.Fromimage}");
                    background-position: 50% 300%;
                    background-repeat:repeat;
                    color: white;
                    }
                    
                </style>
                
                <br> <img style="width:20%;height:10%" src="{!$Resource.Prosera_Logo}"/></br>
            
            <frameset marginheight = "10"  marginwidth = "10" scrolling = "no">
                              
                <br><br><h2><font size="6"><b>Candidate Application Form</b></font></h2></br></br>
        <br></br>       
<p style="padding-right: 5px;font-size:20px;" align="Center">
    First Name* &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
    <input  id="00N1U00000TjzLa" maxlength="255" name="00N1U00000TjzLa" size="20" type="text" style="width:500px"/><br></br>

     Last Name* &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
    <input  id="00N1U00000TjzLa" maxlength="255" name="00N1U00000TjzLa" size="20" type="text" style="width:500px"/><br></br>
   Email * &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;
<input  id="00N1U00000TjzLp" maxlength="80" name="00N1U00000TjzLp" size="20" type="text"  style="margin-left: 47px;width:500px"/><br></br>

Phone * &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
<input  id="00N1U00000TjzLk" name="00N1U00000TjzLk" size="20"  type="text"  style="margin-left: 47px;width:500px" /><br></br>

Years of experience* &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;
<select  id="00N1U00000TjzOy" name="00N1U00000TjzOy" title="Years of experience" style="width:500px"><option value="">--None--</option><option value="Fresher">Fresher</option>
<option value="0-3 Years">0-3 Years</option>
<option value="3-5 Years">3-5 Years</option>
<option value="5-10 Years">5-10 Years</option>
</select><br></br>


Current Location* &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;
<input  id="00N1U00000TjzP3" maxlength="255" name="00N1U00000TjzP3" size="50" type="text" style="margin-left: 40px;width:500px"/><br></br>

Course Interested In &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
<select  id="00N1U00000TjzPr" multiple="multiple" name="00N1U00000TjzPr" title="Course Interested In" style="width:500px"><option value="VF">VF</option>
    <option value="Salesforce">Salesforce</option>
    <option value="Amazon Web Services">Amazon Web Services</option>
    <option value="Data Science">Data Science</option>
    <option value="Web Development">Web Development</option>
    <option value="Big Data">Big Data</option>  
</select><br></br>

<input type= "hidden" id="Origin" name="Origin" value="Web" />
<input type="submit" name="submit" style="width:500px"/>
</p>
</frameset>

</form>
</body>
</html>
</apex:page>these are the fields which i have designed in the custom object
Hello all 

My requirement is that whenever i change the status in the picklict field different color should pop up,
In my requirement i have picklist field called flat status, in that there are 3 fields (Sold,available,Booked), whenever i click on Sold it should show as "red", when i click on Available it should show as "Green", when i click on booked it should show as "Yellow"

for this i have tried formula field and written a formula as
IMAGE( 
CASE(Project_Status__c, 
"Green", "/img/samples/light_green.gif",
"Yellow", "/img/samples/light_yellow.gif",
"Red", "/img/samples/light_red.gif", 
"/s.gif"), 
"status color")

The error shows as " Error: Field Flat_Status__c is a picklist field. Picklist fields are only supported in certain functions"

Is there any better way to achive this

Any Help or suggestion would be Highly appreciated
 
Hello All  

I am new to the salesforce development domain,i am working on the intregration part, does someone have any idea on how to intregrate tally to salesforce and salesforce to tally.

Quick resonse would be highly appreciated
Hello all

I want to  send an automatic email when lead status is converted to "Qualified" , i tried it in workflow and process, it worked fine, now i want to try it in apex , i have ready made email template named "XXX" which shows as 

Hello {!Lead.LastName} 

Thank you for the registering with us 
Soon we will get back to you 

Team EduProserra

my apex class is

public class emailSending {

    public String Lead { get; set; }
    public string toMail { get; set;}
    public string ccMail { get; set;}
    public string repMail { get; set;}
    
    public void sendMail(){
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        string[] to = new string[] {toMail};
        string[] cc = new string[] {ccMail};
        
        email.setToAddresses(to);
        if(ccMail!=null && ccMail != '')
            email.setCcAddresses(cc);
        if(repmail!=null && repmail!= '')
            email.setInReplyTo(repMail);
        
        email.setSubject('Thank you for the Registration');
        
        email.setHtmlBody('Hello, {!Lead.LastName} <br/><br/>Thank you for Registration. <br/>We will get back to you for more details<br/><br/>Regards<br/> EduPro Team');
        try{
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }catch(exception e){
            apexpages.addmessage(new apexpages.message(apexpages.severity.error,e.getMessage()));
        }
        
        toMail = '';
        ccMail = '';
        repMail = '';
    }
}

how do i design a trigger for this??
Hello all

i am new to the vf, i am trying to populate the field values in a table format for the custom object, (i have not used Custom controllers)
how do i populate the field values in 2 columns like shown in the snapshot




below is my code

<apex:page standardController="Apartment__c" showHeader="false" renderAs="pdf" DocType="html">
<apex:form >
   <apex:pageBlock title="Appartment Details">
           <apex:pageBlockSection >
         <table style="width:100%">   
         <tr> 
          <td> <apex:outputField value="{! Apartment__c.Name }" /> </td>
          <td> <apex:outputField value="{! Apartment__c.Floor_No__c }"/> </td>
          <td> <apex:outputField value="{! Apartment__c.Phase__c }" /> </td>
         <td> <apex:outputField value="{! Apartment__c.Property_No__c }"/> </td>
         <td> <apex:outputField value="{! Apartment__c.Facing__c }" /> </td>
          <td> <apex:outputField value="{! Apartment__c.Terrace_Area_Cost__c }"/> </td>
          </tr> 
    </table>
    </apex:pageBlockSection>     
</apex:pageBlock>
</apex:form>
</apex:page>

it should show something like this
Hello all 

My requirement is that whenever i change the status in the picklict field different color should pop up,
In my requirement i have picklist field called flat status, in that there are 3 fields (Sold,available,Booked), whenever i click on Sold it should show as "red", when i click on Available it should show as "Green", when i click on booked it should show as "Yellow"

for this i have tried formula field and written a formula as
IMAGE( 
CASE(Project_Status__c, 
"Green", "/img/samples/light_green.gif",
"Yellow", "/img/samples/light_yellow.gif",
"Red", "/img/samples/light_red.gif", 
"/s.gif"), 
"status color")

The error shows as " Error: Field Flat_Status__c is a picklist field. Picklist fields are only supported in certain functions"

Is there any better way to achive this

Any Help or suggestion would be Highly appreciated