• Rishabh Agrawal 18
  • NEWBIE
  • 35 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 12
    Replies
i have opportunity and custom object(lookup realationship) ...but when two fields in custom object met the condition then opportunity object field want to update ='true' ....to done by trigger
Hi,
I have a requirement where there is a need to stop the record from coming into salesforce if it is a duplicate record ,i.e, the same record is already present in the system. The records are coming via integration and are getting saved but the scenario says that they should not even get saved either if it is a duplicate.
Is there any way that this can be acheived?

Thanks
I have question, i have custom object called broker with field called  Funding CFY (Currency field) and broker object have look up relationship with contact. so take all the opportunities of the cintact of the broker record the created date time of the opportunity should be in the current financial year(1/07/2017 to 30/06/2018) & opportunity stage= closed won calculate the sum of the "amount" field of all such opportunities & assign the sum to the field funding CFY in broker object.

Could you please help me on this bit urgent..

Thanks advance
i have opportunity and custom object(lookup realationship) ...but when two fields in custom object met the condition then opportunity object field want to update ='true' ....to done by trigger
Hi, I wrote Test Class for below Apex Class But I am getting only 67% code coverage how can i achieve 100% code coverage...Apex class and corresponding test class given below....

global class SiteLoginController1 {
    public String username     {get; set;}
    public String password     {get; set;}
    public String EmpName      {get;set;}
   

    
    
    global SiteLoginController1 () {}
    
    public boolean ErrorMsg{get;set;}
    public PageReference CheckUserPswd() {
        system.debug('----username----'+ username);
        system.debug('----password----'+ password);
        List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: username];
        system.debug('----empList----'+ empList);
        if(empList.size()>0){
            if(empList[0].Password__c == password){
                ErrorMsg = False;
                system.debug('----'+ErrorMsg);
                
                 EmpName=empList[0].name;
                system.debug('----'+EmpName);
               //create a new page to enter task and associate here and also do the log off
              PageReference pr=new PageReference('/apex/TimeSheetManagement?name='+EmpName);
                system.debug('-----'+pr);
                
                pr.setRedirect(true);
                return pr;              
            }
            else{
                ErrorMsg = true;
                return null;
            }
        }
        else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'No Active Employee record found with provided username.Please contact your administrator'));
            return null;
        }
    }  
    
    Public Pagereference UpdatePasswordPage(){
        PageReference newPage;
        newPage = new PageReference('/apex/Forgot_Password_VF_Page');
        newPage.setRedirect(true);
        return newPage; 
    } 
    Public Pagereference ChangePassword(){
        PageReference newPage;
        EmpName=username ;
        system.debug('----'+EmpName);
        if(String.isEmpty(EmpName)){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The  User Name'));
            return null;
        }else{
            List<Employee__c> empList = [Select id, Name, User_Name__c,Password__c from Employee__c where User_Name__c =: EmpName];
            system.debug('----'+empList);
            if(empList.size()==0){
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The Valid User Name'));
                return null;
            }else{
                
                EmpName=empList[0].name;
                 system.debug('----'+EmpName);
                newPage = new PageReference('/apex/Change_Password_Vf_Page?name='+EmpName);
                newPage.setRedirect(true);
                 return newPage; 
            }
                
            
        }
        
        
    } 
    
}

----------------------------------------------------------------------My Test Class is-------------------------------------
@isTest
private class SiteLoginController1Test {

@isTest
private static void testSiteLogin() {

Employee__c e = new Employee__c() ;
e.Name ='Test' ; 

// Add Pther required fields  if any
insert e ;
 
    
   SiteLoginController1 controller = new SiteLoginController1();
   controller.CheckUserPswd();
   controller.UpdatePasswordPage();
   controller.ChangePassword();
   
  

 }


}
I currently am working on creating an Apex Class that initiially pulls a specific set of Placements (jstcl__Placement__c) and puts them in a list. 
It then takes that list of Placement Ojects and edits a relevant field called TimecardEnddateAudit__c field. I keep getting errors saying that the field jstcl__Timesheet_Period__c that exists in some of my if logic does not exist. Logically it should edit fields according to the logic:" If the jstcl__Timesheet_Period__c field is equal to 'Weekly Split' then add .5, else add 1. 
public class CamstimecardEndDateAudit{
public static void auditTimeCards(){

List<sObject> placements = [SELECT jstcl__Placement__r.Name
                            FROM jstcl__TG_Timesheet__c 
                            WHERE jstcl__Placement__r.ts2__Status__c IN ('Active') 
                             AND jstcl__Week_Ending__c = LAST_N_DAYS:15
                             AND jstcl__Status__c = 'Pending'];
                             
    for(List<sObject> A : placements){

        if(A.jstcl__Timesheet_Period__c = 'Weekly Split'){
        
        TimecardEndDateAudit__c = TimecardEndDateAudit__c + 0.5;}
        
        else{
        
        TimecardEndDateAudit__c = TimecardEndDateAudit__c ++;
}
}
}}

 
I have to callout webservice in the external server. I got the certificate from them along with password but no username. 

Its SOAP API implementataion, but we have issues with wsdl file so i am unable to generate the apex classes out of wsdl file. As an alternate approach, we have picked up the restful webservices implementation to send the SOAP requests using HTTP classes.

We have converted the .pfx format to .jks format and imported to salesforce using the keystore password.

The question now is, how to set the certificate along with password with HTTP callout? I have read that setCertificateName can be used. But i have doubt on whether this works or not? If it works, how to attach the password along with certificate name to HTTP callout?
trigger EventTrigger on Event (before Insert, before update) {
        public static String communityId=Network.getNetworkId();
        
        if(trigger.isInsert){
            if(communityID!=null){ 
                String CommunityName=ConnectApi.Communities.getCommunity(communityId).name;
                //Update public calendar events for HR4HR community
                if(CommunityName=='HR4HR'){
                   publicCalendar__c pc = [SELECT ID__c FROM publiccalendar__c WHERE Name=: 'HR4HR Community Calendar'];
                   
                   for(Event e:trigger.new){
                       e.OwnerID=pc.ID__c;
                   }
                }
                
                //Update public calendar events for Tech Exchange community
                if(CommunityName=='TechExchange'){
                   publicCalendar__c pc = [SELECT ID__c FROM publiccalendar__c WHERE Name=: 'TechExchange Community Calendar'];
                   for(Event e:trigger.new){
                       e.OwnerID=pc.ID__c;
                   }
                }
            }
        }
        
        if(trigger.isUpdate){
           if(CommunityID!=null){
                for(Event e:trigger.New){
                    if(!(Trigger.OldMap.get(e.id).ownerId==e.ownerId)){
                        e.ownerID.addError('Assigned To field cannot be edited');
                    }    
                }
                
               
            }
            
        }

}

Above is my class and below is my test class.
 
@isTest(seeallData=true)
 public class EventTriggerTest{
  
  
  public static testMethod void testEventTrigger(){
        Network community;
        String communityId;   
        
        Id currentUserId = UserInfo.getUserId();    
        User usr = [select id,Name from User where id =: currentUserId]; 
        
   
     system.runAs(usr){
    community = [SELECT id, Name,OptionsReputationEnabled FROM Network where name =: 'TechExchange'];
        communityId = community.id;
     
    system.debug('Test User Inside Network'+network.getnetworkid());
       
      Event eve = new Event(
            // OwnerId= usr.Id,
             ActivityDate=system.today(),
             StartDateTime=system.now().addhours(35),
             EndDateTime=system.now().addhours(36),
             Subject='Test',
             Description='Testing the event controller'
                               );
      insert eve;
      
      Event e = [Select id, Subject from Event where id=:eve.id];
       
       System.assertEquals('Test', e.subject);
       e.subject='New';
       update e;
       
         
    }

     
  
  }
   
 
  

 }

 
I am stuc on this challenge and its very frustrating. 

For some reason I cannot save the component code, i get an error message when trying to save:

Failed to save undefined: No EVENT named markup://c:addItemEvent found : [markup://c:campinglist]: Source


Here is the code im trying to save. anyone know why it wont allow me to save it?

<aura:component controller="CampingListController">
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <aura:handler name="addItem" event="c:addItemEvent" action="{!c.handleAddItem}"/>
    
    <div class="slds-page-header" role="banner">

      <div class="slds-grid">

        <div class="slds-col">

          <p class="slds-text-heading--label">Camping Items</p>

          <h1 class="slds-text-heading--medium">My Camping Items</h1>

        </div>

      </div>

    </div>

      
  <div aria-labelledby="newitemform">

      <fieldset class="slds-box slds-theme--default slds-container--small">
    
        <c:campingListForm />
    
      </fieldset>

    </div>
    
    
     <aura:attribute name="items" type="Camping_Item__c[]"/>

    <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small">Camping List Items</h3>
        </header>
        
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="item">
                    <c:campingListItem item="{!item}"/>
                </aura:iteration>
            </div>
        </section>
    </div>

</aura:component>
I am doing a rest based integration to an enterprise system via CastIron. The CastIron instance is behind firewall and the method of authentication is certificates. Our CastIron team has provided me certificates to include in my rest call but with all the examples I have seen so far I don't see a way to include external certificates in a rest call from salesforce. Any help on this is very much appreciated.
Is it possible to set the networkid of a running user in a unit test?

I created a test user in a unit test with a profile that only has access to 1 community. Running a test as this user using system.runas(user) still has network.getnetworkId() returning as null. I've tried setting the users networkId both using User.networkId = networkid and User.network.Id = networkid and neither work (invalid foreign key relationship). Is there somewhere in the test I can define what network to run the test under? Any other ideas?
Hi folks,

I was having a bit of difficulty figuring out how to implement an integration and I was hoping someone might have some insight. What I need to to is make an HTTPS callout from SFDC to another system where there system is expecting an incoming XML file where the connection is secured with SSL and they provide SSL files. I am unaware of how to use their SSL files within SFDC and my APEX code. I have seen plenty of discussions of how to generate SSL certificates in SFDC but I assume that I should just be using theirs and I am not sure how. I have also seen many examples going from an external source and posting in to SFDC but not much the other way around. I have also seen that this may be how to use it in APEX once it is generated but that same material only explains how to create it in SFDC, not how to use a provided certificate.
 
req.setClientCertificateName('DocSampleCert');

below is my current code which is hitting their server but returning an unauthorized 401 error. Sensitive or unnecessary parts have been changed/removed.
 
    @future (callout=true)
	public static void basicAuthCallout(String name, Id id){
	system.debug('point 3');
	String xmlToEscape = '<?xml version="1.0" encoding="UTF-8"?>' +
	'<PartnerRecord version="2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PartnerXml.xsd">' +
	'<PartnerId>' + id + '</PartnerId>' +
	'<OrgCode></OrgCode>' +
 	'<CompanyCode></CompanyCode>' +
	'<Name>' + name + '</Name>' +
	// unnecessary parts of XML string removed
	'</PartnerRecord>';
	
	String xmlToSend = xmlToEscape.escapeXml();
	HttpRequest req = new HttpRequest();
	req.setEndpoint('https://example integration endpoint URL');
	req.setMethod('POST');
	
	// Specify the required user name and password to access the endpoint 
	
	// As well as the header and header information 
	
	
	String username = 'exampleUserName';
	String password = 'examplePassword';
	
	Blob headerValue = Blob.valueOf(username + ':' + password);
	String authorizationHeader = 'BASIC ' +
	EncodingUtil.base64Encode(headerValue);
	req.setHeader('Authorization', authorizationHeader);
	req.setBody(xmlToSend);
	// Create a new http object to send the request object 
	
	// A response object is generated as a result of the request   
	
	
	Http http = new Http();
	
	HttpResponse res = new HttpResponse();
	try {
            res = http.send(req);
    } 
    catch(System.CalloutException e) {
        System.debug('Callout error: '+ e);
        System.debug(res.toString());
    }
    
    
	//HTTPResponse res = http.send(req);
	System.debug(res.getBody());
	}

and here is the info that I got from the 3rd party as well as 2 zip files:

Please find the following information related to our SSL certificates and authentication:
 ______________________________________________________________________________________________
Attached are the certificates:
 
STAR.MANAGEMENTDYNAMICS.COM.zip: This has a wild card certificate; like: *.managementdynamics.com. It works for both eoduat (test) and eod (production).
root-intermediate-certificates.zip: This has three certificate files; one root and two intermediate 
Notes:
Our certificates are issued by:

Network Solutions CA company
Network Solutions CA company gets their certificate signed from UTN-USERFIRST CA company
UTN-USERFIRST CA company gets their certificate signed from AddTrustExternal CA  (this is root CA) 
In order to make a secured connection, your certificate store must have intermediate & root certificates. If you already have these, there is no need to import them. 
The Actual SSL Certificates in STAR.MANAGEMENTDYNAMICS.COM.zip are valid until 01/16/2018. 
Our servers do not support non-SSL connections. While sending the inbound XML request, you have to set the Authorization HTTP header in the following format in order to successfully logon (Reference Section 3.1.3, page 28 of Integration guide): 
Basic<Space><Base 64 Encode(UserName:Password)>
 
Be sure to post your files to the correct URL based on whether you want to send to the test or the production environment, and be sure you use the correct UserName and Password for each environment.
 ______________________________________________________________________________________________


finally, a slightly off topic question, I have set them up as a remote site but I just used the base URL of their company, I did not include the application context after the .com that I use for the endpoint connection. Is this correct or do I put the whole endpoint connection for the remote site? Anyway, any ideas or suggestions would be greatly appreciated. Thanks!