• Priyananth R
  • NEWBIE
  • 175 Points
  • Member since 2019

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 22
    Replies
trigger updateborrowerinbucket1 on Account (after insert, after update) {

set<id> setid = new set<id>();
list<bucket1__C> bucketlist = new list<bucket1__C>();

for(Account a : trigger.new){
setid.add(a.Bucket_1__c);

}

for(bucket1__c bb : [select id,name,Borrower_Name__c,(select id, name, Mobile_Number__c from Accounts__r)from bucket1__C]){

bucket1__C bb2 = new bucket1__C();
bb2.id=bb.id;
bb2.count_of_patients__c=bb.Accounts__r.size();
bb2.Borrower_Name__c=bb.Accounts__r.Name;

bucketlist.add(bb2);

}

update bucketlist;
}
  • May 25, 2019
  • Like
  • 0
Hi all, Help me please. 
I want display a field value of a Rich text area in a Visualforce as it is formated in the layout. The must important for me is to go on the next line like in the first screenshot. 
Here is my portion of code

<p style="border: 0.08px solid black;"> {!Container__c.General_Comments__c}</p>
User-added image
Hi,

I want to get 10 users last 10 days loginhistory using map collection.
I am trying with below code, But I am not getting expected result . please help me.
 
Map<Id,User> users =new Map<Id,User>([Select Id from User Limit 10]) ;
system.debug('Users-->'+users);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
for(String uIds : users.keySet()){
    loginDetals.put(uIds , [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK]);
	system.debug('put in map-->'+loginDetals);
    }
 
set<id> uIds= new set<id>();
for(User ac: [Select id from User limit 10]){
    uIds.add(ac.id);
}
system.debug('Users-->'+uIds);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
List<LoginHistory> LHList = [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK Limit 50000 ];
system.debug('Login Details-->'+LHList);
for(LoginHistory lh:LHList)
{    If(!loginDetals.ContainsKey(lh.UserId))
    {
        loginDetals.put(lh.UserId,new List<LoginHistory>{lh});
        system.debug('put in map-->'+loginDetals);
    }
}

please help me.
I am trying to send file as pdf via email. while opening the pdf in mail it is corrupted.
Below is my code.
ContentVersion doc = new ContentVersion();
string before = 'testing base 64';
Blob beforeblob = Blob.valueOf(before);
doc.Title = 'Attachemnt Test';
doc.PathOnClient = 'test5.pdf';
doc.VersionData = beforeblob;
insert doc;

Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('Test.pdf');
attach.setInline(false);
attach.Body = doc.VersionData;

//attach.body = EncodingUtil.base64Decode(jsonStr);

String email = 'abc@gmail.com';
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
mail.setToAddresses(new String[] { email });
mail.setSubject('Document Email Demo');
mail.setHtmlBody('Here is the email you requested: Test.pdf');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });

// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 
I want to get records of contact based on Birthdate.
eg: i need to display contact records in ASC order of next 60 days. so how to use GROUP BY CALENDAR_MONTH(Birthdate) ASC .
If I use GROUP BY Birthdate ASC It will return date in ascending order.

I am trying SOQL query like this
select id, name,PhotoUrl,Birthdate from Contact WHERE Birthdate != null AND Birthdate = NEXT_N_DAYS:60 ORDER BY CALENDAR_MONTH(Birthdate) ASC, DAY_IN_MONTH(Birthdate) ASC LIMIT 5 OFFSET 0

[object Object]: Ordered field cannot be aggregated in a query that is not grouped: CALENDAR_MONTH(Birthdate)

I need this solution through SOQL without using apex
Do you have any solution to sort birthdate based on month and date then please help me
I am trying to display a lightning table which contains contacts information like-
FirstName, Lastname , Email, Phone, Related Account.

I am asked to use wrapper class in apex controller. So, the issue that i am facing is that, I am getting recordID as Null.

here is the code that i am using for this task.

AssignComponent.cmp   -- Component
<aura:component controller='AccountsController' implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordID" access="global">
    <aura:handler name='init' value='{!this}' action ='{!c.doInit}'/>
    <aura:Attribute name='wrapperClass' type ='object'/>
    <aura:attribute name='contactList' type='List'/>
    
    <div class='slds-p-around--large'>
    	<h1 style='font-size:25px;'> Details of Contacts </h1>
    
    
    <table class='slds-table slds-table--bordered slds-table--cell-buffer'>
    	<thead>
        	<tr class='slds-text-title--caps'>
                <th scope='col'>
                	<div class='slds-truncate' title='First name'> First Name</div>
                </th>
                <th scope='col'>
                	<div class='slds-truncate' title='Last name'> Last Name</div>
                </th>
                <th scope='col'>
                	<div class='slds-truncate' title='Phone Number'> Phone Number</div>
                </th>
            </tr>
        </thead>
        <tbody>
        	<aura:iteration items="{!v.contactList}" var="con">
                <lightning:recordViewForm recordId="{!contact.Id}" objectApiName="Contact">
            	<th scope="row">
                	<div class="slds-truncate" title="{!con.FirstName}"></div>
                </th>
                <th scope="row">
                	<div class="slds-truncate" title="{!con.LastName}"></div>
                </th>
                <th scope="row">
                	<div class="slds-truncate" title="{!con.Phone}"></div>
                </th>
                </lightning:recordViewForm>
            </aura:iteration>
        </tbody>
    </table>
    </div>

</aura:component>

AssignComponentController.js ---- JS Controller
({
      doInit: function(component, event, helper) {
        // Fetch the account list from the Apex controller
        console.log('Inside Controller doInit method');
        helper.getAccountListHelper(component,event,helper);
        console.log('After helper call');
      }
    })

AssignComponentHelper.js -- Helper Method
({
      // Fetch the accounts from the Apex controller
      getAccountListHelper: function(component,event,helper) {
          console.log("Inside helper getAccountListHelper method");
          //call apex class method
          var action = component.get("c.getContacts");
          var a= component.get("v.recordID");
          //Here the recordID is getting null value//

          console.log("Record ID is: "+a);
          
          action.setParams({
              acctId : a
              
          });
          
          action.setCallback(this, function(response) {
              console.log('Inside setcallback method of helper');
              var state = response.getState();
              if(state === "SUCCESS"){
                  //set the wrapperClass attribute of component
                  //component.set('v.wrapperClass',response.getReturnValue());
                  var contactList = response.getReturnValue();
                  component.set("v.contactList",contactList);
                  console.log('Contact List>>>>'+contactList);
              console.log('values set successfully');
              }
          });
   		console.log('Exiting helper');
        $A.enqueueAction(action);
      }
    })

AccountController.apxc  ---- Apex class
public class AccountsController {
    @AuraEnabled
    public static List<Contact> getContacts(List<ID> acctId) {
    	WrapperClass  wc = new WrapperClass();
        List<Contact> contactList = [ select id ,firstName, lastName, phone
                                 from contact
                                where AccountID in :acctID];
         wc.conList=contactList;
        return contactList;
    }
    
    public class WrapperClass{
        @AuraEnabled
        public List<Contact> conList {get;set;}
        @AuraEnabled
        public Account accRecord {get; set;}
    }
        
      
}

AssignComponentApp.app
<aura:application extends="force:Slds">
    <c:AssignComponent/>
</aura:application>

The output on the console

Kindly Help me know where i am getting the things wrong.

Any help will be appreciated
trigger updateborrowerinbucket1 on Account (after insert, after update) {

set<id> setid = new set<id>();
list<bucket1__C> bucketlist = new list<bucket1__C>();

for(Account a : trigger.new){
setid.add(a.Bucket_1__c);

}

for(bucket1__c bb : [select id,name,Borrower_Name__c,(select id, name, Mobile_Number__c from Accounts__r)from bucket1__C]){

bucket1__C bb2 = new bucket1__C();
bb2.id=bb.id;
bb2.count_of_patients__c=bb.Accounts__r.size();
bb2.Borrower_Name__c=bb.Accounts__r.Name;

bucketlist.add(bb2);

}

update bucketlist;
}
  • May 25, 2019
  • Like
  • 0
I have several web-to-lead Salesforce forms throughout my website and have set up Google Tag Manager to track each form submission using the Form Submission Trigger. However, GTM is tracking every submission attempt whether or not the form successfully went through. So if someone missed a required field and clicks the submit button it still considers that a submission in GTM. Does anyone know how to set up "Check Vaildation" on web-to-lead Salesforce forms so it can track only the validated form submissions?

Can someone help me how to populate a combobox with Objects?
Please, I’m new to Lightning.

<lightning:combobox type="text" aura:id="object"
                                                                name="object"
                                                                placeholder="-Select-"
                                                                options="{!v.objects}"
                                                                onchange="{!c.handleChange}"/>
Hi all, Help me please. 
I want display a field value of a Rich text area in a Visualforce as it is formated in the layout. The must important for me is to go on the next line like in the first screenshot. 
Here is my portion of code

<p style="border: 0.08px solid black;"> {!Container__c.General_Comments__c}</p>
User-added image
Hi,

I want to get 10 users last 10 days loginhistory using map collection.
I am trying with below code, But I am not getting expected result . please help me.
 
Map<Id,User> users =new Map<Id,User>([Select Id from User Limit 10]) ;
system.debug('Users-->'+users);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
for(String uIds : users.keySet()){
    loginDetals.put(uIds , [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK]);
	system.debug('put in map-->'+loginDetals);
    }
 
set<id> uIds= new set<id>();
for(User ac: [Select id from User limit 10]){
    uIds.add(ac.id);
}
system.debug('Users-->'+uIds);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
List<LoginHistory> LHList = [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK Limit 50000 ];
system.debug('Login Details-->'+LHList);
for(LoginHistory lh:LHList)
{    If(!loginDetals.ContainsKey(lh.UserId))
    {
        loginDetals.put(lh.UserId,new List<LoginHistory>{lh});
        system.debug('put in map-->'+loginDetals);
    }
}

please help me.
Hi All,

 I am trying to push the lightning web component recipes to scratch org.
I have authorized the org, Devhub and created a scratch org.User-added image

I am not able to see the recipes in the scratch org.
User-added image
Please anyone can guide me where I am doing the mistake.
Thanks,
Sirisha
 
I want to provide hyperlink in the apex email body without displaying the url and html tag
message.subject = 'some subject';
emailBody += '<html><a href="'+URL.getSalesforceBaseUrl().toExternalForm()+'/'+someid+'">'+displayname+'</a></html>';

from the above code, I am able to get an email with hyperlink but the hyperlink is not only applied to the 'displayname'. The email body even has the html tag and the complete URL in the hyperlink.
How to provide the hyperlink only to displayname and hide the URL
  • March 31, 2019
  • Like
  • 0
Hi, 
I am struggling with sending a REST Callout from one Salesforce org to another. I am not able to get the access token. Here is my code snippet - 
** Callback url in the connected app on target org - https://<domainName>.my.salesforce.com/services/oauth2/token


String clientId = 'consumer key  from the connected app in the target org';
String clientSecret = 'consumer secret from the connected app in the target org';
String username = 'my username in the target org';
String password = 'my password in the target org';

HttpRequest req = new HttpRequest();
Http h = new Http();
String reqbody = 'grant_type=password&client_id='+ clientId + '&client_secret='+clientSecret + '&username=' + username + '&password='+ password;
req.setMethod('POST'); 
req.setEndpoint('https://test.salesforce.com/services/oauth2/token'); 
HttpResponse res = h.send(req); 
System.debug(res.getBody()); 
deserializeResponse der = (deserializeResponse) JSON.deserialize(res.getBody(), deserializeResponse.class);
String accessToken = der.access_token;
**** I get an error Here - {"error":"invalid_grant","error_description":"authentication failure"}

HttpRequest req2 = new HttpRequest(); 
req2.setEndpoint('https://<domainName>.my.salesforce.com/services/apexrest/<RestResourceClassName>/<HttpPost method name>'); 
req2.setHeader('Authorization','Bearer ' + accessToken); 
req2.setHeader('Content-Type', 'application/json');
req2.setMethod('POST'); 
req2.setBody( body ); 
Http h2 = new Http(); 
HttpResponse res2 = h2.send(req2);
**** Second callout error is as a result of null access token i believe  - [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
 
  • March 31, 2019
  • Like
  • 0
I am working on apex class and visualforce page where I want to group records by Name and sum of hours but I am getting the below error.
"Illegal assignment from List<AggregateResult> to List<Time__c>"
Can anyone help me out in this issue,My code is below
public class RolesFetch {
        public list<Time__c> projectrole { get; set; }
    
    public datetime startdate1;
    public datetime enddate1;
   public Time__c a { get; set; } 
    public RolesFetch(){
     projectrole=new list< Time__c>();
    a=new Time__c();
     
    }
    public PageReference Fetch() {
    startdate1=a.From_Date__c;
    enddate1=a.To_Date__c;
    projectrole=[select Role__c,SUM(Hourly_Rate__c),Date__c,SUM(Hours__c),SUM(Billable_Dollars__c) from Time__c GROUP BY Role__c,Date__c HAVING Date__c>=:startdate1.date() AND Date__c<=:enddate1.date() ];
    return null;
    }

}
My VF Page
<apex:page controller="RolesFetch">
 <apex:form id="dt1">
 <apex:pageBlock >
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <apex:outputLabel >Start Date</apex:outputLabel>
 <apex:inputfield value="{!a.From_Date__c}"/>
</apex:pageBlockSectionItem>
 <apex:pageBlockSectionItem >
 <apex:outputLabel >End Date</apex:outputLabel>
 <apex:inputField value="{!a.To_Date__c}"/>
 </apex:pageBlockSectionItem>
  
<apex:commandButton value="Fetch" action="{!Fetch}" reRender="dt"/>
 
</apex:pageBlockSection>
 <apex:pageBlockTable value="{!projectrole}" var="pr" id="dt">
<apex:column headerValue="Role Name">
<apex:outputText value="{!pr.Role__c}" />
</apex:column>
<apex:column headerValue="Rate">
  <apex:outputText value="{!pr.Hourly_Rate__c}"/>
  </apex:column>
     <apex:column headerValue="Hours">
     <apex:outputText value="{!pr.Hours__c}"/>
     </apex:column>
     <apex:column headerValue="Sum">
  <apex:outputText value="{!pr.Billable_Dollars__c}"/>
  </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
 </apex:form>
</apex:page>


 
Hi, 

When do you go for a Workflow and when do you go for Trigger? How do you decide?

Can any one help me.

Thanks.
I am trying to send file as pdf via email. while opening the pdf in mail it is corrupted.
Below is my code.
ContentVersion doc = new ContentVersion();
string before = 'testing base 64';
Blob beforeblob = Blob.valueOf(before);
doc.Title = 'Attachemnt Test';
doc.PathOnClient = 'test5.pdf';
doc.VersionData = beforeblob;
insert doc;

Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('Test.pdf');
attach.setInline(false);
attach.Body = doc.VersionData;

//attach.body = EncodingUtil.base64Decode(jsonStr);

String email = 'abc@gmail.com';
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
mail.setToAddresses(new String[] { email });
mail.setSubject('Document Email Demo');
mail.setHtmlBody('Here is the email you requested: Test.pdf');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });

// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 
AND(
          ISPICKVAL(Warranty__c, "External"),
          OR(
                  ISBLANK(TEXT(Repairer__c)),
                  ISBLANK(NUMBER(Total_Price__c)),
                  ISBLANK(DATE(Invoice_Paid_Date__c)),

OR(
AND 

              ISPICKVAL(Warranty__c, "Internal"),
          OR(
                   ISBLANK(TEXT(Repairer__c)),
                   ISBLANK(NUMBER(Total_Price__c))
            )
))))

I am getting error as 
Error: Incorrect parameter type for function 'TEXT()'. Expected Number, Date, DateTime, Picklist, received Text

Need assistance
Hello Everyone

I got an issue when firing the below event from Helper, and is working fine in controller in Lightning Component. Any hints?
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
            "entityApiName": "Account" // using account standard object for this sample
        });
 createRecordEvent.fire();

 
I want to get records of contact based on Birthdate.
eg: i need to display contact records in ASC order of next 60 days. so how to use GROUP BY CALENDAR_MONTH(Birthdate) ASC .
If I use GROUP BY Birthdate ASC It will return date in ascending order.

I am trying SOQL query like this
select id, name,PhotoUrl,Birthdate from Contact WHERE Birthdate != null AND Birthdate = NEXT_N_DAYS:60 ORDER BY CALENDAR_MONTH(Birthdate) ASC, DAY_IN_MONTH(Birthdate) ASC LIMIT 5 OFFSET 0

[object Object]: Ordered field cannot be aggregated in a query that is not grouped: CALENDAR_MONTH(Birthdate)

I need this solution through SOQL without using apex
Do you have any solution to sort birthdate based on month and date then please help me