• yogesh_patil
  • NEWBIE
  • 83 Points
  • Member since 2016
  • Consultant
  • Deloitte

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 22
    Replies
Hi,

I am trying to Save an Apex Class. Please see below:

public class clsHelpSalesStages{
  
  public List<OpportunityStage> getSalesStages(){
    
    List<OpportunityStage> lstOppStage = [ SELECT MasterLabel, 
                           IsClosed,
                           IsWon, 
                           ForecastCategory, 
                           ForecastCategoryName, 
                           DefaultProbability, 
                           Description
                    FROM OpportunityStage
                    WHERE IsActive = true
                    ORDER BY SortOrder ASC ];
    return lstOppStage;
  }
  
  public static testMethod void testMyController(){ 
    clsHelpSalesStages objOppStage = new clsHelpSalesStages();
    List<OpportunityStage> lstOppStageTest = objOppStage .getSalesStages();
  
    System.assert( lstOppStageTest.size() > 0 );
  }
}

But I am getting the following error message: Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 18 column 33

The Apex Class is used to show Opportunity Stages Description on the Home Page.

I can see that - The testMethod keyword is now deprecated, so therefore the error. 

I have tried to use @isTest, but it didn't work.

I've never created an Apex Class before, unfortunately, so I am unable to correct the error message.

Could you please let me know what should I correct?


Thanks.
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, bucket1associatetobucket2: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: a14p000000275tEAAQ Trigger.bucket1associatetobucket2: line 35, column 1: []

Bucket1__c is parent and Bucket_2__c is child.Iam trying to create buckel1 record and when borower_name__c is null , then create bucket_2__C record and associate it with parent which is bucket1__c.
​​​​​​​Please help to solve this error.

Please find my code below :-

trigger bucket1associatetobucket2 on Bucket1__c (after insert) {
  map<string,id> conEmailVsId = new map<string,id>();
List<Bucket_2__c> newbuck2 = new list<Bucket_2__c>();
    if(Trigger.isAfter && Trigger.isInsert) {
            for(Bucket1__c a1:trigger.new){
if(a1.Borrower_Name__c == null){

Bucket_2__c bb = new Bucket_2__c();
bb.id=a1.id;
bb.Addhar_Number__c = a1.Aadhar_Number__c;
bb.Name=a1.Name;
newbuck2.add(bb);
system.debug('values in newbuck2'+newbuck2);
}
    
    }
    if(newbuck2.size()>0){
    insert newbuck2;
    
    }
}
}
  • May 26, 2019
  • Like
  • 0
Hi I have completed integartion of Salesforce with google home where by I create accounts in salesforce by giving commands from google home.

On similar lines is there a way by which I can integrate google home with salesforce einstein?
Hello ALL.
I am able to test the scenario as defined in the Apex specialist badge. However I am facing the below error:

Challenge Not yet complete... here's what's wrong: 
Inserting a new Maintenance Request of type 'Routine Maintenance' and then closing it did not create of a new Maintenance Request based upon the original record correctly. The challenge is expecting to find the closed Maintenance Request plus an 'New' Maintenance Request of type 'Routine Maintenance' with the same Vehicle as the closed one.


PFB the code for reference:

public with sharing class MaintenanceRequestHelper {
    
    public static Map<Id,List<Work_Part__c>> mapCaseIdToListWorkParts = new Map<Id,List<Work_Part__c>>();
    public static Map<Id,Case> mapParentCaseRecordToNewCaseRecord = new Map<Id,Case>();
    public static boolean flag = false;
    
    public static void createMaintenanceRequest(List<Case> newList,Map<Id,Case> oldMap,Map<Id,Case> newMap)
    {
        List<Case> listMaintenanceRequest = new List<Case>();
        Set<String> setCaseId = new Set<String>();
        Map<Id,Integer> mapCaseIdToDueDate = new Map<Id,Integer>();
        for(Case objCase : newList)
        {
            if(objCase.Status!=oldMap.get(objCase.Id).Status && 
               objCase.Status == 'Closed' &&
               (objCase.Type=='Repair' || objCase.Type=='Routine Maintenance' ))
            {
                /**/
                setCaseId.add(objCase.Id);
            }
        }
        if(!setCaseId.isEmpty())
        {
            //List<Work_Part__c> listWorkPart = listWorkPart(setCaseId);
            mapCaseIdToDueDate = createMapOfCaseIdToDueDate(setCaseId);
            System.debug('mapCaseIdToDueDate '+mapCaseIdToDueDate);
            for(Id caseId : newMap.keySet())
            {
                if(setCaseId.contains(caseId))
                {
                    Case objCase = newMap.get(caseId);
                    Case newMaintenanceRequest = new Case(Type='Routine Maintenance',
                                                          Subject='Routine Maintenance',
                                                          Origin= objCase.Origin,
                                                          Status = 'New',
                                                          AccountId = objCase.AccountId,
                                                          AssetId = objCase.AssetId,
                                                          ContactId = objCase.ContactId,
                                                          Vehicle__c = objCase.Vehicle__c,
                                                          Equipment__c = objCase.Equipment__c,
                                                          ParentId = objCase.Id,
                                                          Report_Date__c = System.today(),
                                                          Due_Date__c = Date.today().addDays(mapCaseIdToDueDate.get(caseId)));   
                    
                    listMaintenanceRequest.add(newMaintenanceRequest);
                    mapParentCaseRecordToNewCaseRecord.put(objCase.Id,newMaintenanceRequest);
                }
            }    
        }
        
        if(!listMaintenanceRequest.isEmpty())
        {
            insert listMaintenanceRequest;
            flag = true;
        }
        associateOldWPToNewCase(mapCaseIdToListWorkParts,mapParentCaseRecordToNewCaseRecord);
    }
    
    private static Map<Id,Integer> createMapOfCaseIdToDueDate(Set<String> setCaseId)
    {
        Map<Id,Integer> mapCaseIdToDueDate = new Map<Id,Integer>();
        
        for(Work_Part__c objWP:[SELECT Id,Maintenance_Cycle__c,Maintenance_Request__c 
                                FROM Work_Part__c 
                                WHERE Maintenance_Request__c IN: setCaseId])
        {
            if(!mapCaseIdToListWorkParts.containsKey(objWP.Maintenance_Request__c))
            {
                mapCaseIdToListWorkParts.put(objWP.Maintenance_Request__c, new List<Work_Part__c>{objWP});
            }
            if(mapCaseIdToListWorkParts.containsKey(objWP.Maintenance_Request__c))
            {
                List<Work_Part__c> listWP = mapCaseIdToListWorkParts.get(objWP.Maintenance_Request__c);
                listWP.add(objWP);
                mapCaseIdToListWorkParts.put(objWP.Maintenance_Request__c,listWP);
            }
            
            if(!mapCaseIdToDueDate.containsKey(objWP.Maintenance_Request__c))
            {
                mapCaseIdToDueDate.put(objWP.Maintenance_Request__c, (Integer)objWP.Maintenance_Cycle__c);
            }
             if(mapCaseIdToDueDate.containsKey(objWP.Maintenance_Request__c))
            {
                if(mapCaseIdToDueDate.get(objWP.Maintenance_Request__c)<objWP.Maintenance_Cycle__c)
                {
                    mapCaseIdToDueDate.put(objWP.Maintenance_Request__c, (Integer)objWP.Maintenance_Cycle__c);
                }
            }
        }
        System.debug('mapCaseIdToListWorkParts '+mapCaseIdToListWorkParts);
        System.debug('mapCaseIdToDueDate '+mapCaseIdToDueDate);
        
        return mapCaseIdToDueDate;
    }
    
    private static void associateOldWPToNewCase(Map<Id,List<Work_Part__c>> mapCaseIdToListWorkParts,Map<Id,Case> mapParentCaseIdToNewCaseRecord)
    {
        Set<Work_Part__c> setWP = new Set<Work_Part__c>();
        if(flag)
        {
            for(Id caseId : mapParentCaseIdToNewCaseRecord.keySet())
            {
                for(Work_Part__c objWP : mapCaseIdToListWorkParts.get(caseId))
                {
                    objWP.Maintenance_Request__c = mapParentCaseIdToNewCaseRecord.get(caseId).Id;
                    setWP.add(objWP);
                }
            }    
        }
        List<Work_Part__c> listWP = new List<Work_Part__c>(setWP);
            
        if(!listWP.isEmpty())
        {
            update listWP;
        }
        
    }    
}
/**********APP CODE ********/
<aura:application >
    <c:AccountDisplayComponent />
</aura:application>

/********** COMPONENT CODE*************/

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="AccControllerClass">
    <aura:handler name="init" action="{!c.getResults}" value="{!this}" />
    <aura:attribute name="strAccountName" type="Account" default="{'sobjectType':'Account',
                                                                  'Name':''}"/>
    <div class="Text">
        <ui:inputText aura:id="AccountId" label="Account Name" />
    </div>
    <div>
        <ui:Button label="Click Me!" press="{!c.getResults}"/>
    </div>    
</aura:component>


/************ CONTROLLER CODE **************/

({
    getResults : function(component, event) {
        var newAccount= component.find("AccountId").get("v.value");
        var action= component.get("c.saveAccount");
        alert(''+newAccount);
        alert(''+action);
        alert(action.getState());
        
        action.setParams({
            "acc" :newAccount
        });
        
   action.setCallback(this,
            
       function(response){            
           component.set("v.strAccountName",response.getReturnValue());            
           alert(response.getReturnValue());    
             alert('Hello');
                var name = response.getReturnValue();
                alert(name);
                 var state = response.getState();
                alert(state);
                 if (state == "SUCCESS" || response.getState() == "ERROR") {
                        var name = response.getReturnValue();
                     alert(name);
                     alert(action.getReturnValue());
                     console.log(action.getReturnValue());
                        alert("hello from here"+name);
                 }
        });
        
        $A.enqueueAction(action);
    }
})

/******APEX CONTROLLER **********/

public with sharing class AccControllerClass {

    @AuraEnabled
    public static Account saveAccount(Account acc){
        System.debug('@@acc'+acc);
        List<Account>  listAccount =new List<Account>();
        listAccount.add(acc);
        insert listAccount;
        return acc;
    }
    
}

Whenever I amclicking on the convert button i am geting this error..

please help....

My visualforce code

<apex:page standardController="Lead" extensions="LeadConvertClass">    
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Convert" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Convert Lead">
                <apex:selectList value="{!strCompanyName}" label="Account Name" size="1">
                    <apex:selectOptions value="{!CompanyNames}" />
                </apex:selectList>
                <apex:inputField value="{!objOpportunity.Name}"/> 
                <apex:inputField value="{!objLead.Status}" />
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Task Information">
                <apex:inputField value="{!objTask.Subject}"/>
                <apex:inputField value="{!objTask.Status}" />
                <apex:inputField value="{!objTask.priority}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField value="{!objLead.Description}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Reminder">
              <!--  <apex:inputField value="{!objLead.ReminderDateTimeId}"/> -->
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Apex Code

public class LeadConvertClass {

    public LeadConvertClass(ApexPages.StandardController controller) {
    
        objLead  =new Lead();
        objContact =new Contact();
        objAccount =new Account();
        objOpportunity =new Opportunity();
        listCompanyNames =new List<SelectOption>();
    //    listCompanyNames.add(new SelectOption('USA','USA'));
    //    listCompanyNames.add(new SelectOption('IND','IND'));
        strId=apexpages.currentpage().getparameters().get('id');
        System.debug('@@@strId'+strId);
        objLead.status='Closed-Converted';
    
    }


   
    public Lead objLead {get ; set ;}
    public Contact objContact {get ; set ;}
    public Account objAccount {get ; set ;}
    public Opportunity objOpportunity {get ; set ;}
    public Task objTask {get ; set ;} 
    public List<SelectOption> listCompanyNames {get ; set ;}
    public String strCompanyName {get ; set ;}
    public String strId;
    public String strLeadCompany;
    public String strQuery;
    
    public List<SelectOption> getCompanyNames(){
    Lead objLead =[Select id,Company from Lead where id =:strId];
    strQuery ='Select name from Account where name LIKE \'%'+objLead.Company+'%\'';
    List<Account> listAccount=database.query(strQuery);
    listCompanyNames.add(new SelectOption('none','none'));
    listCompanyNames.add(new SelectOption('Create New Account :'+objLead.Company,'Create New Account :'+objLead.Company));
    if(listAccount!=null){
    for(Account objAccount:listAccount)
    {    
         listCompanyNames.add(new SelectOption(objAccount.name,objAccount.name));   
    }
   
   }        
    objOpportunity.Name=objLead.Company;
    return listCompanyNames;
    }
    
    public PageReference save()
    {
        System.debug(strId);
        System.debug(objOpportunity.name);
        System.debug(objAccount.name);
        System.debug(objLead.Status);
        if(strCompanyName!=null){
            insert objAccount;        
        }
        objContact.AccountId=objAccount.id;
        insert objOpportunity;
        update objLead;
        return null;
    }
}


### 

Error: Value 'Call' cannot be converted from Text to core.apexpages.el.adapters.metadata.VFSObjectELAdapter*

This Error is visible under Subject Field















 

Hi,
I want to integrate facebook account with my developer org 
so if any cases posted to my facebook wall could be captured in my org..
this is my visualforce code...
Actually i want to show the loading image button on click of upload attachment  button
On click of select Attachment the apex method is being called which makes the page to rfresh...
i want to avoid the page refresh...
and rerender cannot be used on <apex:inputfile>
////////visualforce code /////////

<apex:page standardController="Account" extensions="extendAccountforstandardController">
<apex:form id="frm">
<apex:pageBlock >
<apex:pageblockSection >
<apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}"/> 
</apex:pageblockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:actionRegion >
<apex:pageBlock id="pgBlkId" >
<apex:pageBlockSection >
<apex:inputField value="{!objAccount.parentid}"/>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:outputpanel id="image">
<apex:commandButton action="{!attachRecord}" value=" upload attachment" reRender="image" status="actStatusId" />
</apex:outputpanel>
 <apex:actionStatus id="actStatusId" >
<apex:facet name="start"  >
<img src="/img/loading.gif" />                    
</apex:facet>
</apex:actionStatus> 
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>

///// Apex Code

public class extendAccountforstandardController {

    public PageReference attachRecord() {
    
    System.debug('@@objAccount.id'+objAccount.id);
    
     System.debug('@@objAccount.parentId'+objAccount.parentId);
      
      objAttachment.parentId=objAccount.parentId;
      objAttachment.body=bodyAttachment;
      objAttachment.name=nameAttachment;
      
      if(objAccount.parentid!=null){    
        
            insert objAttachment;
        
        }
        return null;
    }

    public blob bodyAttachment;
    
    public string nameAttachment;
    
    public Account objAccount { get; set; }

    public Attachment objAttachment {get; set;}
    
    public extendAccountforstandardController(ApexPages.StandardController controller) {

        objAccount =new Account();
        objAttachment=new Attachment();

    }
    
    public void selectAttachment(){
    bodyAttachment=objAttachment.body;
    nameAttachment=objAttachment.name;
    System.debug(''+'@@nameAttachment'+nameAttachment);
    }
}

 
We are facing an issue with respect to Health Cloud package for Registration API. Whenever we hit the Registration API, we insert a household account, contact, user and the Account Contact Relationship. While we insert account/contact using Registration API in the scope of Guest User we encounter the below error:

You don't have the level of access required to complete this action. Please contact your administrator for help.

We didn’t found any documentation associated with this trigger implementation. We have provided all object access, FLS for account, contact objects, Access to API for guest user. Also, the error message generated is not due to custom code of Registration API but from the code in HealthCloudGA.AccountTrigger.
 

We are upgrading our salesforce development to make it compatible with lightning. 

In a few cases, we just need to open a visual force page on click of a button. We implemented this via script "window.open = {url}" using "on click of javascript" option. 

Is it mandatory to use aura components to open up the page? Or directly opening up a new visual force page on click of a button will be good?

I understand both will work, but what is the best way to handle this?

OrderItem object is a junction of Order and a product.
It has 2 lookup fields , 1 for Order (API : OrderId) and 1 for Product (API : Product2Id)
But when we try to create record of OrderItem it throws error Product2Id field does not exists.
Instead it's accepting "PricebookEntryId".
As per scheme it should accept Product Id and not the pricebookEntry Id.
I am new to sales force

My trigger is for the Lead , PFB for the Trigger

trigger HelloWorld on Lead (before update) {
    for (Lead l : Trigger.new){
        l.FirstName = 'Hello';
        l.LastName = 'World';
    }


once after saving this when i go to lead and just select the record. immediately the f.name and l.name is getting changed to Hello world.... i have not even done any changes more over didnt click on the save button also..

To my understanding trigger shuld execute only if i make any change in the record or even while just viewing the record by clicking on its name itself will the trigger gets executed as it is a before trigger
Hi ,
I have written a simple after insert trigger on Account such that for every new Account created, a new related Opportunity is created.

But the trigger is not getting invoked.Any ideas why this may be happening

trigger CreateNewAccountOpportunity on Account (after insert) {

    List<Opportunity> oppList = new List<Opportunity>();
    for(Account acc : Trigger.new){
        Opportunity opp = new Opportunity();
        opp.Name = acc.Name;
        opp.StageName = 'Proposal';
        opp.CloseDate = System.today() + 30;
        oppList.add(opp);
    }
    System.debug('@@@---->'+Trigger.new);
       System.debug('oppList---->'+oppList); 
    
    if(oppList.isEmpty() == false){
        Database.insert(oppList);
    }
}
We have added related cases section on the case page layout and users are adding/linking the many cases to the case.

Now I need to fetch all those cases which are having the related cases. How to get the cases list along with the related cases details.

Good Afternoon,

 

I've 3 objects namely- Doctor, Patient, Doctor-Patient , where Doctor & Patient have a lookup relationship but Doctor-Patient doesn't have any relationship with the 2 objects.

Requirement is that I'e to update/auto-populate the fields of Doctor-Patient fields whenever Patients fields are inserted.

I can't write a Trigger, & workflow will not work for this . HOw can I write a process using Process Builder?

Please help me out with this.

 

Thanks & Regards,

Harsha Deepthi K.

Hi,

I have a short, general question regarding collection types for sObjects when it comes to inline SOQL queries. 

As we all know there are three collection types: Lists, Sets and Maps. I recently stumbled upon a Trailhead Project (https://trailhead.salesforce.com/content/learn/projects/quickstart-apex/quickstart-apex-2) where neither of these types where used in a method to retrieve a list of records using an SOQL query:
Account[] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
I'm talking about the Account[] part of the code. Can someone explain to me what makes the [] type  different from the List type? How does it behave and what are the particular use cases? When to use Account[] and when to use List<Account>?

I guess one could have also go for this option:
List<Account> oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
Any help appreciated! 

Best,
David
Hi,

I am trying to Save an Apex Class. Please see below:

public class clsHelpSalesStages{
  
  public List<OpportunityStage> getSalesStages(){
    
    List<OpportunityStage> lstOppStage = [ SELECT MasterLabel, 
                           IsClosed,
                           IsWon, 
                           ForecastCategory, 
                           ForecastCategoryName, 
                           DefaultProbability, 
                           Description
                    FROM OpportunityStage
                    WHERE IsActive = true
                    ORDER BY SortOrder ASC ];
    return lstOppStage;
  }
  
  public static testMethod void testMyController(){ 
    clsHelpSalesStages objOppStage = new clsHelpSalesStages();
    List<OpportunityStage> lstOppStageTest = objOppStage .getSalesStages();
  
    System.assert( lstOppStageTest.size() > 0 );
  }
}

But I am getting the following error message: Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 18 column 33

The Apex Class is used to show Opportunity Stages Description on the Home Page.

I can see that - The testMethod keyword is now deprecated, so therefore the error. 

I have tried to use @isTest, but it didn't work.

I've never created an Apex Class before, unfortunately, so I am unable to correct the error message.

Could you please let me know what should I correct?


Thanks.
How to convert the folloeing nested for loop using map.
as it a id, list . how to assign values.
public class SLAandAgeOverSLA {
    public void calculatetime(List<Case> caseids,Map<id,case> casemap){
         
        List<CaseMilestone> milestonelist = [select caseId,id,isCompleted,MilestoneTypeId,StartDate,TargetDate,BusinessHoursId,MilestoneType.name,CompletionDate from 
                                             CaseMilestone where(MilestoneType.name='First Response' or MilestoneType.name='Technical Resolution') 
                                             AND isCompleted=true AND caseid IN:caseids]; 
                                             
        map<string,List<CaseMilestone>> milestonemap = new map<string,List<CaseMilestone>>();
        for(CaseMilestone ml: milestonelist ){
            
            if(milestonemap.get(ml.caseId)==null){
                List<CaseMilestone> mtList=new List<CaseMilestone>();
                mtList.add(ml);
                milestonemap.put(ml.CaseId,mtList);
            }else if(milestonemap.get(ml.caseId)!=null){
                List<CaseMilestone> mtList=milestonemap.get(ml.caseId);
                mtList.add(ml);
            }
        }
        for(Case c: caseids){
            if(c.Request_for_Closure_Date__c!=null && milestonemap.containskey(c.id) ){
            
                for(CaseMilestone ml:milestonemap.get(c.id)){
                
                    if(ml.MilestoneType.name=='First Response'){
                        c.Test_Ignore__c = ml.CompletionDate;
                    }
                    else if(ml.MilestoneType.name=='Technical Resolution'){
                        c.Test_Ignore_2__c = ml.CompletionDate;
                    }
                }
            }
        }
    }
}
using trigger i have to do scenario 1.create a formula filed domain on lead 2. so, if email filed on lead is abc@xyz.com- domain will be xyz. 3 insert a new lead-take the domain and search system with the  same  domain for existing lead.4. if match found take most recent modified lead and take owner from that lead and assign the same owner to new lead .

plzz let meknow using trigger
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, bucket1associatetobucket2: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: a14p000000275tEAAQ Trigger.bucket1associatetobucket2: line 35, column 1: []

Bucket1__c is parent and Bucket_2__c is child.Iam trying to create buckel1 record and when borower_name__c is null , then create bucket_2__C record and associate it with parent which is bucket1__c.
​​​​​​​Please help to solve this error.

Please find my code below :-

trigger bucket1associatetobucket2 on Bucket1__c (after insert) {
  map<string,id> conEmailVsId = new map<string,id>();
List<Bucket_2__c> newbuck2 = new list<Bucket_2__c>();
    if(Trigger.isAfter && Trigger.isInsert) {
            for(Bucket1__c a1:trigger.new){
if(a1.Borrower_Name__c == null){

Bucket_2__c bb = new Bucket_2__c();
bb.id=a1.id;
bb.Addhar_Number__c = a1.Aadhar_Number__c;
bb.Name=a1.Name;
newbuck2.add(bb);
system.debug('values in newbuck2'+newbuck2);
}
    
    }
    if(newbuck2.size()>0){
    insert newbuck2;
    
    }
}
}
  • May 26, 2019
  • Like
  • 0
Hi everybody!

My team and I are developing a Google Home 'application' for a company that uses salesforce. Now they asked us if it was possible to make a connection between the app and salesforce. They want to us to create a case from the Google Home. As far as I can see this should be doable, although I am quite new to SalesForce and it is a lot to take in :'-).

So far our plan is to connect the application via Oauth to our backend and if we get a request to make a new case from the user to sent this to SalesForce using the REST api. However we are still struggling how to best identify for which user the event should be made. The current plan is to add gmail accounts to salesforce so we can just sent the gmail account connected to the Google Home to match it.

Are there any suggestions you guys have on this plan and some general tips on best (and safe) practices. Anything would be appreciated, even if it would mean changing the whole plan!

Thanks in advance!

Tijs
Hi Team,
Would like to know if there is a way where we can block emails to create cases in Salesforce if it triggered from 3rd party systems lower tenants.

3rd party lower tenant email address are: (xxx represents the domian name.)
Test1@xxx.com
Test2@xxx.com
Test3@xxx.com
Test4@xxx.com
Test5@xxx.com
.
.
Test25@xxx.com

Earlier 3rd party system had only 1 lower tenant email address, hence we wrote a validation rule to block the case creation.
Formula: AND(NOT(ISNULL(SuppliedEmail)),CONTAINS(SuppliedEmail,'Test1@xxx.com'))

Would like to know how to handle bulk the email addresses which changes based on 3rd paty system lower tenants number to block case creation. The common thing is this 3rd party lower tenant is the from address increases based on there tenant name.. Test1, Test2 ...... and ends with their unique domain name 'xxx.com'

Note: We can not put the STARTS with condition because there are other 3rd parties system are there where the email address is strating with Test.. 

A sample code snippet would be helpful.

Thanks !
Hello ALL.
I am able to test the scenario as defined in the Apex specialist badge. However I am facing the below error:

Challenge Not yet complete... here's what's wrong: 
Inserting a new Maintenance Request of type 'Routine Maintenance' and then closing it did not create of a new Maintenance Request based upon the original record correctly. The challenge is expecting to find the closed Maintenance Request plus an 'New' Maintenance Request of type 'Routine Maintenance' with the same Vehicle as the closed one.


PFB the code for reference:

public with sharing class MaintenanceRequestHelper {
    
    public static Map<Id,List<Work_Part__c>> mapCaseIdToListWorkParts = new Map<Id,List<Work_Part__c>>();
    public static Map<Id,Case> mapParentCaseRecordToNewCaseRecord = new Map<Id,Case>();
    public static boolean flag = false;
    
    public static void createMaintenanceRequest(List<Case> newList,Map<Id,Case> oldMap,Map<Id,Case> newMap)
    {
        List<Case> listMaintenanceRequest = new List<Case>();
        Set<String> setCaseId = new Set<String>();
        Map<Id,Integer> mapCaseIdToDueDate = new Map<Id,Integer>();
        for(Case objCase : newList)
        {
            if(objCase.Status!=oldMap.get(objCase.Id).Status && 
               objCase.Status == 'Closed' &&
               (objCase.Type=='Repair' || objCase.Type=='Routine Maintenance' ))
            {
                /**/
                setCaseId.add(objCase.Id);
            }
        }
        if(!setCaseId.isEmpty())
        {
            //List<Work_Part__c> listWorkPart = listWorkPart(setCaseId);
            mapCaseIdToDueDate = createMapOfCaseIdToDueDate(setCaseId);
            System.debug('mapCaseIdToDueDate '+mapCaseIdToDueDate);
            for(Id caseId : newMap.keySet())
            {
                if(setCaseId.contains(caseId))
                {
                    Case objCase = newMap.get(caseId);
                    Case newMaintenanceRequest = new Case(Type='Routine Maintenance',
                                                          Subject='Routine Maintenance',
                                                          Origin= objCase.Origin,
                                                          Status = 'New',
                                                          AccountId = objCase.AccountId,
                                                          AssetId = objCase.AssetId,
                                                          ContactId = objCase.ContactId,
                                                          Vehicle__c = objCase.Vehicle__c,
                                                          Equipment__c = objCase.Equipment__c,
                                                          ParentId = objCase.Id,
                                                          Report_Date__c = System.today(),
                                                          Due_Date__c = Date.today().addDays(mapCaseIdToDueDate.get(caseId)));   
                    
                    listMaintenanceRequest.add(newMaintenanceRequest);
                    mapParentCaseRecordToNewCaseRecord.put(objCase.Id,newMaintenanceRequest);
                }
            }    
        }
        
        if(!listMaintenanceRequest.isEmpty())
        {
            insert listMaintenanceRequest;
            flag = true;
        }
        associateOldWPToNewCase(mapCaseIdToListWorkParts,mapParentCaseRecordToNewCaseRecord);
    }
    
    private static Map<Id,Integer> createMapOfCaseIdToDueDate(Set<String> setCaseId)
    {
        Map<Id,Integer> mapCaseIdToDueDate = new Map<Id,Integer>();
        
        for(Work_Part__c objWP:[SELECT Id,Maintenance_Cycle__c,Maintenance_Request__c 
                                FROM Work_Part__c 
                                WHERE Maintenance_Request__c IN: setCaseId])
        {
            if(!mapCaseIdToListWorkParts.containsKey(objWP.Maintenance_Request__c))
            {
                mapCaseIdToListWorkParts.put(objWP.Maintenance_Request__c, new List<Work_Part__c>{objWP});
            }
            if(mapCaseIdToListWorkParts.containsKey(objWP.Maintenance_Request__c))
            {
                List<Work_Part__c> listWP = mapCaseIdToListWorkParts.get(objWP.Maintenance_Request__c);
                listWP.add(objWP);
                mapCaseIdToListWorkParts.put(objWP.Maintenance_Request__c,listWP);
            }
            
            if(!mapCaseIdToDueDate.containsKey(objWP.Maintenance_Request__c))
            {
                mapCaseIdToDueDate.put(objWP.Maintenance_Request__c, (Integer)objWP.Maintenance_Cycle__c);
            }
             if(mapCaseIdToDueDate.containsKey(objWP.Maintenance_Request__c))
            {
                if(mapCaseIdToDueDate.get(objWP.Maintenance_Request__c)<objWP.Maintenance_Cycle__c)
                {
                    mapCaseIdToDueDate.put(objWP.Maintenance_Request__c, (Integer)objWP.Maintenance_Cycle__c);
                }
            }
        }
        System.debug('mapCaseIdToListWorkParts '+mapCaseIdToListWorkParts);
        System.debug('mapCaseIdToDueDate '+mapCaseIdToDueDate);
        
        return mapCaseIdToDueDate;
    }
    
    private static void associateOldWPToNewCase(Map<Id,List<Work_Part__c>> mapCaseIdToListWorkParts,Map<Id,Case> mapParentCaseIdToNewCaseRecord)
    {
        Set<Work_Part__c> setWP = new Set<Work_Part__c>();
        if(flag)
        {
            for(Id caseId : mapParentCaseIdToNewCaseRecord.keySet())
            {
                for(Work_Part__c objWP : mapCaseIdToListWorkParts.get(caseId))
                {
                    objWP.Maintenance_Request__c = mapParentCaseIdToNewCaseRecord.get(caseId).Id;
                    setWP.add(objWP);
                }
            }    
        }
        List<Work_Part__c> listWP = new List<Work_Part__c>(setWP);
            
        if(!listWP.isEmpty())
        {
            update listWP;
        }
        
    }    
}
Challenge Not yet complete... here's what's wrong: 
The getBoats() method isn't working properly. Define getBoats() In the BoatSearchResults Apex controller to accept an optional boatTypeId and return all boats if no boatTypeId is passed, and a filtered list of boats if a boatTypeId is passed.

getting this error
Hi,
I want to integrate facebook account with my developer org 
so if any cases posted to my facebook wall could be captured in my org..
this is my visualforce code...
Actually i want to show the loading image button on click of upload attachment  button
On click of select Attachment the apex method is being called which makes the page to rfresh...
i want to avoid the page refresh...
and rerender cannot be used on <apex:inputfile>
////////visualforce code /////////

<apex:page standardController="Account" extensions="extendAccountforstandardController">
<apex:form id="frm">
<apex:pageBlock >
<apex:pageblockSection >
<apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}"/> 
</apex:pageblockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:actionRegion >
<apex:pageBlock id="pgBlkId" >
<apex:pageBlockSection >
<apex:inputField value="{!objAccount.parentid}"/>

</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:outputpanel id="image">
<apex:commandButton action="{!attachRecord}" value=" upload attachment" reRender="image" status="actStatusId" />
</apex:outputpanel>
 <apex:actionStatus id="actStatusId" >
<apex:facet name="start"  >
<img src="/img/loading.gif" />                    
</apex:facet>
</apex:actionStatus> 
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>

///// Apex Code

public class extendAccountforstandardController {

    public PageReference attachRecord() {
    
    System.debug('@@objAccount.id'+objAccount.id);
    
     System.debug('@@objAccount.parentId'+objAccount.parentId);
      
      objAttachment.parentId=objAccount.parentId;
      objAttachment.body=bodyAttachment;
      objAttachment.name=nameAttachment;
      
      if(objAccount.parentid!=null){    
        
            insert objAttachment;
        
        }
        return null;
    }

    public blob bodyAttachment;
    
    public string nameAttachment;
    
    public Account objAccount { get; set; }

    public Attachment objAttachment {get; set;}
    
    public extendAccountforstandardController(ApexPages.StandardController controller) {

        objAccount =new Account();
        objAttachment=new Attachment();

    }
    
    public void selectAttachment(){
    bodyAttachment=objAttachment.body;
    nameAttachment=objAttachment.name;
    System.debug(''+'@@nameAttachment'+nameAttachment);
    }
}