• hamza akouayri
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 6
    Replies
I have valid soql query returning zero results in apex class but it return expected results in developer console - FYI i have tried to running both context with sharing and without sharing  still no result. any idea 
@InvocableMethod(label='Get User info')
  public static List<userOutput> getUserLogedInInfo(List<userInput> inputParameters){
    
    List<userOutput> outputParameters = new List<userOutput>();
    userOutput outputParameter = new userOutput();
    String sEmail = inputParameters[0].sEmail;
    String sContact = null;
    String sUser = null;
    List <User> userList = [SELECT Id, FirstName, LastName, Email,ContactID FROM USER WHERE Email = :sEmail];
    System.debug('###### User####'+userList);
    
    if (userList.size()>0){
        sContact = userList[0].ContactId;
        System.debug('###### UserId####'+ userList[0].Id);
        List <AuthSession> auth = [SELECT Id, UsersId, IsCurrent FROM AuthSession WHERE IsCurrent = True AND UsersId = : userList[0].Id LIMIT 1];
        System.debug('###### auth####'+auth);        
        if (auth.size()>0){
            System.debug('i am here'+ outputParameter.sLogin);  
            outputParameter.sLogin = True;
        }
    }
    outputParameters.add(outputParameter);
    return outputParameters;
  }




 
there is any we can use userInfo.getUserId() in Apex InvocableMethod to get the actually running userId instead of automated process id?
I am trying to query only the users who are currently logged in to the org any idea? 
Hi All, 

I am just wondering what's the best approach to inject a login form authentication in chatbot 

Expectation: when end-user starts the chat the bot will prompt a login form to request the user to login before continuing 

FYI: chatbot lives on a community site as well I have the login form component and login page are already build  

i am calling apex email class from the flow with passing 4 parameters
User-added image
public with sharing class opportunityFulfillmentEmail {

@InvocableMethod 
public static void sentCsmEmail(List <flowInput> requests ) {
     
    
    flowInput req = requests[0];
    
    
      List<string> toAddress = new List<string>(req.primaryEmail);
      List<string> toCCAddress = new List<string>(req.CcEmail);
      ID conId = req.contactId;
    
    // Query the fields we need to merge 
      Opportunity opp = [SELECT Id, Billing_Contact_FirstName__c,Buying_Contact_FirstName__c 
                          FROM Opportunity 
                          WHERE Id=:req.oppId];
    // Query the email template
      EmailTemplate emailTemplate = [SELECT Id,Subject,Body,HtmlValue
                                      FROM EmailTemplate
                                      WHERE Id=:req.templateId
                                      LIMIT 1];
    // Process the merge fields  
      String plainBody = emailTemplate.Body;
      plainBody = plainBody.replace('{!Opportunity.Billing_Contact_FirstName__c}', opp.Billing_Contact_FirstName__c);                             
      plainBody = plainBody.replace('{!Opportunity.Buying_Contact_FirstName__c}', opp.Buying_Contact_FirstName__c); 
      
      String htmlBody = emailTemplate.HtmlValue;
      htmlBody = htmlBody.replace('{!Opportunity.Billing_Contact_FirstName__c}', opp.Billing_Contact_FirstName__c);
      htmlBody = htmlBody.replace('{!Opportunity.Buying_Contact_FirstName__c}', opp.Buying_Contact_FirstName__c);

    // Build the email message
      Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
     
      message.setTemplateID(emailTemplate.Id);
      message.setSubject(emailTemplate.Subject);
      message.setPlainTextBody(plainBody);
      message.setHTMLBody(htmlBody);
      message.setToAddresses(toAddress);          
      message.setCcAddresses(toCCAddress);
      message.setTargetObjectId(conId);
      
      Messaging.sendEmail(new Messaging.SingleEmailMessage[] { Message });


  }
  // Input details which comes to Apex class from flow 
 public class flowInput {

    @InvocableVariable(required=true)
    public List<string> primaryEmail;

    @InvocableVariable(required=true)
    public List<string> CcEmail;
    
    @InvocableVariable(required=true)
    public id oppId;

    @InvocableVariable(required=true)
    public id contactId;  

    @InvocableVariable(required=true)
    public id templateId;  

 }
I got this error even my list is not null 

User-added image
 
I am using this query to query all accounts with won opp and don't have an attachment (CombinedAttachments) related to them but I got these error when I try to filer with CombinedAttachments
INVALID_TYPE_FOR_OPERATION: entity type CombinedAttachment does not support query

SELECT Id, L11_Account_ID__c,Name,(SELECT Id, StageName FROM Opportunities WHERE StageName = 'Closed Won'),(SELECT ParentId,Title FROM CombinedAttachments) 
FROM Account 
Where Id IN (SELECT AccountId FROM Opportunity WHERE StageName = 'Closed Won') 
AND L11_Account_ID__c != null
AND Id NOT IN (SELECT ParentId FROM CombinedAttachment where record.Type ='Accounts') 

any suggestion to work around this 
Need to run a report to get all Accounts that has close won opportunities and don't have attachments related to them
i am not sure if i can approach this using report or SOQL

what is the best approach to use here

Thanks in Advance
Hello All,
I have two custom objects. project_c and week_c 
In Project_c.object  i have fileds start date and end date 
I want to create a trigger that will create records of weeks in week_c object based on start date and end date 
For example:
---------Project---------
start date : 10/02/2020
end date : 27/02/2020
----------week----------
week 9Feb
week 16Feb
week 23Feb
*PS (first day of the week will be sunday )

Thanks in Advance
 
I have valid soql query returning zero results in apex class but it return expected results in developer console - FYI i have tried to running both context with sharing and without sharing  still no result. any idea 
@InvocableMethod(label='Get User info')
  public static List<userOutput> getUserLogedInInfo(List<userInput> inputParameters){
    
    List<userOutput> outputParameters = new List<userOutput>();
    userOutput outputParameter = new userOutput();
    String sEmail = inputParameters[0].sEmail;
    String sContact = null;
    String sUser = null;
    List <User> userList = [SELECT Id, FirstName, LastName, Email,ContactID FROM USER WHERE Email = :sEmail];
    System.debug('###### User####'+userList);
    
    if (userList.size()>0){
        sContact = userList[0].ContactId;
        System.debug('###### UserId####'+ userList[0].Id);
        List <AuthSession> auth = [SELECT Id, UsersId, IsCurrent FROM AuthSession WHERE IsCurrent = True AND UsersId = : userList[0].Id LIMIT 1];
        System.debug('###### auth####'+auth);        
        if (auth.size()>0){
            System.debug('i am here'+ outputParameter.sLogin);  
            outputParameter.sLogin = True;
        }
    }
    outputParameters.add(outputParameter);
    return outputParameters;
  }




 
Need to run a report to get all Accounts that has close won opportunities and don't have attachments related to them
i am not sure if i can approach this using report or SOQL

what is the best approach to use here

Thanks in Advance
Hello All,
I have two custom objects. project_c and week_c 
In Project_c.object  i have fileds start date and end date 
I want to create a trigger that will create records of weeks in week_c object based on start date and end date 
For example:
---------Project---------
start date : 10/02/2020
end date : 27/02/2020
----------week----------
week 9Feb
week 16Feb
week 23Feb
*PS (first day of the week will be sunday )

Thanks in Advance