I'm pretty new to this, so asking seems appropriate. Basically, i'm trying to Query for some data. So did that, I queried the ID of the License i need, then im finding every user who matches the profile ID and telling my program they need this license. Basically i'm stuck trying to figure out what i need to change to make this work.
I don't think i need the first For loop where i query for the license ID, but i dont know how to make it work without a For loop. the reason i need it to work without a For loop is so the other two for loops can see the variables. The error im getting now is in the third For loop.
upl.UserId = listUsersToAssignLicenses[i].Id <-- Error no definition for Id
How come it isnt recognizing Id? is it because i need to reference the index of the list? If so, how do i do that?
Do i need the first for loop?
How do i write a bulk insert and allow an error message to tell me how many licenses are left?
Sorry for so many questions, i dont know if im even allowed to ask more than one. Just kind of frustrated. Thanks!
QueryResult getUsers = null;
QueryResult queryPackageLicenses = null;
String SOQL = "";
String getUsersSOQL = "";
SOQL = "Select Id, NamespacePrefix, AllowedLicenses, UsedLicenses, ExpirationDate, Status from PackageLicense Where NamespacePrefix = SVMXC";
queryPackageLicenses = Sfdcbinding.query(SOQL);
getUsersSOQL = "Select Id, FirstName, LastName From User Where ProfileId = 00e400000013Yv9AAE"; //Dispatch ID
getUsers = Sfdcbinding.query(getUsersSOQL);
string SVMXCID = null;
string namespacePrefix = null;
int? allowedLicenses = null;
int? usedLicenses = null;
string expirationDate = null;
string status = null;
string userId = null;
string firstName = null;
string lastName = null;
string profileID = "00e400000013Yv9AAE";
int? licensesLeft = null;
if (getUsers.size > 0)
{
for (int i = 0; i < queryPackageLicenses.size; i++)
{
PackageLicense pl = (PackageLicense)queryPackageLicenses.records[i];
SVMXCID = pl.Id;
namespacePrefix = pl.NamespacePrefix;
allowedLicenses = pl.AllowedLicenses;
usedLicenses = pl.UsedLicenses;
expirationDate = pl.ExpirationDate.ToString();
status = pl.Status;
string[] packLicense = { SVMXCID, namespacePrefix, expirationDate, status };
int?[] packLicense1 = { allowedLicenses, usedLicenses};
lstSVMXCTest.Items.Add("SVMXCID Name Allowed Licenses Used Licenses Expiration Status");
lstSVMXCTest.Items.Add(string.Format("{0} {1} {2} {3} {4} {5}", SVMXCID, namespacePrefix, allowedLicenses, usedLicenses, expirationDate, status));
licensesLeft = (allowedLicenses - usedLicenses);
}
for (int i = 0; i < getUsers.size; i++) ///Returns users who match the Profile ID above. (Dispatch) Can you add more than 1 profile to list?
{
User uid = (User)getUsers.records[i];
userId = uid.Id;
firstName = uid.FirstName;
lastName = uid.LastName;
string[] UID = { userId, firstName, lastName };
listGetUsersWithProfile.AddRange(UID);
lstSVMXCTest.Items.Add(string.Format("{0} {1} {2}", userId, firstName, lastName));
}
List<string> listUsersToAssignLicenses = listGetUsersWithProfile;
List<UserPackageLicense> firstUpl = new List<UserPackageLicense>();
//create a new UserPackageLicense record for each user with a specified profile
for (int i = 0; i < listUsersToAssignLicenses.Count; i++)
{
UserPackageLicense upl = new UserPackageLicense();
upl.PackageLicenseId = "05040000000TQfcAAG"; //SVMXC ID
upl.UserId = listUsersToAssignLicenses[i].Id;
firstUpl.add(upl);
}
try
{
//Bulk Insert
//insert (FirstUPL);
}
Aucun commentaire:
Enregistrer un commentaire