• shrey.tyagi88@tcs.com
  • NEWBIE
  • 115 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 124
    Questions
  • 138
    Replies
Hi All ,
    I need to open a pop-up window from a record detail page . I got my hands on the following snippet of code that works just fine.

<aura:component implements="force:lightningQuickAction" >
    <ui:button label="Open in New window" press="{!c.openActionWindow}"/>
</aura:component>

Controller-

({
    openActionWindow : function(component, event, helper) {
         window.open("https://www.w3schools.com");
    }
})

Now in this code when you click on a button (on record detail page)a pop up comes in front and asks you to click a button (Label-Open in new window). I want to disable this behavior, I want that when I click the button on record detail page, a pop up should have the url (w3 schools) loaded into it.And I also want to pass a record parameter in the URL , say Opportunity.Id.
HI All,
    I have a scenario which I want to discuss and confirm whether the anyone else has experienced the same issue or not. 

I am deploying a change set of 400 components. The flows are in that change set alnong with the test classes. Now, I use flows to create records of custom object "Project Review" and then I have written test classes that fetch those newly created "Project Review" records . When I run my tests in sandbox (with active flow) all of the test cases pass and I get good coverage. But when I validate the same change set for deployment , exactly at point where "Project Review "records are queried in test class - A list has no records error gets thrown out to me. 

Salesforce Says : 'An active flow in a change set is deployed to its destination as inactive. Activate the flow manually after deployment.' 

I googled this and found that even active flows upon deployment are deactivated initially. Is this the reason why I may be facing this issue ? Becuase my active flows of change sets are deactivated initially upon deployment , I dont get any records created for my test class and exception error gets in .



Just want to confirm my guess here. Thanks for your help ...


Regards
Shrey Tyagi
Hi All ,
     I have this VF page that renders the page as PDF file upon click of a button . This works well in salesforce , however it does not work and goes to salesforce login screen when the button is clicked on Force.com site . Please help. I have explicitly given access of this page to the site as well. 

Button : Generate PDF (On Object Detail Page- This page is accessible from force.com site as well , button is also visible to site users.)

Visualfoce Page tied to the button mentioned above is given below:


<apex:page standardController="Project_Form__c" showHeader="true" tabStyle="Project_Form__c" renderas="pdf" >
   <apex:detail relatedList="false" title="true"/>
</apex:page>
Hi Everyone,
        I have a question on how to cover exceptions of Database.Save method. The method I want to cover is given below:

Apex Code : 
     Database.SaveResult[] lsr = Database.insert(GateReviewShrs,false); 
     // Create counter
     Integer i=0;
     // Process the save results
        for(Database.SaveResult sr : lsr){
            if(!sr.isSuccess()){
                // Get the first save result error
                Database.Error err = sr.getErrors()[0];
                if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  
                                               &&  err.getMessage().contains('AccessLevel'))){

                    trigger.newMap.get(GateReviewShrs[i].ParentId).
                      addError(
                       'Unable to grant sharing access due to following exception: '
                       + err.getMessage());
                }
            }
            i++;
        }
I am trying to cover this exception by making a wrong entry in my test class (one of inactive user). Code given below: 


@isTest
public class Test_PrasApexCode {
    
    static testMethod void testDoGet1() {



        
        Costpoint_Project__c testCostpointProject = new Costpoint_Project__c();
        testCostpointProject.Name = '0281300.003';

        insert testCostpointProject;

        //Fetch related Project Risk Review form.
        Project_Risk_Review__c ProRiskRev=[Select id,DVP__c,Project_Manager__c,Chair_Reviewer__c,Delegate__c 
                                           from Project_Risk_Review__c where Costpoint_Project__c=:testCostpointProject.Id];

        List<User> u2= [SELECT Id FROM User WHERE isActive=False and ProfileId=:Label.PRAS_RTI_BusinessDevelopment_Profile_Id Limit 1];

  
         ProRiskRev.Delegate__c=u2[0].Id;
         Update ProRiskRev;
      
But when I try to do this my coverage increases but test method fails . It has to fail because the user is inactive. Is there any way to pass the test method and increase the coverage?
 
Hi Everyone,
              Just a quick question for you all. I have opportunity and Account bothe private . If I grant someone acess to opportunity record , via manaul share or opportunity team , what will be the new access of that person on the related account record? Does it work the same way for cases/contact as well?

Regards
Shrey Tyagi
Hi Everyone,
             I have a requirement with me . I need to do a validation when opportunity team member is added to the opportunity. The requirement is that , user must not be able to add a new opportunity team member on an opportunity which has its close date in the past . I have written a before insert trigger on Oppotunity team member . Need your help in getting SOQL out of for Loop. I know it can be done via map , just need some pointers to get started on this.

Sample code:

for(OpportunityTeamMember member : Trigger.new)
      {
        Opportunity opp= Select CloseDate from Opportunity where Id = member.OpportunityId ;
        if (opp.closedate<system.today()){
         member.adderror('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
        }
      }
Hi Everyone,
           I am running into a small issue here.  Need help just with 1 line of syntax. So I have an object called Project Form , which is looking up to its parent called costpoint project . There is a user field on costpoint record (project team member 1) . I want an apex sharing record (on project form) to get created whenever a project form is added to a particular costpoint project .  All is working well, just the syntax to pass on the Id of the user from parent record seems to go awry . Please help me with the code given below, I have underscored the lines .


 for(Project_Form__c ProjectForm : trigger.new){
            // Instantiate the sharing objects
            teamMemberShr = new Project_Form__Share();
            
            
            // Set the ID of record being shared
            teamMemberShr.ParentId = ProjectForm.Id;
            
            
            // Set the ID of user or group being granted access
            //teamMemberShr.UserOrGroupId = ProjectForm.Costpoint_Project__r.Project_Team_Member_1__c;
            system.debug('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: ' + ProjectForm.Costpoint_Project__r.Project_Team_Member_1__c);
         
            teamMemberShr.UserOrGroupId = '005G0000001to4iIAA';
            
            // Set the access level
            teamMemberShr.AccessLevel = 'read';
            
            
            // Set the Apex sharing reason for hiring manager and recruiter
            teamMemberShr.RowCause = Schema.Project_Form__Share.RowCause.Project_Team_Member__c;
            
            
            // Add objects to list for insert
            ProjectFormShrs.add(teamMemberShr);
            
        }
Hi Everyone,
         I have written a @HTTP Post method which works fine. I need a sample code to write it's test class . Can anyone  please help me with this? My test method is giving an error saying that method doPost() does not exist (second last line).

Apex Code:

@RestResource(urlMapping='/v1/cans/*')
global with sharing class MyRestResource {
  @HttpPost
    global static DocWrapper doPost(String Description, String ParentId, String FilePathname, String Name, String Type) {
        DocWrapper response=new DocWrapper();
        Document__c doc= new Document__c();
        doc.Doc_Name__c=Name;
        doc.Type__c=Type;
        doc.CAN__c=ParentId;
        doc.Link__c=FilePathname;
        doc.Description__c=Description;
        insert doc;
        response.message='Doc Inserted';
        return response;
        
     }
       global class DocWrapper {          
          public String message;
     }
}

Test Method:


static testMethod void testDoPost(){
        
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
        
        RecordType RecType = [Select Id From RecordType  Where SobjectType = 'CAN__c' and Name = 'CAN Fed'];    
        CAN__c cf = new CAN__c (Name='Test CAN 1',RecordTypeId=RecType.Id);
        insert cf;
        String CanId=cf.id;
        
        req.requestURI = '/services/apexrest/v1/cans/';  
        req.addParameter('Description', '0000000');
        req.addParameter('ParentId',CanId);
        req.addParameter('FilePathname', 'www.google.com');
        req.addParameter('Name', '1wer2547');
        req.addParameter('Type', '1wer2547');

        req.httpMethod = 'POST';
        RestContext.request = req;
        RestContext.response = res;
        
        Test.startTest();
        MyRestResource.DocWrapper results = MyRestResource.doPost();
        Test.stopTest();
        

    }
Hi Everyone,
              I have written a trigger that posts a feed on Accdount record whenever a child gets inserted. This trigger works fine , but I am struggling to add multi word topics to it. Please finde the code given below:

trigger CreateChatterFeedOnAccount on Chatter_Feed__c (after insert) {

List<FeedItem> lstFeeds = new List<FeedItem>();
String BodyOfFeed;
 if(Trigger.isInsert && Trigger.isAfter){
        for(Chatter_Feed__c cf : trigger.new) {
         FeedItem fi = new FeedItem();
         fi.ParentId = cf.Account__c;
         fi.Title= cf.Title__c;
         BodyOfFeed =  cf.Description__c;
         if(cf.link__c!= null){
            fi.Type = 'LinkPost';
            fi.LinkUrl = cf.link__c; 
         }
          if(cf.Topic_1__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_1__c;}
          if(cf.Topic_2__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_2__c;}
          if(cf.Topic_3__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_3__c;}
          if(cf.Topic_4__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_4__c;}
          if(cf.Topic_5__c!= null){BodyOfFeed=BodyOfFeed+' #'+cf.Topic_5__c;}

          fi.Body=BodyOfFeed;
         
                    
         lstFeeds.add(fi);
        }
    }
   if(lstFeeds.size()>0){
         insert lstFeeds;
   }
  }
Now in the bold lines given above, if I add a topic that is of asingle word , it gets appended properly for eg  if Topic_1__c= "Sunshine" then post adds #Sunshine . But if Topic_1__c= "My Topic" post adds #My Topic to it. So how do we add muti word topis via apex. I found another link , but was not able to figure out much from this. Please help.

http://salesforce.stackexchange.com/questions/31163/how-to-add-topics-names-containing-spaces-to-feeditem-using-hashtag-via-apex?rq=1

Regards
Shrey Tyagi
Hi Everyone,
     I am taking baby steps towards REST apex  functionalliy and have developed some code (which fortunately woorks). Now I need your help in enhancing its operations. Please find the summary given below:

Using a json (given below) I managed to create an account record in salesforce:

{
   "acct":
   {
     "Name":"Jag"
   }

}

Apex Code:
@RestResource(urlMapping='/v1/accounts/*')
global with sharing class MyRestResource {
@HttpPost
    global static AccountWrapper doGet(Account acct) {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        AccountWrapper response= new Accountwrapper();
        try{
         insert acct;
         response.message='Mogamgo Khush Hua :)';
        }
        catch(Exception exc){
         response.message='Mogamgo Dukhi Hua :('; 
        }
       return response;
    }
      global class AccountWrapper {
      public Account acct;
      public String status;
      public String message;
      public AccountWrapper(){}

    }

}
Now I want to modify my apex code so that it can take a json with 1 account and 3 contacts in it and insert them in salesforce. Sample json is given below , can anyone please guide me with the modifications that are to be done in my apex class?


{
  "rqst":{
        "acct":{
         "Name":"Jag"
        }
        "conlist":{
         [
           {"FirstName":"Test","LastName":"Test"},
           {"FirstName":"Test1","LastName":"Test1"}
         ]
        }
  }

}
 
Hi Everyone,
          I am a newbie to Salesforce Integrations and I am reading a lot of stuff to get hang of how SOAP and REST integrations are done . I have few very basic questions related to patterns , if anyone can help me out with them , that would be great. Please find them given below:

Q1. For an inbound integration, we have 2 options (as per my knowledge). One is to create an apex class and expose it as a web service , so that it can be consumed by external entity (C# or Java platform). This code will be used in whatever DML operations  that are required . Second option is to ask the Java/C# side developers to write their own code and provide their code login access to salesforce by adding the application under remote side settings. How do we choose which approach to take? 

Q2. While making HTTP callouts to external systems , we usedifferent type of encoding like given below:

String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
String encodedPropAddress = EncodingUtil.urlEncode(Rec.a__c,'UTF-8');

How do we know which format is to be used when ? As in when to use base64 . Will it be provided to me as a salesforce developer by technicians of external systems (to which callouts are being made)?

I do know that these questions might sound to you as very basic ones , but I am bit confused . So I would really appriciate if someone can throw some light on them.

Thanks a lot for your help!!!

Regards
Shrey Tyagi
Hi All,
         I have this piece of code given below , Its a search page that displays results depending on search parametres and shows resuls with a checkbox next to them (Using Wrapper class). I wanna implement pagination here , Can anyone plz help me with the code?
Wrapper class line are highlighted.

public class AccountSearchController{

public List<Contact> ContactObjects {get;set;}
public List<Account> AccountObjects {get;set;}
public List<Account> AccountObjectsx {get;set;}
public Account AccObj {get;set;}
public Contact ContactObj {get;set;}
private String soql {get;set;}
//Our collection of the class/wrapper objects cContact 
public List<cContact> contactList {get; set;}
public ApexPages.StandardSetController con{get; set;}


////////////////////////////////////////////////////Constructor//////////////////////
public AccountSearchController(ApexPages.StandardController controller) {
  Value='Contact';
  ContactObj = new Contact();
  AccObj = new Account();
  // makes the defalut in the VF page for contact type as 'Main'
  ContactObj.Contact_Type__c ='Main';
  //pass value for picklist conatct type in query
  String slist = 'Main';
 
  // strings to pass defalut value of account segment and contact status and recordtype of account and contact as sales in query
  String defaultAccSegemnt= 'Regional';
  String defaultConStatus= 'Active';

  //list strings to pass account type in query as ('Active','Inactive','New')
  List <String> defaultAccType=new List<String>();
  String active= '\'Active\'';

  //userid = Userinfo.getUserId();
  userid='00550000000rgCd';
  system.debug('logged in user id>>>>>>>>>>'+ userid);
  
 
  soql ='SELECT Id,FirstName,LastName,Position__c,Contact.Account.IsPersonAccount,Contact.Account.Other_Address_Street_1__pc,Contact.Account.Phone ,Contact_Master_Policy_Mailing__c,Contact.Account.Type,Contact.Account.PY_Total_Ins_Volume__c,Contact_Type__c ,Phone,Email,Title, Contact.Account.Segment__c,Contact.Account.Parent_Name__c,Contact.Account.Branch_Org__c,Contact.Account.Name FROM Contact  ';

  runQuery();
 

}
public  PageReference runSearch() {
 
 

 
   Boolean masterPolicyBoolean=AccObj.Master_Policy__c;
  String masterPolicy;
  RecordType recordTypeValue= AccObj.RecordType;
  String recordType=String.valueof(recordTypeValue);

  if(Value == 'Contact'){
      soql ='SELECT Id,FirstName,LastName,Contact.Account.IsPersonAccount,Position__c,Contact.Account.Other_Address_Street_1__pc,Contact.Account.Phone,Contact_Master_Policy_Mailing__c,Contact.Account.Type,Contact.Account.PY_Total_Ins_Volume__c,Contact_Type__c ,Phone,Email,Title, Contact.Account.Parent_Name__c,Contact.Account.Segment__c,Contact.Account.Branch_Org__c,Contact.Account.Name FROM Contact WHERE  Contact.Account.Name!=null';
      soql += ' and Contact.Account.RecordTypeId =\''+String.escapeSingleQuotes(recordtypeAccount_sales)+'\'';
      soql += ' and Contact.RecordTypeId = \''+String.escapeSingleQuotes(recordtypeContact_sales)+'\'';
 
            if(AccountOwnerValue!=null && !AccountOwnerValue.equals('') && AccountOwnerValue.equals('My'))
                {soql += ' and Account.ownerId = \''+String.escapeSingleQuotes(userid)+'\'';
                system.debug('AccountOwnerValue soql -----------------------------'+AccountOwnerValue);
                system.debug('soql AccountOwnerValue -----------------------------'+soql );}


                }  
        }

                
   
  runQuery(); 
  return null;

}

public void runQuery() {


      soql+=  'Order By Contact.Account.Name';
          ContactObjects =Database.query(soql + ' limit 30');
          getContacts();
     

}

////////////////////////////Code Of Wrapper Class Starts here///////////

public List<cContact> getContacts() {
        system.debug('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
        //if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c:ContactObjects ) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                contactList.add(new cContact(c));
            }
            
        // }
        return contactList;
    }
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}
        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public cContact(Contact c) {
        con = c;
        selected = false;
      }
}

public PageReference processSelected() {
    //We create a new list of Contacts that we be populated only with Contacts if they are selected
      List<Contact> selectedContacts = new List<Contact>();
      Set<Account> selectedAccounts = new Set<Account>();
      List<Account> selectedAccountList = new List<Account>();
      //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
      //for(cContact cCon: gatContacts()) {
      for(cContact cCon: contactList) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
                selectedAccounts.add(cCon.con.Account);
            }
        }
      // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
      for(Account acs: selectedAccounts){
          selectedAccountList.add(acs);
       }
       update selectedAccountList;
       update selectedContacts;
       contactList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
       return null;
   }




     

}
Hi All ,
        I want to paginate a wrapper class such that when i navigate from one page to another the slected records dont get unchecked in previos page.
Code is goven below:

Apex:
public class wrapperClassController {
    //Our collection of the class/wrapper objects cContact
    public List<cContact> contactList {get; set;}
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c: [select Id, Name, Email, Phone from Contact limit 10]) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }
    public PageReference processSelected() {
        List<Contact> selectedContacts = new List<Contact>();
        for(cContact cCon: getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }
        for(Contact con: selectedContacts) {
            system.debug(con);

        }
        contactList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
        return null;
    }
 
    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}
        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}
///////////////////////////////////////////////////////vf page////////////////////////////////////////////////////
<apex:page controller="wrapperClassController">




    <apex:form >




        <apex:pageBlock >




            <apex:pageBlockButtons >




                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>




            </apex:pageBlockButtons>




            <!-- In our table we are displaying the cContact records -->




            <apex:pageBlockTable value="{!contacts}" var="c" id="table">




                <apex:column >




                    <!-- This is our selected Boolean property in our wrapper class -->




                    <apex:inputCheckbox value="{!c.selected}"/>




                </apex:column>




                <!-- This is how we access the contact values within our cContact container/wrapper -->




                <apex:column value="{!c.con.Name}" />




                <apex:column value="{!c.con.Email}" />




                <apex:column value="{!c.con.Phone}" />




            </apex:pageBlockTable>




        </apex:pageBlock>




    </apex:form>



20
</apex:page>

Hi and thanks for reading this and for any help...

 

The requirement is to stop users from saving duplicate Team Member roles when they add or edit their Default Opportunity or Account Team.  

 

So, if Tom wants to add users to his default opp team, he can only add 1 "Sales Manager", 1 "Sales Lead", etc.

 

 

Eric

 

I need a javascript function that I can call from within a visualforce page that will make a call out to an external web service and return the result. The reason for this is that the result needs to be passed back to a calling javascript method rather than being rendered on the page.

What's the best way is acheive this?

- By using actionFunction and calling the actionFunction method from my proposed javascript method. I have attempted this option and the call out from the apex class method works fine but I'm not sure how to return the result to the calling javascript method. (i.e. I have a javascript method calling the actionFunction js method, passing in appropriate parameters, but unable to receive back a result.)

- Or by using Ajax Proxy? But was this designed for use within s-controls?

- Or any other suggestions gratefully received..

Message Edited by nelloC on 11-29-2009 12:28 PM