• Rajan
  • NEWBIE
  • 64 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 33
    Questions
  • 69
    Replies
Hi Guyz,

I've this requirement so I need some help for this:---
Business has requirement to hide "Authorization Approved" picklist value when current status of the claim is "Draft" or "Manual Review" and the logged-in user is not payment processor permission set user.

Note- Authorization Approved, Draft and Manual Review are picklist value of the same picklist field which is 'Status' and object is Case.

Thanks i advance
  • July 10, 2018
  • Like
  • 0
Hi Guyz,
Trailhead requirement for validation:
*************************************************
Create a validation rule to check that a contact is in the zip code of its account.
To complete this challenge, add a validation rule which will block the saving of a new or updated contact if the contact is related to an account and has a mailing postal code (which has the API Name MailingPostalCode) different from the account's shipping postal code (which has the API Name ShippingPostalCode).
Name the validation rule Contact must be in Account ZIP Code
A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode should return with a validation error and not be saved
The validation rule should ONLY apply to contact records with an associated account. Contact records with no associated parent account can be added with any MailingPostalCode value. (Hint: you can use the ISBLANK function for this check)

Every time I'm getting the same error as ---  Challenge Not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic

My validation formaula is :
1) AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )

2) AND( NOT(ISBLANK( Account.Id)), MailingPostalCode  <>  Account.ShippingPostalCode )

3) IF(ISBLANK( Account.Id ), false, (IF(MailingPostalCode  <>  Account.ShippingPostalCode, true, false)))
4) AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode__c <> Account.ShippingPostalCode )

My challengfe is not passing in for any case but its firing from frontend.
  • April 17, 2018
  • Like
  • 0
I'm having process builder in my org for autocalculation of some fields. Now I have to replace that process builder with code. So I have written code for that but unable to insert fields after any DML operation.Below is my code for the same. data should automatically inser in field 'Exposure_at_Default__c' from  field Limit__c 
*******
trigger EAD_Calculator on Facility__c (after insert, after update) {
    Facility__c[] facList = new Facility__c[] {};
        
        //if (trigger.isAfter){
            if (trigger.isUpdate || trigger.isInsert){
                for (Facility__c fac: Trigger.new) {
                    Facility__c newFac = new Facility__c(id= fac.Id);
                     if(newFac.Limit__c != null){
                            newFac.Exposure_at_Default__c = newFac.Limit__c;
                         system.debug('Limit__c' +newFac.Limit__c);
                         system.debug('Exposure_at_Default__c' +newFac.Exposure_at_Default__c);
                     facList.add(newFac);
               }
            }
         }
      upsert facList;
    }
  • April 03, 2018
  • Like
  • 0
Hi Friends,

I have stucked for a SOQL query. Requirement is as below:
I have 3 objects for example A, B and C
A- custom Object
B- Account 
C- Custom Object

A-B- Masterdetail Relationship
B-C - lookup relationship
Their is no relationship between A and C but I have to fetch data using query from Object C.
I have to display C object records for each account. How to write query for this condition?
  • December 18, 2017
  • Like
  • 0
Hi friends,

​I have designed a custom button for sending email. I have a custom table where I'm displaying data. Whenever I'll select any record using checkbox and click that button then that particular record should go as email with that VF template which I'm using. I've designed a Visualforce email template using HTML which is coppy of the main table. I've also written a seperate controller for template but unable to map data. I'm able to send email with that template but records are not coming. I think their is some problem with data mapping with that template. I'm displaying recods in table from 3 different custom objects with Account and contact standard object. Any idea or suggestion or sample code for this requirement?
Thanks in advance.
Rajan
  • November 16, 2017
  • Like
  • 0
Hi friends,

I've to implement dynamic SOQL in my class. I have a class where I have written so many Remote action methods and in each method I have a SOQL query with different where clause and fetching data on the basis of multiple values for each methods. Since I have so many methods so SOQL queries count is also so many. I have to write a dynamic SOQL query so that I can call same query n every methods on the basis of where clause. Any suggesion or sample code for this requirement?

Thanks in Advance
Rajan
  • November 06, 2017
  • Like
  • 0
Hi friends,

​I have designed a custom button for sending email. I have a custom table where I'm displaying data. Whenever I'll select any record using checkbox and click that button then that particular record should go as email with that VF template which I'm using. I'm able to send email with that template but records are not coming. I think their is some problem with data mapping with that template. I'm displaying recods in table from 3 different custom objects with Account and contact standard object. Any idea or suggestion or sample code for this requirement?
  • September 25, 2017
  • Like
  • 0
Hi friends,

I have a custome object in which I am saving records and their is a field with name Date_and_Time__c which is containing time and date for next schedule. I need a query which will give all records during current time and next 5 mints.  For example if current time is 4:30 PM and I have given time 4:32 PM in Date_and_Time__c field then it should return this record and if their is any other records during this interval then it sould give all records.
My code is as below:
*****************
global static string GetReminder(){  
        
        DateTime dt = datetime.now();
        DateTime dtIST = dt.addMinutes(330); //330 is GMT +5:30 as IST conversion
        //String CurrentdateTime = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
        DateTime dt1 = dtIST.addMinutes(5); // 5 minutes after current time.
        
        List<SetReminder__c> reminderList = [Select Id, Name, Date_and_Time__c, Next_Best_Action__c, Recom_External_Id__c, Recommendation__c from SetReminder__c where (Date_and_Time__c >=: dtIST and Date_and_Time__c <=:dt1)];
      
        system.debug('DT:' + dtIST);
        system.debug('DT1:' +dt1);
        system.debug('ReminderList:' +reminderList);
         return null;
        }
   
Thanks in  advance
Regards:
Rajan   
  • September 19, 2017
  • Like
  • 0
Hi friends,
I'm unable to execute my method because unable to pass correct format for datetime datatype. Can any one please let me know the format for execution. In my execute window I have to pass 2 values. One in integer and another is datetime.My code is as below
**********************
@RemoteAction
    global static string SetReminder(Integer dataId, datetime Date_time){
         Recommendation__c recom = [Select id, name, Account__r.Id, Account__r.Name, Recommendation_Contact__r.Name,Recommendation_Contact__r.Contact_YTD_Sales__c, Feedback__c, Account__r.AccountNumber,
                                                 Recommendation_Contact__r.Title, Product_Service__c, Type__c, Opportunity_Score__c, Next_Best_Action__c, Product_Recommendation__c, Primary_SKU__c,  
                                                 Status__c, Recom_External_Id__c from Recommendation__c where Recom_External_Id__c =:dataId];
                system.debug('Recommendation:' +recom);
          if(recom != null){  
              SetReminder__c rem = new SetReminder__c();
              rem.Name = recom.name;
              rem.Recommendation__c = recom.name;
              rem.Recom_External_Id__c = recom.Recom_External_Id__c;
              rem.Date_and_Time__c = Date_time;
              insert rem;
        }
        
         return null;
    }
  • September 15, 2017
  • Like
  • 0
Hi Friends,

I have to update records in 3rd party application database once I am inserting or updating data in salesforce account. My project is having web version also and their is seperate database for that. I've to update or insert record in that database at the same time as soon as I m updating or inserting in salesforce databse. How to implement this because I m not getting any idea for this? I know its part of integration but dont know how to do this. Any sample code or blogs will be helpfull for me. Thanks in advance.

Regards:
Rajan
  • September 14, 2017
  • Like
  • 0
Hi Friends,
How to get all accounts and recpective contacts in JSON format? Also I need to return Product name from a custom object and this product name field is a text field and its containing products name. But problem I m facing is its returning all duplicate products also but I need unique one. Suppose I have hundred records so product name can be multiple time. Please check the code and let me know the changes i need in code
Code
*********************
 public static string AccountContactProductList(){
        SalesAIRecommendations.Response item = new SalesAIRecommendations.Response();
                    item.status = 'SUCCESS';
                    item.code = 1000;
                    item.message = 'SUCCESS';
                    item.mappingId = 0;
                    item.sessionToken = null;
                    item.userType = null;
                    item.name = null;
                    item.emailId = null;
                    item.data1 = new List<SalesAIRecommendations.Data1>();
        
        SalesAIRecommendations.Data1 data1 = new SalesAIRecommendations.Data1();
        
        data1.Accounts = new List<SalesAIRecommendations.Accounts>();
        set<Id> accountids= new set<Id>();
        List<Account> accountlist= [select Id,Name FROM Account];
                       for(Account a : accountlist){
                          accountids.add(a.Id);
                          } 
       List<Contact> contactlist= [select Id,account.id, account.name, Name From contact WHERE AccountId In:accountids];
        for(contact con:contactlist ){
        SalesAIRecommendations.Accounts Accounts = new SalesAIRecommendations.Accounts();
                                Accounts.accountId = con.account.id;
                                Accounts.accountName = con.account.name;
                                data1.Accounts.add(Accounts);
                          }
    
        data1.Contacts = new List<SalesAIRecommendations.Contacts>();
        
        for(contact con:contactlist ){
        SalesAIRecommendations.Contacts Contacts = new SalesAIRecommendations.Contacts();
                                Contacts.contactId = con.Id;
                                Contacts.contactName = con.Name;
                                data1.Contacts.add(Contacts);
                                } 
        
        data1.Recommendation = new Set<SalesAIRecommendations.Recommendation>();
           
        Set<Recommendation__c> Product_RecommendationList = new Set<Recommendation__c>([SELECT Product_Recommendation__c FROM Recommendation__c ORDER BY Product_Recommendation__c ASC]);
        
        system.debug('ProductsList#######:' +Product_RecommendationList);
        for (Recommendation__c PR :Product_RecommendationList){
        SalesAIRecommendations.Recommendation Product_Recom = new SalesAIRecommendations.Recommendation();
                            Product_Recom.Product_Recommendation = PR.Product_Recommendation__c;
                            data1.Recommendation.add(Product_Recom);
                            }
         
                            item.data1.add(data1);
        system.debug('{"Account_Contact_List":' + JSON.serialize(item) + '}');
        return '{"Account_Contact_List":' + JSON.serialize(item) + '}';
          }
  • September 13, 2017
  • Like
  • 0
Hi Friends,
My class is as below and I need to return the response in JSOn format. My class is returning Accoun t and related contacts. Can any one please help me out?
My class:
*****************
public with sharing class AccountContactList{
public List<account> accountlist{get;set;}
public set<Id> accountids= new set<Id>();
public  List<contact> contactlist{get;set;}
//public string eventid{get;set;}
public AccountContactList(){
   accountlist= [select Id,Name FROM Account];
   for(Account a : accountlist){
       accountids.add(a.Id);
         }
}
public void getcontactdetails(){
contactlist= [select Id,AccountId,Name From contact WHERE AccountId In:accountids];
 system.debug('ContactList:' +contactlist);
}
}


 
  • September 07, 2017
  • Like
  • 0
Hello Friends,

I've to write a method for Set Reminder button. Is their any one who can help me to write code, any sample code or any suggestion or Links?
Requirement - I've a custom table in which I'm displaying records. Once I'll select any record by clicking on checkbox and click on the button then it should display a calender and time table for selecting reminder and then we have to set reminder at a particular date and time.
Thanks in advance.

Regards:
Rajan
  • September 06, 2017
  • Like
  • 0
Hi Friends,
Can any one please help for this error?.
I have to design a custom button for converting records in opportunity.
I have a table in which I am displaying data from Account, contact and 3 custom objects like attached pic. Whenever I'll select any record from this table using checkbox and click on that button then it should create opportunity. User-added image
I'm unable to get data of related object records like Account name, Contact name.
My code is as below:
******************
 global static string ConvertToOpportunity(Integer dataId){    
                
        Recommendation__c rec = [Select name, Account__r.Id, Account__r.Name, Recommendation_Contact__r.Name,Recommendation_Contact__r.Contact_YTD_Sales__c, Feedback__c,                                       Account__r.AccountNumber ,Recommendation_Contact__r.Title , Product_Service__c, Type__c, Opportunity_Score__c, Next_Best_Action__c, Product_Recommendation__c, Primary_SKU__c,  Recom_External_Id__c from Recommendation__c where Recom_External_Id__c =:dataId];
        system.debug('Recommendation:' +rec);
        
        if(rec != null){
        Opportunity opp = new Opportunity();
            opp.Name = rec.name;
            opp.Account_ID__c = rec.Account__r.Id;
            //opp.Account = rec.Account__r.Name;
            //opp.Account = String.valueOf(rec.Account__r.Name);
            // opp.Contact__c = rec.Recommendation_Contact__r.Name;
            opp.Recommendation_Name__c = rec.Name;
            opp.Opportunity_Lead_Score__c = rec.Opportunity_Score__c;
            opp.Contact_YTD_Sales__c = rec.Recommendation_Contact__r.Contact_YTD_Sales__c;
            opp.Conversation_Type__c = rec.Type__c;
            opp.Product_Recommendation__c = rec.Product_Recommendation__c;
            opp.Next_Best_Action__c = rec.Next_Best_Action__c;
            opp.CloseDate = system.today();
            opp.StageName = 'Pre-Qualified';
            
            system.debug('Opportunity:' +opp);
        insert opp;
        }
}|
  • September 05, 2017
  • Like
  • 0
Hi Friends
Can you please help for one requirement?.
I have to design a custom button for converting records in opportunity.
I have a table in which I am displaying data from Account, contact and 3 custom objects like attached pic. Whenever I'll select any record from this table using checkbox and click on that button then it should create opportunity. Any suggestion or sample code will be helpful.User-added image
  • August 31, 2017
  • Like
  • 0
Hi Friends,
My JSOn is - {"InvalidData"{"userType":null,"status":"success","sessionToken":null,"name":null,"message":"success","mappingId":null,"emailId":null,"data":null,"code":1000}}

But VF is returning - {&quot;InvalidData&quot;:{&quot;userType&quot;:null,&quot;status&quot;:&quot;success&quot;,&quot;sessionToken&quot;:null,&quot;name&quot;:null,&quot;message&quot;:&quot;success&quot;,&quot;mappingId&quot;:null,&quot;emailId&quot;:null,&quot;data&quot;:null,&quot;code&quot;:1000}}


So how to remove this &quot so that I can get the correct JSON as per my class.

My method is as below:
****************************
@RemoteAction
    global static String inValid(integer dataId,boolean contactValid, boolean productValid,
                                 boolean actionValid,String other){
      
       integer contact = 0;
       integer action = 0;
       integer product = 0;
       if(contactValid == true){
        contact = 1;                
       }
       if(productValid == true){
        product = 1;
       }
       if(actionValid == true){
        action = 1;
       }

       SalesAIRecommendations.Item response = new SalesAIRecommendations.Item();
        Recommendation__c recommendation = [SELECT Id,Recom_External_Id__c,Feedback__c FROM Recommendation__c where Recom_External_Id__c =: dataId];
                                            
        if(recommendation != null){
            system.debug('valid recommendation Id');
            recommendation.Feedback__c = other;
            update recommendation;
          
            Invalid_Recommendation__c invRec = new Invalid_Recommendation__c();
            invRec.Recommendation_ID__c = recommendation.Recom_External_Id__c;
            invRec.productChange__c = product;
            invRec.Next_Best_Action__c = action;
            invRec.contactId__c = contact;
            invRec.Others__c = recommendation.Feedback__c;
            insert invRec;
            response.status='success';
            response.code=1000;
            response.message = 'success';
          
            system.debug('{"InvalidData":' + JSON.serialize(response) + '}');
            return '{"InvalidData":' + JSON.serialize(response) + '}';
        }
        else{
            system.debug('invalid recommendation Id');   
            response.status='failure';
            response.code=1001;
            response.message = 'failure';
            system.debug('******:'  + '{"InvalidData":' + JSON.serialize(response) + '}');
            return '{"InvalidData":' + JSON.serialize(response) + '}';
                        
              }
    }
 
  • August 31, 2017
  • Like
  • 0
Hi Friend,
I'm getting above error for sending email using apex class. I have a custom table and I have to design a method for button. In table their are so many records but whenever I'll select and record and click on the button then the detail should go via email with same format. I've created VF template using component. Codes are as below:
COMPONENT
*********
<apex:component controller="NavikRecommendationsControllerHelper" access="global"> <apex:attribute name="RecID" type="Integer" description="Selected Recommendation" assignTo="{!dataId}"/> <html lang="en"> <head> <title>NAVIK SalesAI</title> <style> body{font-family: arial;} table{ font-size: 13px; text-align: left;} table tr td{padding:2px;} p{padding: 7px;} </style> </head> <body> <!-- <b>Dear {!recipient.name}</b>,<br/><br/> --> Details of your recommendation are: <br/><br/><br/> <table style="border:1px solid #ddd; border-radius:4px;" align="center" width="900" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"> <table align="left" width="900" cellpadding="0" cellspacing="0" style=" width:900px; font-size: 13px; background-color: #dceef4 !important; font-family:arial; border:1px solid #ddd; border-radius:4px; "> <tbody> <tr> <th align="center" width="100" bgcolor="#C8E1E9" style="padding:7px 0px;">Account</th> <th align="center" width="110" bgcolor="#C8E1E9" style="padding:7px 0px;">Contact</th> <th align="center" width="100" bgcolor="#C8E1E9" style="padding:7px 0px;">Title</th> <th align="center" width="100" bgcolor="#C8E1E9" style="padding:7px 0px;">Type</th> <th align="center" width="80" bgcolor="#C8E1E9" style="padding:7px 0px;">Contact YTD Sales ($)</th> <th align="center" width="120" bgcolor="#C8E1E9" style="padding:7px 0px;">Primary SKU</th> <th align="center" width="80" bgcolor="#DCEEF4" style="padding:7px 0px;">Lead Score</th> <th align="center" width="100" bgcolor="#DCEEF4" style="padding:7px 0px;">Next Best Action</th> <th align="center" width="110" bgcolor="#DCEEF4" style="padding:7px 0px;">Product Recommendation</th> </tr> </tbody> </table> </td> </tr> <apex:repeat var="rc" value="{!recList}"> <tr> <td colspan="2"> <table style="font-size: 13px; font-family:arial;" align="left" width="900" cellpadding="0" cellspacing="0"> <tbody> <tr style="background:#EFF0F2;"> <!-- <td> <a href="https://cs6.salesforce.com/{!rc.id}"> {!rc.Account__r.Name}</a> </td> --> <td align="center" width="100" style="padding:7px 0px;"> {!rc.Account__r.Name}</td> <td align="center" width="110" style="padding:7px 0px;"> {!rc.Recommendation_Contact__c}</td> <td align="center" width="100" style="padding:7px 0px;"> {!rc.Recommendation_Contact__r.Title}</td> <td align="center" width="100" style="padding:7px 0px;">{!rc.Type__c}</td> <td align="center" width="80" style="padding:7px 0px;"> {!rc.Recommendation_Contact__r.Contact_YTD_Sales__c}</td> <td align="center" width="120" style="padding:7px 0px;">{!rc.Account__r.primarySKU__c}</td> <td align="center" width="80" style="padding:7px 0px;"> {!rc.Opportunity_Score__c}</td> <td align="center" width="100" style="padding:7px 0px;">{!rc.Next_Best_Action__c}</td> <td align="center" width="110" style="padding:7px 0px;">{!rc.Product_Recommendation__c}</td> </tr> </tbody> </table> </td> </tr> </apex:repeat> </table> </body> </html> </apex:component>


EMAIL Template:
****************
<messaging:emailTemplate subject="Recommendation to contact{name} of Account{name} for {product Name}" recipientType="User" relatedToType="Account">
<messaging:htmlEmailBody >
     <b>Dear {!recipient.name}</b>,<br/><br/> 
        Details of your recommendation are: <br/><br/><br/>
  <c:SalesAI_SendToInbox_Component RecID="{!relatedTo.Id}">
  </c:SalesAI_SendToInbox_Component>
</messaging:htmlEmailBody>
</messaging:emailTemplate>


Method:
*************************
global static string SendToInbox(Integer dataId){
        
         // Picking a dummy Contact
            //User u =[select id, name, email from user where email <> null limit 1];
            Contact c = [select id, Email from Contact where email <> null limit 1];
         
         //List<Recommendation__c> recList; 
        List<Recommendation__c> dataList = new List<Recommendation__c>();
        Recommendation__c recList;   
        recList = [Select id, Account__r.Id, Account__r.Name, Recommendation_Contact__r.Name, Recommendation_Contact__r.Title, 
                                 Recommendation_Contact__r.Contact_YTD_Sales__c, Type__c, Primary_SKU__c, Opportunity_Score__c, Next_Best_Action__c, 
                                 Product_Recommendation__c, Account__r.BillingState, Account__r.Customer_Since__c, Recommendation_Contact__r.Phone ,
                                 Recommendation_Contact__r.Assistant_Phone__c, Recommendation_Contact__r.email , Account__r.Industry, Account__r.Business_Unit__c, 
                                 Est_Value__c, Recom_External_Id__c from Recommendation__c where Recom_External_Id__c =: dataId];
           dataList.add(recList);
           system.debug('Recom#########:' +recList);
           
        
           Recommendation_Rationale__c rrList;
                rrList = [SELECT Id, Rationale1__c, Rationale2__c, Rationale3__c, Rationale4__c, Rationale5__c, 
                                 Rationale6__c, Recommendation__c FROM Recommendation_Rationale__c where Recommendation__c =:recList.id];
        
        
           system.debug('Rationale#####:' + rrList);
        
           Cheatsheet__c chtList;
           chtList= [SELECT Id, Pitch1__c, Pitch2__c, Pitch3__c, Pitch4__c, Pitch5__c, Pitch6__c, Discount_Guidance__c, RelatedProducts1__c, RelatedProducts2__c, RelatedProducts3__c,
                                 RelatedProducts4__c, RelatedProducts5__c, RelatedProducts6__c, Recommendation__c FROM Cheatsheet__c where Recommendation__c =:recList.id]; 
           system.debug('Cheatsheet########:' +chtList);
 
                  List<Messaging.SingleEmailMessage> lstMsgs = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
         
             msg.setTemplateId( [select id from EmailTemplate where DeveloperName='SalesAI_SendToInbox_VF_EmailTemplate'].id );
                  msg.setWhatId( [select id from Account limit 1].id );
                msg.setTargetObjectId(c.id);
                //msg.setToAddresses(new List<String>{'Azam.Khan@absolutdata.com'});
                msg.setToAddresses(new List<String>{'rajan.mishra@absolutdata.com'});
                msg.setSaveAsActivity(false);
                lstMsgs.add(msg);
                system.debug('############:'+lstMsgs);
        // Send the emails in a transaction, then roll it back
                Savepoint sp = Database.setSavepoint();
                Messaging.sendEmail(lstMsgs);
                Database.rollback(sp);

                List<Messaging.SingleEmailMessage> lstMsgsToSend = new List<Messaging.SingleEmailMessage>();
                for (Messaging.SingleEmailMessage email : lstMsgs) {
                Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
                emailToSend.setToAddresses(email.getToAddresses());
                emailToSend.setSaveAsActivity(false);
                emailToSend.setPlainTextBody(email.getPlainTextBody());
                emailToSend.setHTMLBody(email.getHTMLBody());
                emailToSend.setSubject(email.getSubject());
                lstMsgsToSend.add(emailToSend);
            }
            Messaging.sendEmail(lstMsgsToSend);
        
         
  • August 11, 2017
  • Like
  • 0
Hi Guyz,

I've written a batch class for updating records and its working for 10000 records. I've to update more than 1 lacs records using API call and as I know the JSON limit is 10000. So can anyone help me out for solving this issue? How to pass multiple calls one by one? Please check my code and suggest me for solution. Thanks in advance.
**********
global class AccountDataSyncBatch implements Database.Batchable<sObject>, Database.AllowsCallouts, Schedulable, Database.stateful{
 
   global String lastAccountId;
   global String lastContactId;
   global String lastOpportunityId; 
   global boolean isStart;
   
   global AccountDataSyncBatch(){
      /* lastAccountId = accId;
       lastContactId = conId;
       lastOpportunityId = oppId;
       isStart = tempStart; */
   }
   
   global Database.QueryLocator start(Database.BatchableContext BC){
      //return Database.getQueryLocator('SELECT Id FROM User LIMIT 1');
      string query = 'SELECT Id, name, Account_Lead_Score__c,Relative_Performance__c, (select id, name,Contact_Lead_Score__c from contacts), (select id, name, Opportunity_Lead_Score__c from opportunities) from account';
      return Database.getQueryLocator(query);
   }

    
   global void execute(Database.BatchableContext BC, List<sObject> scope){
        fetchData();
   }    
    
    global void fetchData(){
        
          //navikAuthDomain.response mapResp = navikAuthentication.getMapId(UserInfo.getUserEmail());
            Http http = new Http();
            HttpRequest request = new HttpRequest();
         // request.setHeader('sessionToken',mapResp.sessionToken);
            request.setHeader('sessionToken', 'UNUEXHA0//SLWpBR9J3v6gEN5hHsbQd0C79nFkpelRojiBfhF6Yth2dZi6oawXSRYDE6AFRGsN0gpV3N0XMrqAkynQ5ZWSmcGT3QAomh3f0=');
            if(isStart = true){
                request.setEndpoint(Label.AccountContactOpportunity_Dump_API); 
            }
            
            request.setMethod('GET');
            HttpResponse response = http.send(request);
            
            if (response.getStatusCode() == 200) {
                DataSyncBatchHelper.ParentData parentData = (DataSyncBatchHelper.ParentData)JSON.deserialize(response.getBody(), DataSyncBatchHelper.ParentData.class);
                system.debug(parentData);
                
                if(parentData != null && parentData.data != null){
                    List<Account> accList = new List<Account>();
                    List<Contact> conList = new List<Contact>();
                    List<Opportunity> oppList = new List<Opportunity>();
                    
                    //****************Accounts***********
                    if(parentData.data.accounts != null && parentData.data.accounts.size() > 0){
                        for(DataSyncBatchHelper.Accounts account : parentData.data.accounts){
                            if(account.accountNumber != null && account.accountNumber.startsWith('001')){
                                accList.add(new Account(Id = account.accountNumber,
                                                                 Account_Lead_Score__c = account.accountleadScore,
                                                                 Relative_Performance__c = account.relative_Performance));
                            system.debug(accList);
                            }
                        }
                        if(accList.size() > 0){
                        Database.update(accList, false);
                        }
                      //****************Contacts************
                      if(parentData.data.contacts != null && parentData.data.contacts.size() > 0){
                        for(DataSyncBatchHelper.Contacts contact : parentData.data.contacts){
                            if(contact.contactId != null && contact.contactId.startsWith('003')){
                                conList.add(new Contact(Id = contact.contactId,
                                                                 Contact_Lead_Score__c = Decimal.valueOf(contact.contactLeadScore)));
                            system.debug(conList);
                            }
                        }   
                          if(conList.size() > 0){
                        Database.update(conList, false);
                        }
                        
                       //*****************Opportunity***************
                       if(parentData.data.opportunities != null && parentData.data.opportunities.size() > 0){
                        for(DataSyncBatchHelper.Opportunities opportunity : parentData.data.opportunities){
                            if(opportunity.opportunityId != null && opportunity.opportunityId.startsWith('006')){
                                oppList.add(new Opportunity(Id = opportunity.opportunityId,
                                                                          Opportunity_Lead_Score__c = Decimal.valueOf(opportunity.Opportunity_Score)));
                            system.debug(oppList);
                            }
                        } 
                         if(oppList.size() > 0){
                        Database.update(oppList, false);
                        }  
                      
                
                       }}}}}}
    
             
   global void finish(Database.BatchableContext BC){
        
           }
    
    global void execute(SchedulableContext sc){
      database.executebatch(new AccountDataSyncBatch());
   } 

}
 
  • July 18, 2017
  • Like
  • 0
Hi friends.
I am getting this error for this batch class:- Methods defined as TestMethod do not support Web service callouts
Class is as below:
********************************
global class SalesAIChildDataSyncBatch implements Database.Batchable<sObject>, Database.AllowsCallouts, Schedulable{

    global class Item {
        global String status;
        global Integer code;
        global String message;
        global Integer mappingId;
        global String sessionToken;
        global String userType;
        global String name;
        global String emailId;
        global Data data;
        
        global Item(){}
    }
    
    global class Data {
        global Integer dataId;
        global String oppId;
        public String accountNumber;
        public String accountId;
        public String accountName;
        public String contactName;
        public String designation;
        public String status;
        public String type;
        public String email;
        public Integer contactYTDSales;
        public Integer contactLeadScore;
        public Integer leadScore;
        public Integer opportunityScore;
        public String nextBestAction;
        public String productServiceRecommendation;
        public String feedback;
        public Integer thisWeek;
        public Integer lastWeek;
        public String primarySKU;
        public String skuLabel;
        public String CurrencyC;
        public String businessUnit;
        public String mobileNumber;
        public String officeNumber;
        public String productServiceRationale1;
        public Integer productServiceScore1;
        public String productServiceRationale2;
        public Integer productServiceScore2;
        public String productServiceRationale3;
        public String productServiceRationale4;
        public Integer productServiceScore4;
        public String productServiceRationale5;
        public Integer productServiceScore5;
        public String productServiceRationale6;
        public Integer productServiceScore6;
        public String industryType;
        public Date customerSince;
        public String productCheatSheet1;
        public String productCheatSheet2;
        public String productCheatSheet3;
        public String productCheatSheet4;
        public String productCheatSheet5;
        public String productCheatSheet6;
        public String relatedProduct1;
        public String relatedProduct2;
        public String relatedProduct3;
        public String relatedProduct4;
        public String relatedProduct5;
        public String relatedProduct6;
        public String discountGuidance;
        public String location;
        
        public Data(){}
    }

   
   global Database.QueryLocator start(Database.BatchableContext BC){
      Set<Id> accIds = new Set<Id>{'001N000001AJNSi'};
      return Database.getQueryLocator('SELECT Id, AccountNumber, dataId__c, (SELECT Name FROM Contacts ORDER BY CreatedDate DESC LIMIT 1) FROM Account WHERE Id IN : accIds');
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
        for(Account acc : (List<Account>) scope){
            String contactName = '';
            
            if(acc.Contacts != null && acc.Contacts.size() > 0){
                contactName = acc.Contacts[0].Name;
            }
            String dataId = string.valueof(acc.dataId__c);
            fetchData(acc.Id, dataId);
        }
   }
   
   global void fetchData(Id accId, String dataidAcc){
       navikAuthDomain.response mapResp = navikAuthentication.getMapId(UserInfo.getUserEmail());

        Recommendation__c recomnd;
        Recommendation_Rationale__c recomRational;
        Cheatsheet__c cheatsht;
        
        if(mapResp !=null){
            Http http = new Http();
            HttpRequest request = new HttpRequest();
        
            request.setHeader('sessionToken',mapResp.sessionToken);
            request.setEndpoint('http://35.163.113.123:8080/sales-core/v1.0/sales/recommendation/product_services?');
            request.setMethod('POST');
            
            //accId = EncodingUtil.urlEncode(accId,'UTF-8');
            dataidAcc = EncodingUtil.urlEncode(dataidAcc,'UTF-8');
            //cont = EncodingUtil.urlEncode(cont,'UTF-8');
            String recom = EncodingUtil.urlEncode('true','UTF-8');
            
            request.setBody('dataId='+dataidAcc);
            
            HttpResponse response = http.send(request);
            
                       /*    if(!test.isRunningTest()){
                       
                                response = http.send(request);}
                           else {
                                 response=new HttpResponse();
                                        }        */    
            
            System.debug('>>>>' + response.getBody());
            if (response.getStatusCode() == 200) {
                Item lstData = (Item)JSON.deserialize(response.getBody(), Item.class);
                //SalesAIRecommendations.Item item = (SalesAIRecommendations.Item)JSON.deserialize(response.getBody(), SalesAIRecommendations.Item.class);
                System.debug('>>>>lstData'+lstData);

            if(lstData != null && lstData.data != null ){
                    //Map<Id, Recommendation__c> accRecommMap = new Map<Id, Recommendation__c>();
                    //Map<Id, Recommendation_Rationale__c> RecomRatnlMap = new Map<Id, Recommendation_Rationale__c>();
                    //Map<Id, Cheatsheet__c> cheatShtMap = new Map<Id, Cheatsheet__c>();

                    
                    Data freshData = lstData.Data;
                        System.debug('Accid>>>>' + accId);
                        recomnd = new Recommendation__c(Opportunity_Score__c = freshData.opportunityScore,
                                                                        Product_Service__c = freshData.productServiceRecommendation,
                                                                        Est_Value__c = freshData.contactYTDSales,
                                                                        Account__c = accId );
                        
                       // accRecommMap.put(data.accountNumber, recomnd);
                        
                        
                        //Recommendation Rationale Upsert
                        recomRational = new Recommendation_Rationale__c();                      
                        recomRational.Rationale1__c = freshData.productServiceRationale1;
                        recomRational.Rationale2__c = freshData.productServiceRationale2;
                        recomRational.Rationale3__c = freshData.productServiceRationale3;
                        recomRational.Rationale4__c = freshData.productServiceRationale4;
                        recomRational.Rationale5__c = freshData.productServiceRationale5;
                        recomRational.Rationale6__c = freshData.productServiceRationale6;
                        
                        //RecomRatnlMap.put(data.accountNumber, recomRational);
                        
                        //Cheatsheet upsert
                        cheatsht = new Cheatsheet__c();
                        cheatsht.Discount_Guidance__c = freshData.discountGuidance;
                        cheatsht.Pitch1__c = freshData.productCheatSheet1;
                        cheatsht.Pitch2__c = freshData.productCheatSheet2;
                        cheatsht.Pitch3__c = freshData.productCheatSheet3;
                        cheatsht.Pitch4__c = freshData.productCheatSheet4;
                        cheatsht.Pitch5__c = freshData.productCheatSheet5;
                        cheatsht.Pitch6__c = freshData.productCheatSheet6;
                        cheatsht.RelatedProducts1__c = freshData.relatedProduct1;
                        cheatsht.RelatedProducts2__c = freshData.relatedProduct2;
                        cheatsht.RelatedProducts3__c = freshData.relatedProduct3;
                        cheatsht.RelatedProducts4__c = freshData.relatedProduct4;
                        cheatsht.RelatedProducts5__c = freshData.relatedProduct5;
                        cheatsht.RelatedProducts6__c = freshData.relatedProduct6;
                       
                        //cheatShtMap.put(data.accountNumber, cheatsht);
                        }

                    upsert recomnd;
                    system.debug('recomnd >> '+recomnd.Id);
                    recomRational.Recommendation__c = recomnd.Id;
                    upsert recomRational;
                    cheatsht.Recommendation__c= recomnd.Id;
                    upsert cheatsht;
                        
               }
            }

        }

   global void finish(Database.BatchableContext BC){}
   
   global void execute(SchedulableContext sc){
      database.executebatch(new SalesAIChildDataSyncBatch());
   }
}
  • April 23, 2017
  • Like
  • 0
Hi friends,
I am getting only 41% code coverage for this class. Plz help me to get the coverage for this class.

My Test Class
******************
@isTest
public with sharing class NavikRecommendationsControllerHelperTest {
    public static testmethod void ControllerHelperTest() {
        
        
        Account acc = new Account(Name= 'Test', Industry= 'Pharma', Account_Lead_Score__c= 90, Last_Action__c= 'call', Existing_Conversation__c= 1, New_Conversations__c = 1, Account_YTDSales__c = 10);
        insert acc;
        
        Opportunity opp = new Opportunity(Name= 'Testopp' /*, Contact__c= 'jain' */, CloseDate= System.today(), StageName = 'Closed', Sales_Rep_1__c= 'Kunal Jain', Geography__c = 'ME', Vertical__c = 'CPG', Horizontal__c ='NCT', Opportunity_Lead_Score__c= 90, Contact_YTD_Sales__c = 100, Conversation_Type__c = 'Phone', Product_Recommendation__c= 'test', Next_Best_Action__c = 'email', Account_Manager_1__c = 'Jim', Status__c ='lost', Reason_for_Closure__c= 'done');
        insert opp;
        //Account= 'Test',
        
        Recommendation__c rec = new Recommendation__c (Name= 'Test', Est_Value__c= 5000, Opportunity_Score__c = 90, Product_Service__c= 'PC');
        insert rec;
        
        Recommendation_Rationale__c rcr = new Recommendation_Rationale__c (Name= 'Offer', Rationale1__c = 'Offer1', Rationale2__c= 'offer2', Rationale3__c= 'Offer3', Rationale4__c = 'offer4', Rationale5__c= 'offer5', Rationale6__c= 'offer6', Recommendation__c = rec.Id);
        insert rcr;
        
          Cheatsheet__c cts = new Cheatsheet__c (Name= 'cheatsheet', Recommendation__c = rec.Id);
        insert cts;
        
        /*
        List<SalesAIRecommendations.Data> lst = new List<SalesAIRecommendations.Data>();

        SalesAIRecommendations.Data data = new SalesAIRecommendations.Data();
            data.accountNumber = '7846483469';
            data.AccountId = acc.Id;
            data.dataId = 9456;
            data.accountName = 'Test';
            data.leadScore = 90;
            data.productServiceRecommendation = 'NA';
            data.feedback = 'testing';
            data.thisWeek = 1;
            data.lastWeek = 2;
            data.primarySKU = 'NA';
            data.skuLabel = 'NA';
            data.location = 'Gurgaon';
            data.industryType = 'IT';
            data.customerSince = System.today();
            data.contactName = 'NA';
            data.oppId = acc.Id;
            //insert data;
        lst.add(data);
        */
        
        /* SalesAIRecommendations.Recommendations temp = new SalesAIRecommendations.Recommendations();
                    temp.productServiceRecommendation = 'PC';
                    temp.opportunityScore = 90;
                    temp.estimatedValue = 5000;
                    data.recommendations.add(temp); */
        
        
        
        test.startTest();
        string str = NavikRecommendationsControllerHelper.pCallout();
        string str1 = NavikRecommendationsControllerHelper.deCallout();
        string str2 = NavikRecommendationsControllerHelper.inCallout();
         string str3 = NavikRecommendationsControllerHelper.callout('98748', 'Raj', 'test');
        string str4 = NavikRecommendationsControllerHelper.specificSalesRecommendation('test');
        string str5 = NavikRecommendationsControllerHelper.specificOpportunities('73872832');
        //string str6 = NavikRecommendationsControllerHelper.sendEmail(new List<SendToInbox.response>{new SendToInbox.response()});
        //string str7 = NavikRecommendationsControllerHelper.invalid(new List<integer>{123435}, new List<String>{'123435'});
         //string str8 = NavikRecommendationsControllerHelper.setInvalidCallout(new List<integer>{123435});
        test.stopTest();
        
        
    
    }
    
}
  • April 19, 2017
  • Like
  • 0
Hi friends, 
I am a salesforce Certified admin and I am having depth knowledge about admin and also know development. I need video materials for core development including integration. Can anyone suggest me for video materials of development with all topics. I can pay the cost for the material but all topics should be there. Please help me to get correct video material for learning in depth.
  • September 19, 2016
  • Like
  • 1
Hi Guyz,
Trailhead requirement for validation:
*************************************************
Create a validation rule to check that a contact is in the zip code of its account.
To complete this challenge, add a validation rule which will block the saving of a new or updated contact if the contact is related to an account and has a mailing postal code (which has the API Name MailingPostalCode) different from the account's shipping postal code (which has the API Name ShippingPostalCode).
Name the validation rule Contact must be in Account ZIP Code
A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode should return with a validation error and not be saved
The validation rule should ONLY apply to contact records with an associated account. Contact records with no associated parent account can be added with any MailingPostalCode value. (Hint: you can use the ISBLANK function for this check)

Every time I'm getting the same error as ---  Challenge Not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic

My validation formaula is :
1) AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )

2) AND( NOT(ISBLANK( Account.Id)), MailingPostalCode  <>  Account.ShippingPostalCode )

3) IF(ISBLANK( Account.Id ), false, (IF(MailingPostalCode  <>  Account.ShippingPostalCode, true, false)))
4) AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode__c <> Account.ShippingPostalCode )

My challengfe is not passing in for any case but its firing from frontend.
  • April 17, 2018
  • Like
  • 0
I'm having process builder in my org for autocalculation of some fields. Now I have to replace that process builder with code. So I have written code for that but unable to insert fields after any DML operation.Below is my code for the same. data should automatically inser in field 'Exposure_at_Default__c' from  field Limit__c 
*******
trigger EAD_Calculator on Facility__c (after insert, after update) {
    Facility__c[] facList = new Facility__c[] {};
        
        //if (trigger.isAfter){
            if (trigger.isUpdate || trigger.isInsert){
                for (Facility__c fac: Trigger.new) {
                    Facility__c newFac = new Facility__c(id= fac.Id);
                     if(newFac.Limit__c != null){
                            newFac.Exposure_at_Default__c = newFac.Limit__c;
                         system.debug('Limit__c' +newFac.Limit__c);
                         system.debug('Exposure_at_Default__c' +newFac.Exposure_at_Default__c);
                     facList.add(newFac);
               }
            }
         }
      upsert facList;
    }
  • April 03, 2018
  • Like
  • 0
Hi friends,

​I have designed a custom button for sending email. I have a custom table where I'm displaying data. Whenever I'll select any record using checkbox and click that button then that particular record should go as email with that VF template which I'm using. I've designed a Visualforce email template using HTML which is coppy of the main table. I've also written a seperate controller for template but unable to map data. I'm able to send email with that template but records are not coming. I think their is some problem with data mapping with that template. I'm displaying recods in table from 3 different custom objects with Account and contact standard object. Any idea or suggestion or sample code for this requirement?
Thanks in advance.
Rajan
  • November 16, 2017
  • Like
  • 0
Hi friends,

I've to implement dynamic SOQL in my class. I have a class where I have written so many Remote action methods and in each method I have a SOQL query with different where clause and fetching data on the basis of multiple values for each methods. Since I have so many methods so SOQL queries count is also so many. I have to write a dynamic SOQL query so that I can call same query n every methods on the basis of where clause. Any suggesion or sample code for this requirement?

Thanks in Advance
Rajan
  • November 06, 2017
  • Like
  • 0
Hi friends,

​I have designed a custom button for sending email. I have a custom table where I'm displaying data. Whenever I'll select any record using checkbox and click that button then that particular record should go as email with that VF template which I'm using. I'm able to send email with that template but records are not coming. I think their is some problem with data mapping with that template. I'm displaying recods in table from 3 different custom objects with Account and contact standard object. Any idea or suggestion or sample code for this requirement?
  • September 25, 2017
  • Like
  • 0
Hi friends,

I have a custome object in which I am saving records and their is a field with name Date_and_Time__c which is containing time and date for next schedule. I need a query which will give all records during current time and next 5 mints.  For example if current time is 4:30 PM and I have given time 4:32 PM in Date_and_Time__c field then it should return this record and if their is any other records during this interval then it sould give all records.
My code is as below:
*****************
global static string GetReminder(){  
        
        DateTime dt = datetime.now();
        DateTime dtIST = dt.addMinutes(330); //330 is GMT +5:30 as IST conversion
        //String CurrentdateTime = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
        DateTime dt1 = dtIST.addMinutes(5); // 5 minutes after current time.
        
        List<SetReminder__c> reminderList = [Select Id, Name, Date_and_Time__c, Next_Best_Action__c, Recom_External_Id__c, Recommendation__c from SetReminder__c where (Date_and_Time__c >=: dtIST and Date_and_Time__c <=:dt1)];
      
        system.debug('DT:' + dtIST);
        system.debug('DT1:' +dt1);
        system.debug('ReminderList:' +reminderList);
         return null;
        }
   
Thanks in  advance
Regards:
Rajan   
  • September 19, 2017
  • Like
  • 0
Hello Friends,

I've to write a method for Set Reminder button. Is their any one who can help me to write code, any sample code or any suggestion or Links?
Requirement - I've a custom table in which I'm displaying records. Once I'll select any record by clicking on checkbox and click on the button then it should display a calender and time table for selecting reminder and then we have to set reminder at a particular date and time.
Thanks in advance.

Regards:
Rajan
  • September 06, 2017
  • Like
  • 0
The challenge is:

You've been given a requirement to keep Contact addresses in sync with the Account they belong to. Use Process Builder to create a new process that updates all child Contact addresses when the address of the Account record is updated. This process:Can have any name.
Must be activated.
Must update Contact mailing address fields (Street, City, State, Post Code, Country) when the parent Account shipping address field values are updated.

I start with Accounts when records is created or edited.
Filter criteria where accounts shipping address (street, city, state, zip code) is changed (used "or" logic).

I am stuck on the next step "add action".  I started with action type "Update Records".
On objects, I can't seem to change Accounts to Contacts.  Why?