• Amidou Cisse
  • NEWBIE
  • 90 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 4
    Likes Given
  • 9
    Questions
  • 22
    Replies
Scenario:- Create a Map with cityName as key,and its corresponing
======    places as values

Public class Map_Practice{
public static void mapPrac(){
    //*Create a Map with cityName as key,and its corresponing places as values
    Map<string,list<string>> myMap = new Map<string,list<string>>();
        list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
        list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
        list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
            myMap.put('HYD',Hplaces);
               myMap.put('BAN',Bplaces);
            myMap.put('CHE',Cplaces);
        system.debug('City and Its Places'+myMap);
        //Get all the city names
        set<string> keys =myMap.keySet();
         system.debug('Cityes==>'+keys);
        //get all the places
        /* *if my map of values is list<string> then we can get all the values list<list<string>>*/
        list<list<string>> values = myMap.values();
           system.debug('Places==>'+values);  
        } 

}

Please Help Me i am new to salesforce
User-added image
//VF page ::

<apex:page standardController="Insertion__c" extensions="VC06_0_Insertion_TarifsPresse" Title="Tarifs Presse" showHeader="true" sidebar="true" showQuickActionVfHeader="false">
    <script>
        function redirectToInsPage(errMessageParam){
            if(errMessageParam == ''){ 
                window.top.location = '/lightning/r/Insertion__c/' + '{!insertionRecord.id}' + '/view';
            }else{
                alert(errMessageParam);
            }
        }
    </script>    
  <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <apex:slds />
        </head>
        <body>
            <div class="slds-scope">
                <apex:form styleClass="slds-form--stacked">
                    <apex:pageMessages id="pageMessageId"> </apex:pageMessages>
                    <br/>                    
                        <div class="slds-form-element">
                            <label class="slds-form-element__label slds-text-heading_small" for="select-01"> <abbr class="slds-required" title="required">*</abbr>Nom de la ligne d'offre</label>
                            <div class="slds-select_container">
                                <apex:selectList id="LigneOffre" styleclass="slds-select" value="{!ligneOffreString}" size="4">
                                    <apex:selectOptions value="{!ligneOffreSelectList}"/>
                                </apex:selectList>  
                                <div class="slds-select_container">
                                    <p> DATE DE PARUTION </p>
                                    	<apex:outputField value="{!Insertion__c.DATE_DE_PARUTION__c}"/> 
                               		<p> BRUT BASE ACHAT </p>
                                    	<apex:outputField value="{!Insertion__c.BRUT_BASE_ACHAT__c}"/>                                  
                                </div> 
                            </div>
                        </div>
                    <br/>
                    <br/>
                    <div class="slds-modal__footer slds-container--small slds-align--absolute-center">
                        <div class="slds-align--absolute-center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Enregistrer" action="{!saveButton}" oncomplete="redirectToInsPage('{!errorMessage}')"/>
                        </div>
                    </div>
                </apex:form>
            </div>
        </body>
    </html>
</apex:page>
 
// Apex Controller 

public class VC06_0_Insertion_TarifsPresse {

    public Insertion__c insertionRecord {get; set;}
    public String ligneOffreString {get; set;} 
    public List<SelectOption> ligneOffreSelectList {get; set;} 
    public String errorMessage {get; set;}
    public Map<String, Lignes_Offre__c> nomLigneOffreMap {get; set;}
    
   //************************************************************************************************************************************************
    public VC06_0_Insertion_TarifsPresse(ApexPages.StandardController controller){
        errorMessage = '';
        insertionRecord = (Insertion__c)controller.getRecord();
        queryInsertionRecord();
        System.debug('DEBUGKS_1_0_0, insertionRecord.Name: ' + insertionRecord.Name);

        if((insertionRecord.SUPPORT_RESEAU__c != null)||(insertionRecord.SUPPORT_RESEAU__r.Name != null)){
            System.debug('DEBUGKS_1_0_2, insertionRecord.SUPPORT_RESEAU__r.Name: ' + insertionRecord.SUPPORT_RESEAU__r.Name);
        populateLigneOffrePicklist(); 
        }
    }
    //***********************************************************************************************************************************************
    public void queryInsertionRecord() {
        insertionRecord = [SELECT Id, Name, DATE_DE_PARUTION__c, SUPPORT_RESEAU__c, BRUT_BASE_ACHAT__c, SUPPORT_RESEAU__r.Name
                           FROM Insertion__c 
                           WHERE Id =: insertionRecord.Id
                           LIMIT 500];
    }
    //***********************************************************************************************************************************************
    public void populateLigneOffrePicklist(){
      List<Lignes_Offre__c> supportReseauAccsList = [SELECT Id, Name, Nom_du_support__c, Nom_de_la_ligne_d_offre__c, Tarif__c, DateParution__c, Format__c
                                                       FROM Lignes_Offre__c
                                                       WHERE Nom_du_support__c =: insertionRecord.Id
                                                       LIMIT 50000];
                
        ligneOffreSelectList = new List<SelectOption>();
        nomLigneOffreMap  = new Map<String, Lignes_Offre__c>();

        for(Lignes_Offre__c ligneOffre1 : supportReseauAccsList){
            nomLigneOffreMap.put(ligneOffre1.Nom_de_la_ligne_d_offre__c, ligneOffre1);
        }

        for(String ligneOffreUnique : nomLigneOffreMap.keySet()){
            ligneOffreSelectList.add(new SelectOption(ligneOffreUnique, ligneOffreUnique));
        }
    }
   //*************************************************************************************************************************************************
    public void saveButton(){
        if(ligneOffreString != null){
            errorMessage = '';
            insertionRecord.FORMAT__c = ligneOffreString;
            insertionRecord.BRUT_BASE_ACHAT__c = nomLigneOffreMap.get(ligneOffreString).Tarif__c;
            update insertionRecord;
        }
        else{
            errorMessage = 'Veuillez choisir une ligne d`offre';
            System.debug('DEBUGKS_3_0_2, errorMessage: ' + errorMessage);
        }       
           System.debug('DEBUGKS_3_0_3, errorMessage FINAL: ' + errorMessage);
           System.debug(errorMessage == '');
    }
   //*************************************************************************************************************************************************
}

 
User-added image
Hello everyone, I hope you are well.
I have this array of data to develop by lightning component, this table allows me to show some data from my campaign as you can see below. If someone has already developed a simulare lightning component, I would like to have their code as a model to adapt my table.

Thank you in advance.
Sales Target: a trigger can be set to disable modification possibilities on the Sales Target fields.
Trigger possibilities:
Time trigger: after a predefined period;
Validation trigger: after Central CRM Manager validation.
Hello everyone,

How to manage the objectives of sales people in salesforce ?
//BlockContentLinkTrigger
trigger BlockContentLinkTrigger on ContentDocumentLink (before insert) {  
    for(ContentDocumentLink  contDocL : Trigger.new) {
            contDocL.addError('Pièce joint bloquée depuis objet ContentDocumentLink');
   }  
}

 
//BlockContentLinkTrigger
trigger BlockContentLinkTrigger on ContentDocumentLink (before insert) {  
    for(ContentDocumentLink  contDocL : Trigger.new) {
      if (CDLHelper.isSharingAllowed(contDocL)) {  
          contDocL.addError('Pièce joint bloquée depuis objet ContentDocumentLink');
     } 
   }  
}

//CDLHelper
public class CDLHelper {
    public static boolean isSharingAllowed(ContentDocumentLink cdl) {
        //String docId = cdl.ContentDocumentId;        
        ContentVersion version = [select PublishStatus, FileExtension from ContentVersion
                                  where ContentDocumentId =: cdl.ContentDocumentId limit 5];              
        if (version.PublishStatus.equals('P') && (version.FileExtension != 'null')) {
            return false;
        }
        return true;
    }
}

 
error
//Trigger
trigger BlockContentLtrigger on ContentDocumentLink (before insert) 
{  
    for(ContentDocumentLink  contDocL : Trigger.new)
    {
      if (CDLHelper.isSharingAllowed(contDocL))
     {
          contDocL.addError('stop3 ');        
     }
   }  
}

//Class
public class CDLHelper {
    public static boolean isSharingAllowed(ContentDocumentLink cdl) {
        String docId = cdl.ContentDocumentId;  
        
        ContentVersion version = [select PublishStatus, FileExtension from ContentVersion where ContentDocumentId =: docId].get(0);        
       
        if (version.PublishStatus.equals('P') && (version.FileExtension != null)) {
            return false;
        }
        return true;
    }
}

 
Hello everybody !
Someone could help me to resolve this problem please ?
 
trigger DateDeCompteRendu on Event (after insert, after update){
    
    Date dateCompteRendu;
    Datetime dateCompteRendunew;
    
    for(Event rdv : trigger.new){
    
        if (rdv.Date_de_compte_rendu__c != NULL) {
           
          dateCompteRendunew = rdv.StartDateTime;  
          dateCompteRendu = date.NewInstance(dateCompteRendunew.year(), dateCompteRendunew.month(),dateCompteRendunew.day());
        
          list<Account> acc = [SELECT Id, Date_de_derniere_visite__c FROM Account WHERE Id = :rdv.WhatId];
          list<Account> accUpdate = new list<Account>();
            
          for(Account a: acc){
             
              a.Date_de_compte_rendu__c = dateCompteRendu;
              accUpdate.add(a);
            }
         
        if (accUpdate.size()>0) {       
            update accUpdate;
            }               
      }
    } 
}
Hi guys!

I created a trigger and a test class that successfully passed the tests, but when I try to run a test myself, nothing is happening...

Here is my trigger:
public class UserProfilePhotoPublicLink {
    public static void updateUserCustomURL(List<User> users) {
        for (User user : users) {
            if (user.SmallPhotoUrl != null && user.Custom_Photo_URL__c == null) {
                user.Custom_Photo_URL__c = user.SmallPhotoUrl.replace('caesarstone', 'BENJI');
            }
        }
        update users;
    }
}

And here is the test class:
@isTest
private class UserProfilePhotoPublicLinkTest {
    static User testUser;

    static testMethod void setUp() {
        // Create a test user
        testUser = new User(
            FirstName = 'Test',
            LastName = 'User',
            Email = 'testuser@example.com'
        );
        insert testUser;

        // Update the test user's SmallPhotoUrl
        //testUser.SmallPhotoUrl = 'https://example.com/s96-c/photo.jpg';
       // update testUser;
    }

    static testMethod void testUpdateUserCustomURL() {
        // Call the method being tested
        UserProfilePhotoPublicLink.updateUserCustomURL(new List<User> { testUser });

        // Verify that the Custom_Photo_URL__c field has been updated
        testUser = [SELECT Custom_Photo_URL__c FROM User WHERE Id = :testUser.Id];
        System.assertEquals(testUser.Custom_Photo_URL__c, 'https://example.com/photo.jpg');
    }
}

Somehow when I upload a new picture to a user (and then the SmallPhotoUrl is getting automatically populated), nothing is happening ​​in the Custom_Photo_URL__c.

I don't understand why because it should trigger the apex class.

Could you please help me?

Thanks a lot!
Benji
Scenario:- Create a Map with cityName as key,and its corresponing
======    places as values

Public class Map_Practice{
public static void mapPrac(){
    //*Create a Map with cityName as key,and its corresponing places as values
    Map<string,list<string>> myMap = new Map<string,list<string>>();
        list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
        list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
        list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
            myMap.put('HYD',Hplaces);
               myMap.put('BAN',Bplaces);
            myMap.put('CHE',Cplaces);
        system.debug('City and Its Places'+myMap);
        //Get all the city names
        set<string> keys =myMap.keySet();
         system.debug('Cityes==>'+keys);
        //get all the places
        /* *if my map of values is list<string> then we can get all the values list<list<string>>*/
        list<list<string>> values = myMap.values();
           system.debug('Places==>'+values);  
        } 

}

Please Help Me i am new to salesforce
AND(
$UserRole.Name <> 'System Administrator',
$Setup.Migration_Admin__c.AdminId__c <> $User.Id,
CASE( RecordType.Name ,
'Rental', 1,
'Retail', 1,
'Corporate/System Help', 1,
'Customer Experience-Quiq', 1,
'Custom'
0 ) = 1,
OR(
AND(
TEXT(Status) = 'Solved',
OR(
ISBLANK(TEXT(tb_Type__c)),
ISBLANK(TEXT(tb_Category__c))
)
)
I keep getting an error, whcih is attached in this post. User-added image
Need assistance, please
 
Hi everyone,

I've got two custom fields in the Opportunities Object (Custom_Opp_Field_1__c, Custom_Opp_Field_2__c) that need to be updated with information from a two fields in Opportunity Product Object (Custom_Prod_Field_1__c, Custom_Prod_Field_2__c) whenever a new Opportunity Product is added or edited.

I've never written a Trigger before, so any help is very much appreciated!

Thanks in advance!
Best,
Ryno Lourens

 
Hi all , 
 I have one large method which i need to split it into two ,have one doubt 
public static void method1( List<Contact> conList, Set<ID> accountIdSet, Set<ID> OrgId){

performing some acction1
{
//
}
method2(conList,accountIdSet,OrgId);
}

public static void method2( List<Contact> conList, Set<ID> accountIdSet, Set<ID> OrgId){
performing some action2
{
//
}
}


since I am calling method2 in method 1 will the parameter are same or will it differs in method 1 and method 2 ?
means will same contactlist is passed in mtehod 2 as that on mthod 1 ..Please help 
​​​​​​​TIA
User-added image
//VF page ::

<apex:page standardController="Insertion__c" extensions="VC06_0_Insertion_TarifsPresse" Title="Tarifs Presse" showHeader="true" sidebar="true" showQuickActionVfHeader="false">
    <script>
        function redirectToInsPage(errMessageParam){
            if(errMessageParam == ''){ 
                window.top.location = '/lightning/r/Insertion__c/' + '{!insertionRecord.id}' + '/view';
            }else{
                alert(errMessageParam);
            }
        }
    </script>    
  <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <apex:slds />
        </head>
        <body>
            <div class="slds-scope">
                <apex:form styleClass="slds-form--stacked">
                    <apex:pageMessages id="pageMessageId"> </apex:pageMessages>
                    <br/>                    
                        <div class="slds-form-element">
                            <label class="slds-form-element__label slds-text-heading_small" for="select-01"> <abbr class="slds-required" title="required">*</abbr>Nom de la ligne d'offre</label>
                            <div class="slds-select_container">
                                <apex:selectList id="LigneOffre" styleclass="slds-select" value="{!ligneOffreString}" size="4">
                                    <apex:selectOptions value="{!ligneOffreSelectList}"/>
                                </apex:selectList>  
                                <div class="slds-select_container">
                                    <p> DATE DE PARUTION </p>
                                    	<apex:outputField value="{!Insertion__c.DATE_DE_PARUTION__c}"/> 
                               		<p> BRUT BASE ACHAT </p>
                                    	<apex:outputField value="{!Insertion__c.BRUT_BASE_ACHAT__c}"/>                                  
                                </div> 
                            </div>
                        </div>
                    <br/>
                    <br/>
                    <div class="slds-modal__footer slds-container--small slds-align--absolute-center">
                        <div class="slds-align--absolute-center">
                            <apex:commandButton styleClass="slds-button slds-button--brand" value="Enregistrer" action="{!saveButton}" oncomplete="redirectToInsPage('{!errorMessage}')"/>
                        </div>
                    </div>
                </apex:form>
            </div>
        </body>
    </html>
</apex:page>
 
// Apex Controller 

public class VC06_0_Insertion_TarifsPresse {

    public Insertion__c insertionRecord {get; set;}
    public String ligneOffreString {get; set;} 
    public List<SelectOption> ligneOffreSelectList {get; set;} 
    public String errorMessage {get; set;}
    public Map<String, Lignes_Offre__c> nomLigneOffreMap {get; set;}
    
   //************************************************************************************************************************************************
    public VC06_0_Insertion_TarifsPresse(ApexPages.StandardController controller){
        errorMessage = '';
        insertionRecord = (Insertion__c)controller.getRecord();
        queryInsertionRecord();
        System.debug('DEBUGKS_1_0_0, insertionRecord.Name: ' + insertionRecord.Name);

        if((insertionRecord.SUPPORT_RESEAU__c != null)||(insertionRecord.SUPPORT_RESEAU__r.Name != null)){
            System.debug('DEBUGKS_1_0_2, insertionRecord.SUPPORT_RESEAU__r.Name: ' + insertionRecord.SUPPORT_RESEAU__r.Name);
        populateLigneOffrePicklist(); 
        }
    }
    //***********************************************************************************************************************************************
    public void queryInsertionRecord() {
        insertionRecord = [SELECT Id, Name, DATE_DE_PARUTION__c, SUPPORT_RESEAU__c, BRUT_BASE_ACHAT__c, SUPPORT_RESEAU__r.Name
                           FROM Insertion__c 
                           WHERE Id =: insertionRecord.Id
                           LIMIT 500];
    }
    //***********************************************************************************************************************************************
    public void populateLigneOffrePicklist(){
      List<Lignes_Offre__c> supportReseauAccsList = [SELECT Id, Name, Nom_du_support__c, Nom_de_la_ligne_d_offre__c, Tarif__c, DateParution__c, Format__c
                                                       FROM Lignes_Offre__c
                                                       WHERE Nom_du_support__c =: insertionRecord.Id
                                                       LIMIT 50000];
                
        ligneOffreSelectList = new List<SelectOption>();
        nomLigneOffreMap  = new Map<String, Lignes_Offre__c>();

        for(Lignes_Offre__c ligneOffre1 : supportReseauAccsList){
            nomLigneOffreMap.put(ligneOffre1.Nom_de_la_ligne_d_offre__c, ligneOffre1);
        }

        for(String ligneOffreUnique : nomLigneOffreMap.keySet()){
            ligneOffreSelectList.add(new SelectOption(ligneOffreUnique, ligneOffreUnique));
        }
    }
   //*************************************************************************************************************************************************
    public void saveButton(){
        if(ligneOffreString != null){
            errorMessage = '';
            insertionRecord.FORMAT__c = ligneOffreString;
            insertionRecord.BRUT_BASE_ACHAT__c = nomLigneOffreMap.get(ligneOffreString).Tarif__c;
            update insertionRecord;
        }
        else{
            errorMessage = 'Veuillez choisir une ligne d`offre';
            System.debug('DEBUGKS_3_0_2, errorMessage: ' + errorMessage);
        }       
           System.debug('DEBUGKS_3_0_3, errorMessage FINAL: ' + errorMessage);
           System.debug(errorMessage == '');
    }
   //*************************************************************************************************************************************************
}

 
User-added image
Hello everyone, I hope you are well.
I have this array of data to develop by lightning component, this table allows me to show some data from my campaign as you can see below. If someone has already developed a simulare lightning component, I would like to have their code as a model to adapt my table.

Thank you in advance.
//BlockContentLinkTrigger
trigger BlockContentLinkTrigger on ContentDocumentLink (before insert) {  
    for(ContentDocumentLink  contDocL : Trigger.new) {
            contDocL.addError('Pièce joint bloquée depuis objet ContentDocumentLink');
   }  
}

 
//BlockContentLinkTrigger
trigger BlockContentLinkTrigger on ContentDocumentLink (before insert) {  
    for(ContentDocumentLink  contDocL : Trigger.new) {
      if (CDLHelper.isSharingAllowed(contDocL)) {  
          contDocL.addError('Pièce joint bloquée depuis objet ContentDocumentLink');
     } 
   }  
}

//CDLHelper
public class CDLHelper {
    public static boolean isSharingAllowed(ContentDocumentLink cdl) {
        //String docId = cdl.ContentDocumentId;        
        ContentVersion version = [select PublishStatus, FileExtension from ContentVersion
                                  where ContentDocumentId =: cdl.ContentDocumentId limit 5];              
        if (version.PublishStatus.equals('P') && (version.FileExtension != 'null')) {
            return false;
        }
        return true;
    }
}

 
error
//Trigger
trigger BlockContentLtrigger on ContentDocumentLink (before insert) 
{  
    for(ContentDocumentLink  contDocL : Trigger.new)
    {
      if (CDLHelper.isSharingAllowed(contDocL))
     {
          contDocL.addError('stop3 ');        
     }
   }  
}

//Class
public class CDLHelper {
    public static boolean isSharingAllowed(ContentDocumentLink cdl) {
        String docId = cdl.ContentDocumentId;  
        
        ContentVersion version = [select PublishStatus, FileExtension from ContentVersion where ContentDocumentId =: docId].get(0);        
       
        if (version.PublishStatus.equals('P') && (version.FileExtension != null)) {
            return false;
        }
        return true;
    }
}

 
trigger DateDeCompteRendu on Event (after insert, after update){
    
    Date dateCompteRendu;
    Datetime dateCompteRendunew;
    
    for(Event rdv : trigger.new){
    
        if (rdv.Date_de_compte_rendu__c != NULL) {
           
          dateCompteRendunew = rdv.StartDateTime;  
          dateCompteRendu = date.NewInstance(dateCompteRendunew.year(), dateCompteRendunew.month(),dateCompteRendunew.day());
        
          list<Account> acc = [SELECT Id, Date_de_derniere_visite__c FROM Account WHERE Id = :rdv.WhatId];
          list<Account> accUpdate = new list<Account>();
            
          for(Account a: acc){
             
              a.Date_de_compte_rendu__c = dateCompteRendu;
              accUpdate.add(a);
            }
         
        if (accUpdate.size()>0) {       
            update accUpdate;
            }               
      }
    } 
}
Hello everyone I could use some help on the using future Methods trailhead. Please keep in mind I am not an Apex coder at all but I am trying to learn as much as I can.

Here is the Task

Create an Apex class with a method using the @future annotation that accepts a List of Account IDs and updates a custom field on the Account object with the number of contacts associated to the Account. Write unit tests that achieve 100% code coverage for the class.
Create a field on the Account object called 'Number_of_Contacts__c' of type Number. This field will hold the total number of Contacts for the Account.
Create an Apex class called 'AccountProcessor' that contains a 'countContacts' method that accepts a List of Account IDs. This method must use the @future annotation.
For each Account ID passed to the method, count the number of Contact records associated to it and update the 'Number_of_Contacts__c' field with this value.
Create an Apex test class called 'AccountProcessorTest'.
The unit tests must cover all lines of code included in the AccountProcessor class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

I have written an Apex class and a Test class but I think I am doing them both Wrong: because when I try to check the challenge i Get this error

Challenge Not yet complete... here's what's wrong: 
The 'AccountProcessorTest' test class doesn't appear to be calling the 'AccountProcessor.countContacts' method between Test.startTest() and Test.stopTest().


When I run the Test class I get this error :

System.QueryException: List has no rows for assignment to SObject

Here is the CLASS:
 
public class AccountProcessor {
     @future

  public static void someFutureMethod(List<id> scope) {

   Account[] updates = new Account[] {};
        for (AggregateResult ar : [
                select AccountId a, count(Id) c
                from Contact
                where AccountId in :scope
                group by AccountId
                ]) {
            updates.add(new Account(
                    Id = (Id) ar.get('a'),
                    Number_of_Contacts__c = (Decimal) ar.get('c')
                    ));
        }
        update updates;
    }

}

Here is the Test Class:
 
@IsTest
public class AccountProcessorTest {
  public static testmethod void TestAccountProcessorTest() {
 
Test.startTest();
     Account a = new Account();
        a.Name = 'Test Account';
        Insert a;
      
      Contact cont = New Contact();
      
      cont.FirstName ='Bob';
      cont.LastName ='Masters';
      cont.AccountId = a.Id;
      Insert cont;

    Test.stopTest() ;
     Contact ACC = [select AccountId from Contact where id = :a.id LIMIT 1];

 
        System.assert(Cont.AccountId != null);
        System.assertequals(cont.id, ACC.AccountId);

  }}

I have used alot or diffrent google searches to get me this far. But I have not Idea if Im even remotly close to the right answer or not.


 
Hello ,
         I create a webservice for consuming rest api from .net . I am facing issue in test class for this . It's gives error callout not allowed from test method. How to write test class for below controller.
 
public with sharing class WebserviceCall {

    public WebserviceCall(ApexPages.StandardController controller) {

    }

    public String message {get; set;}
    
    public PageReference getaccesstoken() { 
      string jsonstring ='userName=test@gmail.com&Password=123&grant_type=password';
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
       // req.setClientCertificateName('Client Certificate');
       
        req.setEndpoint('http://google.com');
        req.setMethod('POST');
       // req.setHeader('SOAPAction', 'Soap Action');
        //req.setHeader('Authorization','Auth Token');
      
       req.setBody(jsonstring);
 
           try {
            res = http.send(req);
            message = res.getBody();
    TokenInformation token = new TokenInformation();
    token =(TokenInformation)System.JSON.deserialize(message, TokenInformation.class);
  // JSONParser parser = JSON.createParser(res.getBody());
            System.debug(token.access_token);
                 //HttpServletResponse httpResponse = (HttpServletResponse)response;
              string s = token.access_token;
            string a1 = s.substring(0,255);
            string a2 = s.substring(255,510);
            string a3 =s.substring (510,s.length());
            //Here SessionData__c is custom setting used for store access_token
       SessionData__c objToken = new SessionData__c();
       objToken.Name ='token2';
       objToken.Id ='a0G28000000ENAI';
    objToken.Access_Token1__c =a1;objToken.Access_Token2__c =a2;
               objToken.Access_Token3__c =a3;

upsert objToken;
               
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
             message = res.toString() + res.getBody();
            System.debug(res.toString());
        }
        return null;
        
}       
    
    
    
    
}

Hey everyone,

 

I'm working on an application, and I got the OAuth2 workflow working right away, but I've been struggling with making requests afterward.

 

I get the access_token and instance_url back, and when I make a call like this:

 

 

curl -v https://__instance_id__ (na7).salesforce.com/services/data/v20.0/ -H "Authorization: OAuth access_token_from_earlier"

 

the server responds with a 401 with the following body:

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

 

I've scoured the forum for solutions already, and made sure that I have API access turned on, signed up for the REST API through the developer preview form, but am still having errors all over the place.

 

Any help would be greatly appreciated.

 

Thanks!

Did not seem difficult at all, however got 18% and failed on it after a month of learning on trailhead getting up to 75 badges and 1 superbadge before taking the exam.
Things I noticed, before I took exam I watched https://www.youtube.com/watch?v=lIZk8cKOFHk&t=6613s the person teaching is teaching in classic while a lot of trailhead is in lightning. He did help me visualize a  few questions on the test I would've had no clue on.
Things I would recommend studying is going to every profiles, user, permission sets, validation rule, object and flow and look at what you can and cannot do, and the default settings.
In object such and such pick 2 of 4 things you can do. In this thing what is true?

I'm thinking about retaking it in a week, its a good test, just wasnt ready for that. Thought it would be more scenarios rather than 'what are your options, what is default settings, what went wrong, what things could have not been done right'. It will get you if you are a second guesser or overthinker because you have a lot of options, a lot of questions I noticed you have to pick 2 out of 4 choices, meaning 2 times to second guess yourself in 1 question.

Definitely not easy, but felt like I was closer to passing score of 65% or around there, I felt like I had small chance to pass before hitting the submit answers. I had feeling I did have a feeling I wasn't going to pass before I started the exam but I took it anyways because I kept seeing the message "FAILURE IS AN OPTION". So I'm not too upset I failed, but disappointed. 

I'd say my reason for failure was that I was having too much fun in trailhead rather than specifically studying for subjects relating to ADMIN exam. I had over 35 minutes left after answering questions and went back to check answers too for 20 minutes, which I felt good with, but all in all, 18%.

My 2 cents. Good luck to anyone taking it, also look at the flashcards, I didn't look at them but now thinking I would've passed it if I did http://www.sfdc99.com/2014/10/02/guide-to-passing-all-salesforce-certifications/

 
  • May 11, 2018
  • Like
  • 1
public class SendMailController {

    public String z { get; set; }

    public String y { get; set; }

    public String x { get; set; }

    public void saveMethod() {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        string[] xyz =new string[] {x};  
        mail.setToAddresses(xyz);
        mail.setSubject(y);
        mail.setHtmlBody(z);    
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
   
  }

As Admin can not prevent directly some profile based user to add comment. I have develope small trigger which can help you for this validation.

 

trigger RistrictUser on FeedComment (Before Insert) 
/*This trigger will restirct user to add comment on chatter*/
{
for(FeedComment FC: trigger.new)
    {
    /*Following Code will get Current User information*/
    User u = [SELECT id,ProfileId,Profile.Name  FROM User WHERE id = :UserInfo.getUserId()];

    /*We are going to restrict user from 'Non-Chatter Users' profile */
        if(u.Profile.Name == 'Non-Chatter Users')
        {
            FC.adderror('You can not post comment'); //You can Customize the error message here 
        }

    }
}/*EOF*/

 

 

Let me know your feedback