Vous êtes ici :
Définition du comportement des actions avec une classe et des méthodes de contrôleur Apex
Définissez une classe et des méthodes de contrôleur Apex qui génèrent une liste de comptes affichée dans le widget tableau, créez une opportunité pour chaque compte et renvoyez la progression de chaque tâche.
- Dans Configuration, saisissez Classes Apex dans la case Recherche rapide.
- Sélectionnez Classes Apex.
-
Cliquez sur Nouveau.
-
Ajoutez le code suivant :
public class CreateOpportunitiesController { public string query{get; set;} /* To determine the records to perform the bulk action on, extract the SAQL query */ public PageReference init() { query = ApexPages.currentPage().getParameters().get('query'); return null; } /* Takes the account records from the SAQL query, creates an opportunity for each account, and then returns a map between account ID and new opportunity name. Note: Account.Name and AccountId referenced below refer to the dataset field names. Update them to match your dataset fields. */ @RemoteAction public static Map<String, String> create(List <Map<String, String>> accountRecords) { Map<String, String> result = new Map<String, String>(); List<Opportunity> opps = new List<Opportunity>(); for (Map<String, String> accountRecord : accountRecords) { String name = accountRecord.get('Account.Name') + ' - Sprint Review - 12/2'; String accountId = accountRecord.get('AccountId'); result.put(accountId, name); Opportunity opp = new Opportunity( /* You can set different fields from the Opportunity object than those listed below, like Amount. */ Name = name, Type ='New Customer', AccountId = Id.valueOf(accountId), CloseDate=Date.valueOf('2016-12-31'), StageName='Prospecting'); opps.add(opp); } insert opps; return result; } } - Cliquez sur Enregistrer.
